Getmail Retriever is a Roundcube plugin to collect mail from external e-mail
accounts (Gmail, Yahoo, etc.) per-user, using getmail.  This is a standard
feature of contemporary mail services; this plugin provides it to your users
via Roundcube.  Getmail Retriever was forked from ispcp_fetchmail by Arthur
Mayer, a.mayer@citex.net .  This plugin only works with getmail, fetchmail
users should install ispcp_fetchmail, which can be found at:
https://github.com/flames/RCFetchmail

Released under the GPL license (http://www.gnu.org/licenses/gpl.txt)

Installation instructions:
--------------------------
Install getmail: apt-get install getmail (Debian/Ubuntu/Mint) or install from
source at http://pyropus.ca/software/getmail

Create a directory for getmail and set ownership to the user:group your mail
is delivered by:

mkdir /mail/getmail
chown -R vmail:mail /mail/getmail
chmod -R 700 /mail/getmail

Add Your mail user to the web server group so it can read the Roundcube
config files:

usermod -G www-data vmail

In the Roundcube database create an additional table:

mysql -u user -p password roundcube<<EOF
CREATE TABLE `getmail` (
`mailget_id` int(11) NOT NULL auto_increment,
`userhere` varchar(50) collate utf8_unicode_ci NOT NULL,
`active` int(1) unsigned NOT NULL default '1',
`type` varchar(5) collate utf8_unicode_ci NOT NULL default 'POP3',
`server` varchar(50) collate utf8_unicode_ci NOT NULL,
`user` varchar(50) collate utf8_unicode_ci NOT NULL,
`pass` varchar(50) collate utf8_unicode_ci NOT NULL,
`ssl` int(1) unsigned NOT NULL default '1',
`folder` varchar(60) collate utf8_unicode_ci NOT NULL,
`delete` int(1) unsigned NOT NULL DEFAULT '0',
`getonlynew` int(1) unsigned NOT NULL DEFAULT '1',
`getallnext` int(1) unsigned NOT NULL DEFAULT '0',
`poll` int(10) unsigned NOT NULL DEFAULT '15',
`lastpoll` int(10) unsigned NOT NULL,
PRIMARY KEY (`mailget_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;
EOF

Copy the getmail_receiver folder to your Roundcube plugins directory.
On a Debian-derived system this is /var/lib/roundcube/plugins

Enable the plugin by editing Roundcube's main.inc.php file and adding
'getmail_retriever' to the $rcmail_config['plugins'] array.

The plugin's config file is config/config.inc.php where you must set:

  # The directory getmail writes getmailrc and log files to
  $rcmail_config['getmail_dir'] = '/var/mail/getmail';

  # The getmail destination and its options (external MDA)
  $rcmail_config['getmail_destination_type'] = 'MDA_external';
  $rcmail_config['getmail_destination_path'] = '/usr/local/sbin/sendmail';

  # The getmail destination and its options (Maildir)
  $rcmail_config['getmail_destination_type'] = 'Maildir';
  $rcmail_config['getmail_destination_path'] = '/var/mail/vmail/%(domain)/%(local)';

  # The getmail destination and its options (mboxrd)
  $rcmail_config['getmail_destination_type'] = 'mboxrd';
  $rcmail_config['getmail_destination_path'] = '/var/mail/vmail/%(recipient)/mbox';

  # The directory where Roundcube's main.inc.php is located, the Roundcube
  # plugin obviously doesn't need this, but the backend script needs it.
  $rcmail_config['getmail_rc_config'] = '/etc/roundcube';

You may also set these:
  # Path to getmail
  $rcmail_config['getmail'] = '/usr/bin/getmail';

  # Run getmail with trace option on
  $rcmail_config['getmail_trace'] = FALSE;

  # Arguments for destination type External_MDA
  $rcmail_config['getmail_destination_arguments'] = array('-i', '-f %(sender)', '%(recipient)');

  # Lock type for destination type mboxrd, 
  $rcmail_config['getmail_destination_locktype'] = 'lockf';

  # Add Delivered-to: header
  $rcmail_config['getmail_delivered_to'] = TRUE;

  # Add Received: header
  $rcmail_config['getmail_received'] = TRUE;

  # Timeout for getmail
  $rcmail_config['getmail_timeout'] = 60;
  
  # getmail verbosity
  $rcmail_config['getmail_verbose'] = 1;

  # getmail maximum message size
  $rcmail_config['getmail_max_message_size'] = 0;

  # getmail maximum messages to retrieve per session
  $rcmail_config['getmail_max_messages_per_session'] = 0;

  # Getmail Retriever and getmail logs to syslog
  $rcmail_config['getmail_message_log_syslog'] = TRUE;

  # Getmail Retriever and getmail logs to file
  $rcmail_config['getmail_message_log'] = TRUE; // TRUE or FALSE here, not a file

  # getmail logfile verbose
  $rcmail_config['getmail_message_log_verbose'] = FALSE;

  # The maximum number of accounts that can be checked per-user
  $rcmail_config['getmail_limit'] = 5;

Configure cron to run the backend.  This needs to be run frequently:
Create /etc/cron.d/getmail_retriever with the contents:
*/5 * * * * vmail php /var/lib/roundcube/plugins/getmail_retriever/getmail-backend.php

The backend will only poll accounts whose next polling time has arrived based
on user settings.  There is no configuration value for the minimum amount of
time that must pass between polling attempts, how often you run the cron job
is the minimum time that must pass between polling attempts.

- The UI of the plugin originally was based on the ISPConfig3-Fetchmail plugin
  by Horst Fickel.
