From cb1ecf6b6ed415ee92878270fafcb5c0bc002772 Mon Sep 17 00:00:00 2001 From: Quitta Date: Mon, 12 Aug 2013 01:11:48 +0200 Subject: [PATCH] ready to do the imap part --- .../ams_lib/autoload/mail_handler.php | 19 +++++++++++-------- .../tools/server/ryzom_ams/www/config.php | 8 ++++---- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/mail_handler.php b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/mail_handler.php index 67a90114b..363b82917 100644 --- a/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/mail_handler.php +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/mail_handler.php @@ -80,7 +80,7 @@ class Mail_Handler{ //creates child process $pid = self::mail_fork(); - $pidfile = '/tmp/ams_cron_email_pid'; + $pidfile = '/tmp/ams_cron_email_pid2'; //INFO: if $pid = //-1: "Could not fork!\n"; @@ -89,15 +89,14 @@ class Mail_Handler{ if($pid) { - // We're the parent process, do nothing! - + // We're the parent process, do nothing! + } else { //make db connection here because the children have to make the connection. $this->db = new DBLayer("lib"); //if $pidfile doesn't exist yet, then start sending the mails that are in the db. if(!file_exists($pidfile)) { - //create the file and write the child processes id in it! $pid = getmypid(); $file = fopen($pidfile, 'w'); @@ -143,12 +142,13 @@ class Mail_Handler{ unlink($pidfile); } // Check mail - /* + //$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); for ($i = 1; $i <= $message_count; ++$i) { + $header = imap_header($mbox, $i); $entire_email = imap_fetchheader($mbox, $i) . imap_body($mbox, $i); $subject = decode_utf8($header->subject); @@ -156,6 +156,7 @@ class Mail_Handler{ $from = $header->from[0]->mailbox . '@' . $header->from[0]->host; $txt = get_part($mbox, $i, "TEXT/PLAIN"); $html = get_part($mbox, $i, "TEXT/HTML"); + //return task ID $tid = oms_create_email($from, $subject, $txt, $html, $to, $from); @@ -163,12 +164,14 @@ class Mail_Handler{ $file = fopen("$basedir/mail/$tid", 'w'); fwrite($file, $entire_email); fclose($file); - } + } + //mark message $i of $mbox for deletion! imap_delete($mbox, $i); } + //delete marked messages imap_expunge($mbox); imap_close($mbox); - */ + } } diff --git a/code/ryzom/tools/server/ryzom_ams/www/config.php b/code/ryzom/tools/server/ryzom_ams/www/config.php index ce1439acb..516ae0da4 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/config.php +++ b/code/ryzom/tools/server/ryzom_ams/www/config.php @@ -31,8 +31,8 @@ $cfg['db']['ring']['name'] = 'ring_open'; $cfg['db']['ring']['user'] = 'shard'; $cfg['db']['ring']['pass'] = ''; -$cfg['mail']['username'] = '123'; -$cfg['mail']['password'] = '456'; +$cfg['mail']['username'] = 'amsryzom@gmail.com'; +$cfg['mail']['password'] = 'lol123bol'; $cfg['mail']['host'] = 'test.com'; // 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"); // 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. -$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 // (in nel.user= nel.permission= ring.ring_user and ring.characters