diff --git a/util/db-upgrade-0.1.24-vs-0.1.25.sql b/util/db-upgrade-0.1.24-vs-0.1.25.sql index 7672ddb..1d8aff6 100644 --- a/util/db-upgrade-0.1.24-vs-0.1.25.sql +++ b/util/db-upgrade-0.1.24-vs-0.1.25.sql @@ -17,7 +17,6 @@ alter table archiving_rule drop index `from`; create unique index `entry` on archiving_rule (`domain`,`from`,`to`,`subject`,`_size`,`size`,`attachment_name`,`attachment_type`,`_attachment_size`,`attachment_size`,`spam`); -alter table retention_rule drop index `entry`; create unique index `entry` on retention_rule (`domain`,`from`,`to`,`subject`,`_size`,`size`,`attachment_name`,`attachment_type`,`_attachment_size`,`attachment_size`,`spam`); @@ -26,7 +25,7 @@ alter table ldap add column ldap_distributionlist_attr varchar(128) default null; alter table ldap add column ldap_distributionlist_objectclass varchar(128) default null; -alter table google change column id id char(32) not null primary key; +alter table google change column id id char(32) not null; alter table google_imap change column id id char(32) not null primary key; diff --git a/util/gmail-imap-import.php b/util/gmail-imap-import.php index 3fb3f7f..9aaa8a2 100644 --- a/util/gmail-imap-import.php +++ b/util/gmail-imap-import.php @@ -3,8 +3,33 @@ ini_set("session.save_path", "/tmp"); $webuidir = ""; +$daemonize = 0; -if(isset($_SERVER['argv'][1])) { $webuidir = $_SERVER['argv'][1]; } + +$opts = 'hd::'; +$lopts = array( + 'webui:' + ); + + +if($options = getopt($opts, $lopts)) { + + if(isset($options['webui'])) { + $webuidir = $options['webui']; + } + else { + echo("\nError: must provide path to WebUI directory\n\n"); + exit; + } + + if(isset($options['d'])) { + $daemonize = 1; + } + +} + + + require_once($webuidir . "/config.php"); @@ -41,17 +66,38 @@ openlog("piler-gmail-import", LOG_PID, LOG_MAIL); -$ug = new ModelUserGoogle(); -$g = new ModelGoogleGoogle(); +if($daemonize == 1) { + while(1) { + syslog(LOG_INFO, "started another imap poll"); + poll_imap_accounts(); - -$query = $db->query("SELECT email FROM " . TABLE_GOOGLE); -if(isset($query->rows)) { - foreach($query->rows as $q) { - $access_token = $ug->refresh_access_token($q['email']); - $g->download_users_emails($q['email'], $access_token); + sleep(300); } } +else { + poll_imap_accounts(); +} + + + + +function poll_imap_accounts() { + $db = Registry::get('db'); + + $ug = new ModelUserGoogle(); + $g = new ModelGoogleGoogle(); + + + $query = $db->query("SELECT email FROM " . TABLE_GOOGLE); + + if(isset($query->rows)) { + foreach($query->rows as $q) { + $access_token = $ug->refresh_access_token($q['email']); + $g->download_users_emails($q['email'], $access_token); + } + } +} + ?> diff --git a/webui/config.php b/webui/config.php index 529032e..e0a8651 100644 --- a/webui/config.php +++ b/webui/config.php @@ -192,6 +192,7 @@ $config['SPHINX_NOTE_INDEX'] = 'note1'; $config['RELOAD_COMMAND'] = 'sudo -n /etc/init.d/rc.piler reload'; +$config['PILERIMPORT_IMAP_COMMAND'] = '/usr/local/bin/pilerimport -d /var/piler/imap -q -r'; $config['LDAP_IMPORT_CONFIG_FILE'] = '/usr/local/etc/ldap-import.cfg'; diff --git a/webui/model/google/google.php b/webui/model/google/google.php index b7825ed..7d7b94d 100644 --- a/webui/model/google/google.php +++ b/webui/model/google/google.php @@ -129,6 +129,8 @@ } } + if($count > 0) { $this->run_import_command(); } + return $count; } @@ -158,6 +160,13 @@ } + private function run_import_command() { + syslog(LOG_INFO, "importing emails ..."); + system(PILERIMPORT_IMAP_COMMAND, $val); + syslog(LOG_INFO, "importing emails done"); + } + + } ?>