a few fixes

This commit is contained in:
SJ
2014-04-24 10:18:29 +02:00
parent 4e6946feca
commit 989cd68054
4 changed files with 65 additions and 10 deletions

View File

@ -3,8 +3,33 @@
ini_set("session.save_path", "/tmp");
$webuidir = "";
$daemonize = 0;
$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;
}
}
if(isset($_SERVER['argv'][1])) { $webuidir = $_SERVER['argv'][1]; }
require_once($webuidir . "/config.php");
@ -41,17 +66,38 @@ $loader->model('google/google');
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();
sleep(300);
}
}
else {
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);
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);
}
}
}
?>