From 70fdf0dc748c8cc8a10ee71df1091d5ddabebe47 Mon Sep 17 00:00:00 2001 From: Quitta Date: Fri, 16 Aug 2013 22:24:11 +0200 Subject: [PATCH] Hanle multiple mailaccounts --- .../ams_lib/autoload/mail_handler.php | 52 +++++++++++-------- .../tools/server/ryzom_ams/www/config.php | 13 +++-- 2 files changed, 36 insertions(+), 29 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 67c53b301..19869abde 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 @@ -60,8 +60,7 @@ class Mail_Handler{ global $cfg; $default_groupemail = $cfg['mail']['default_groupemail']; $default_groupname = $cfg['mail']['default_groupname']; - /*$inbox_username = $cfg['mail']['username']; - $inbox_password = $cfg['mail']['password']; + /* $inbox_host = $cfg['mail']['host']; $oms_reply_to = "Ryzom Ticketing Support "; global $MAIL_DIR;*/ @@ -133,29 +132,38 @@ class Mail_Handler{ unlink($pidfile); } // Check mail + $sGroups = Support_Group::getGroups(); + $defaultGroup = new Support_Group(); + $defaultGroup->setGroupEmail($default_groupemail); + $defaultGroup->setIMAP_MailServer($cfg['mail']['default_mailserver']); + $defaultGroup->setIMAP_Username($cfg['mail']['default_username']); + $defaultGroup->setIMAP_Password($cfg['mail']['default_password']); + + $sGroups[] = $defaultGroup; - $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) { - - //return task ID - self::incoming_mail_handler($mbox, $i); - $tid = 1; //self::ams_create_email($from, $subject, $txt, $html, $to, $from); - - if($tid) { - //TODO: base file on Ticket + reply id - /* $file = fopen($MAIL_DIR."/mail/".$tid, 'w'); - fwrite($file, $entire_email); - fclose($file); */ + foreach($sGroups as $group){ + $mbox = imap_open($group->getIMAP_MailServer(), $group->getIMAP_Username(), $group->getIMAP_Password()) or die('Cannot connect to mail server: ' . imap_last_error()); + $message_count = imap_num_msg($mbox); + + for ($i = 1; $i <= $message_count; ++$i) { + + //return task ID + self::incoming_mail_handler($mbox, $i); + $tid = 1; //self::ams_create_email($from, $subject, $txt, $html, $to, $from); + + if($tid) { + //TODO: base file on Ticket + reply id + /* $file = fopen($MAIL_DIR."/mail/".$tid, 'w'); + fwrite($file, $entire_email); + fclose($file); */ + } + //mark message $i of $mbox for deletion! + imap_delete($mbox, $i); } - //mark message $i of $mbox for deletion! - imap_delete($mbox, $i); + //delete marked messages + imap_expunge($mbox); + imap_close($mbox); } - //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 611d96e76..13e6e37bb 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/config.php +++ b/code/ryzom/tools/server/ryzom_ams/www/config.php @@ -31,12 +31,6 @@ $cfg['db']['ring']['name'] = 'ring_open'; $cfg['db']['ring']['user'] = 'shard'; $cfg['db']['ring']['pass'] = ''; -$cfg['mail']['default_groupemail'] = 'support@ryzomcore.com'; -$cfg['mail']['default_groupname'] = 'Ryzomcore Support'; -$cfg['mail']['username'] = 'amsryzom@gmail.com'; -$cfg['mail']['password'] = 'lol123bol'; -//$cfg['mail']['host'] = 'ryzomcore.com'; - // To connect to an IMAP server running on port 143 on the local machine, // do the following: $mbox = imap_open("{localhost:143}INBOX", "user_id", "password"); // POP3 server on port 110: $mbox = imap_open ("{localhost:110/pop3}INBOX", "user_id", "password"); @@ -47,7 +41,12 @@ $cfg['mail']['password'] = 'lol123bol'; // 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']= '{imap.gmail.com:993/imap/ssl}INBOX'; +$cfg['mail']['default_mailserver']= '{imap.gmail.com:993/imap/ssl}INBOX'; +$cfg['mail']['default_groupemail'] = 'support@ryzomcore.com'; +$cfg['mail']['default_groupname'] = 'Ryzomcore Support'; +$cfg['mail']['default_username'] = 'amsryzom@gmail.com'; +$cfg['mail']['default_password'] = 'lol123bol'; + //----------------------------------------------------------------------------------------- // If true= the server will add automatically unknown user in the database // (in nel.user= nel.permission= ring.ring_user and ring.characters