model('user/google'); $loader->model('google/google'); openlog("piler-gmail-import", LOG_PID, LOG_MAIL); if($daemonize == 1) { while(1) { syslog(LOG_INFO, "started another imap poll"); poll_imap_accounts(); sleep(300); } } else { poll_imap_accounts($email); } function poll_imap_accounts($email = '') { $db = Registry::get('db'); $ug = new ModelUserGoogle(); $g = new ModelGoogleGoogle(); if($email) { $query = $db->query("SELECT email FROM " . TABLE_GOOGLE . " WHERE email=?", array($email)); } else { $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 display_help() { $phpself = basename(__FILE__); echo("\nUsage: $phpself --webui [PATH] [OPTIONS...]\n\n"); echo("\t--webui=\"[REQUIRED: path to the Piler WebUI Directory]\"\n\n"); echo("options:\n"); echo("\t--email: Email address to poll. Leave it empty to poll all email addresses\n"); echo("\t-d: Daemonize the imap polling\n"); echo("\t-h: Prints this help screen and exits\n"); } ?>