ready to do the imap part

This commit is contained in:
Quitta 2013-08-12 01:11:48 +02:00
parent 0d57ff53e8
commit 7206e19c20
2 changed files with 15 additions and 12 deletions

View file

@ -80,7 +80,7 @@ class Mail_Handler{
//creates child process //creates child process
$pid = self::mail_fork(); $pid = self::mail_fork();
$pidfile = '/tmp/ams_cron_email_pid'; $pidfile = '/tmp/ams_cron_email_pid2';
//INFO: if $pid = //INFO: if $pid =
//-1: "Could not fork!\n"; //-1: "Could not fork!\n";
@ -89,7 +89,7 @@ class Mail_Handler{
if($pid) { if($pid) {
// We're the parent process, do nothing! // We're the parent process, do nothing!
} else { } else {
//make db connection here because the children have to make the connection. //make db connection here because the children have to make the connection.
@ -97,7 +97,6 @@ class Mail_Handler{
//if $pidfile doesn't exist yet, then start sending the mails that are in the db. //if $pidfile doesn't exist yet, then start sending the mails that are in the db.
if(!file_exists($pidfile)) { if(!file_exists($pidfile)) {
//create the file and write the child processes id in it! //create the file and write the child processes id in it!
$pid = getmypid(); $pid = getmypid();
$file = fopen($pidfile, 'w'); $file = fopen($pidfile, 'w');
@ -143,12 +142,13 @@ class Mail_Handler{
unlink($pidfile); unlink($pidfile);
} }
// Check mail // Check mail
/*
//$mailbox = imap_open("{localhost:110/pop3/novalidate-cert}INBOX", $inbox_username, $inbox_password); //$mailbox = imap_open("{localhost:110/pop3/novalidate-cert}INBOX", $inbox_username, $inbox_password);
$mbox = imap_open($cfg['mail']['server'], $inbox_username, $inbox_password); $mbox = imap_open($cfg['mail']['server'], $inbox_username, $inbox_password) or die('Cannot connect to mail server: ' . imap_last_error());
$message_count = imap_num_msg($mbox); $message_count = imap_num_msg($mbox);
for ($i = 1; $i <= $message_count; ++$i) { for ($i = 1; $i <= $message_count; ++$i) {
$header = imap_header($mbox, $i); $header = imap_header($mbox, $i);
$entire_email = imap_fetchheader($mbox, $i) . imap_body($mbox, $i); $entire_email = imap_fetchheader($mbox, $i) . imap_body($mbox, $i);
$subject = decode_utf8($header->subject); $subject = decode_utf8($header->subject);
@ -156,6 +156,7 @@ class Mail_Handler{
$from = $header->from[0]->mailbox . '@' . $header->from[0]->host; $from = $header->from[0]->mailbox . '@' . $header->from[0]->host;
$txt = get_part($mbox, $i, "TEXT/PLAIN"); $txt = get_part($mbox, $i, "TEXT/PLAIN");
$html = get_part($mbox, $i, "TEXT/HTML"); $html = get_part($mbox, $i, "TEXT/HTML");
//return task ID //return task ID
$tid = oms_create_email($from, $subject, $txt, $html, $to, $from); $tid = oms_create_email($from, $subject, $txt, $html, $to, $from);
@ -164,11 +165,13 @@ class Mail_Handler{
fwrite($file, $entire_email); fwrite($file, $entire_email);
fclose($file); fclose($file);
} }
//mark message $i of $mbox for deletion!
imap_delete($mbox, $i); imap_delete($mbox, $i);
} }
//delete marked messages
imap_expunge($mbox); imap_expunge($mbox);
imap_close($mbox); imap_close($mbox);
*/
} }
} }

View file

@ -31,8 +31,8 @@ $cfg['db']['ring']['name'] = 'ring_open';
$cfg['db']['ring']['user'] = 'shard'; $cfg['db']['ring']['user'] = 'shard';
$cfg['db']['ring']['pass'] = ''; $cfg['db']['ring']['pass'] = '';
$cfg['mail']['username'] = '123'; $cfg['mail']['username'] = 'amsryzom@gmail.com';
$cfg['mail']['password'] = '456'; $cfg['mail']['password'] = 'lol123bol';
$cfg['mail']['host'] = 'test.com'; $cfg['mail']['host'] = 'test.com';
// To connect to an IMAP server running on port 143 on the local machine, // To connect to an IMAP server running on port 143 on the local machine,
@ -44,8 +44,8 @@ $cfg['mail']['host'] = 'test.com';
// $mbox = imap_open ("{localhost:995/pop3/ssl/novalidate-cert}", "user_id", "password"); // $mbox = imap_open ("{localhost:995/pop3/ssl/novalidate-cert}", "user_id", "password");
// NNTP server on port 119 use: $nntp = imap_open ("{localhost:119/nntp}comp.test", "", ""); // NNTP server on port 119 use: $nntp = imap_open ("{localhost:119/nntp}comp.test", "", "");
// To connect to a remote server replace "localhost" with the name or the IP address of the server you want to connect to. // To connect to a remote server replace "localhost" with the name or the IP address of the server you want to connect to.
$cfg['mail']['server'] = '{localhost:110/pop3/novalidate-cert}INBOX'; //$cfg['mail']['server'] = '{localhost:110/pop3/novalidate-cert}INBOX';
$cfg['mail']['server']= '{imap.gmail.com:993/imap/ssl}INBOX'
//----------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------
// If true= the server will add automatically unknown user in the database // If true= the server will add automatically unknown user in the database
// (in nel.user= nel.permission= ring.ring_user and ring.characters // (in nel.user= nel.permission= ring.ring_user and ring.characters