function run() { $logger = DevblocksPlatform::getConsoleLog(); $logger->info("[POP3] Starting POP3 Task"); if (!extension_loaded("imap")) { die("IMAP Extension not loaded!"); } @set_time_limit(0); // Unlimited (if possible) @ini_set('memory_limit', '64M'); $accounts = DAO_Mail::getPop3Accounts(); /* @var $accounts CerberusPop3Account[] */ $timeout = ini_get('max_execution_time'); // Allow runtime overloads (by host, etc.) @($gpc_pop3_max = DevblocksPlatform::importGPC($_REQUEST['pop3_max'], 'integer')); $max_downloads = !empty($gpc_pop3_max) ? $gpc_pop3_max : $this->getParam('max_messages', $timeout ? 20 : 50); // [JAS]: Make sure our output directory is writeable if (!is_writable(APP_MAIL_PATH . 'new' . DIRECTORY_SEPARATOR)) { $logger->err("[POP3] The mail storage directory is not writeable. Skipping POP3 download."); return; } foreach ($accounts as $account) { /* @var $account CerberusPop3Account */ if (!$account->enabled) { continue; } $logger->info('[POP3] Account being parsed is ' . $account->nickname); switch ($account->protocol) { default: case 'pop3': // 110 $connect = sprintf("{%s:%d/pop3/notls}INBOX", $account->host, $account->port); break; case 'pop3-ssl': // 995 $connect = sprintf("{%s:%d/pop3/ssl/novalidate-cert}INBOX", $account->host, $account->port); break; case 'imap': // 143 $connect = sprintf("{%s:%d/notls}INBOX", $account->host, $account->port); break; case 'imap-ssl': // 993 $connect = sprintf("{%s:%d/imap/ssl/novalidate-cert}INBOX", $account->host, $account->port); break; } $runtime = microtime(true); if (false === ($mailbox = @imap_open($connect, !empty($account->username) ? $account->username : "", !empty($account->password) ? $account->password : ""))) { $logger->err("[POP3] Failed with error: " . imap_last_error()); continue; } $messages = array(); $check = imap_check($mailbox); // [TODO] Make this an account setting? $total = min($max_downloads, $check->Nmsgs); $logger->info('[POP3] Init time: ' . (microtime(true) - $runtime) * 1000, " ms"); $runtime = microtime(true); for ($i = 1; $i <= $total; $i++) { /* * [TODO] Logic for max message size (>1MB, etc.) handling. If over a * threshold then use the attachment parser (imap_fetchstructure) to toss * non-plaintext until the message fits. */ $msgno = $i; $time = microtime(true); $headers = imap_fetchheader($mailbox, $msgno); $body = imap_body($mailbox, $msgno); do { $unique = sprintf("%s.%04d", time(), mt_rand(0, 9999)); $filename = APP_MAIL_PATH . 'new' . DIRECTORY_SEPARATOR . $unique; } while (file_exists($filename)); $fp = fopen($filename, 'w'); if ($fp) { fwrite($fp, $headers, strlen($headers)); fwrite($fp, "\r\n\r\n"); fwrite($fp, $body, strlen($body)); @fclose($fp); } /* * [JAS]: We don't add the .msg extension until we're done with the file, * since this will safely be ignored by the parser until we're ready * for it. */ rename($filename, dirname($filename) . DIRECTORY_SEPARATOR . basename($filename) . '.msg'); unset($headers); unset($body); $time = microtime(true) - $time; $logger->info("[POP3] Downloaded message " . $msgno . " (" . sprintf("%d", $time * 1000) . " ms)"); imap_delete($mailbox, $msgno); continue; } imap_expunge($mailbox); imap_close($mailbox); imap_errors(); $logger->info("[POP3] Total Runtime: " . (microtime(true) - $runtime) * 1000 . " ms"); } }
function showTabMailAction() { $tpl = DevblocksPlatform::getTemplateService(); $tpl->assign('path', $this->_TPL_PATH); $settings = DevblocksPlatform::getPluginSettingsService(); $mail_service = DevblocksPlatform::getMailService(); $smtp_host = $settings->get('cerberusweb.core', CerberusSettings::SMTP_HOST, ''); $smtp_port = $settings->get('cerberusweb.core', CerberusSettings::SMTP_PORT, 25); $smtp_auth_enabled = $settings->get('cerberusweb.core', CerberusSettings::SMTP_AUTH_ENABLED, false); if ($smtp_auth_enabled) { $smtp_auth_user = $settings->get('cerberusweb.core', CerberusSettings::SMTP_AUTH_USER, ''); $smtp_auth_pass = $settings->get('cerberusweb.core', CerberusSettings::SMTP_AUTH_PASS, ''); } else { $smtp_auth_user = ''; $smtp_auth_pass = ''; } $smtp_enc = $settings->get('cerberusweb.core', CerberusSettings::SMTP_ENCRYPTION_TYPE, 'None'); $smtp_max_sends = $settings->get('cerberusweb.core', CerberusSettings::SMTP_MAX_SENDS, '20'); $pop3_accounts = DAO_Mail::getPop3Accounts(); $tpl->assign('pop3_accounts', $pop3_accounts); $tpl->display('file:' . $this->_TPL_PATH . 'configuration/tabs/mail/index.tpl'); }
/** * Enter description here... * * @param integer $id * @return CerberusPop3Account */ static function getPop3Account($id) { $accounts = DAO_Mail::getPop3Accounts(array($id)); if (isset($accounts[$id])) { return $accounts[$id]; } return null; }