From a3f9e44c0c86a1417ab98fd483448870d9ede111 Mon Sep 17 00:00:00 2001 From: Quitta Date: Sat, 10 Aug 2013 01:46:21 +0200 Subject: [PATCH] added mail_handler class (from Botanic) still needs to be reworked + added show queue template --- .../ams_lib/autoload/mail_handler.php | 252 ++++++++++++++++++ .../ams_lib/ingame_templates/show_queue.tpl | 222 +++++++++++++++ .../tools/server/ryzom_ams/www/config.php | 6 +- 3 files changed, 479 insertions(+), 1 deletion(-) create mode 100644 code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/mail_handler.php create mode 100644 code/ryzom/tools/server/ryzom_ams/ams_lib/ingame_templates/show_queue.tpl 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 new file mode 100644 index 000000000..cbce72fbd --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/mail_handler.php @@ -0,0 +1,252 @@ + $recipient, 'subject' => $subject, 'body' => $body, 'status' => 'NEW', 'id_user' => $id_user, 'sender' => $from)); +} + + + +function oms_mail_cron() { + + $oms_inbox_username = '123'; + $oms_inbox_password = '456'; + $oms_host = 'test.com'; + $oms_reply_to = "OMS "; + global $basedir; + + // Deliver new mail + echo("mail cron\n"); + + //TO ASK: + $pid = oms_fork(); + $pidfile = '/tmp/oms_cron_email_pid'; + + if($pid) { + + // We're the main process. + + } else { + + if(!file_exists($pidfile)) { + + $pid = getmypid(); + $file = fopen($pidfile, 'w'); + fwrite($file, $pid); + fclose($file); + $emails = db_query("select * from email where status = 'NEW' or status = 'FAILED'"); + + foreach($emails as $email) { + $message_id = oms_new_message_id(); + echo("Emailing {$email['recipient']}\n"); + if(!$email['recipient']) { + $email['recipient'] = oms_get_email_by_user_id($email['id_user']); + } + + if($email['sender']) { + $username = oms_get_username_from_id($email['sender']); + $from = "$username <$username@$oms_host>"; + } else { + $from = $oms_reply_to; + } + $headers = "From: $from\r\n" . "Message-ID: " . $message_id; + + if(mail($email['recipient'], $email['subject'], $email['body'], $headers)) { + $status = "DELIVERED"; + echo("Emailed {$email['recipient']}\n"); + } else { + $status = "FAILED"; + echo("Email to {$email['recipient']} failed\n"); + } + db_exec('update email set status = ?, message_id = ?, attempts = attempts + 1 where id_email = ?', array($status, $message_id, $email['id_email'])); + } + unlink($pidfile); + } + // Check mail + + //$mailbox = imap_open("{localhost:110/pop3/novalidate-cert}INBOX", $oms_inbox_username, $oms_inbox_password); + $mbox = imap_open("{localhost:110/pop3/novalidate-cert}INBOX", $oms_inbox_username, $oms_inbox_password); + $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); + $to = $header->to[0]->mailbox; + $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); + + if($tid) { + $file = fopen("$basedir/mail/$tid", 'w'); + fwrite($file, $entire_email); + fclose($file); + } + imap_delete($mbox, $i); + } + imap_expunge($mbox); + imap_close($mbox); + } + +} + + + +function oms_new_message_id() { + + $time = time(); + $pid = getmypid(); + global $oms_mail_count; + $oms_mail_count = ($oms_mail_count == '') ? 1 : $oms_mail_count + 1; + return ""; + +} + + + +function oms_create_email($from, $subject, $body, $html, $recipient = 0, $sender = NULL) { + + if($recipient == 0 && !is_string($recipient)) { + global $user; + $recipient = $user->uid; + } + + if($sender !== NULL && !is_numeric($sender)) $sender = oms_get_id_from_username($sender); + if(!is_numeric($recipient)) $recipient = oms_get_id_from_username($recipient); + + oms_error_log("Sending message: '$subject' from $sender to $recipient", 3); + + $message = array( + 'creator' => $sender, + 'owner' => $recipient, + 'id_module' => 'email', + 'type' => 'email', + 'summary' => $subject, + 'data' => array ( + 'subject' => $subject, + 'body' => $body, + 'html' => $html, + 'sender' => oms_get_username_from_id($sender), + 'from' => $from, + 'recipient' => oms_get_username_from_id($recipient), + 'time' => time(), + ), + ); + + //TO ASK: + oms_task_create($message); + oms_task_index($message, array('subject', 'body', 'sender', 'recipient')); + //--------------------------- + return $message['id_task']; +} + + + +function oms_get_email($id) { + + $message = oms_task_load($id); + if($message) { + oms_prepare_email($message); + return $message; + } else { + return FALSE; + } + +} + + + +function oms_prepare_email(&$message) { + + $data = $message['data']; + $data['id_message'] = $message['id_task']; + $data['read'] = ($message['status'] != 'NEW' && $message['status'] != 'UNREAD'); + $message = $data; + +} + + + +function oms_email_mark_read($mid) { + + db_exec("update task set status = 'READ' where id_task = ? and type = 'email' and module = 'email'", array($mid)); + +} + + + +function decode_utf8($str) { + + preg_match_all("/=\?UTF-8\?B\?([^\?]+)\?=/i",$str, $arr); + for ($i=0;$isubtype) { + return $primary_mime_type[(int) $structure->type] . '/' .$structure->subtype; + } + return "TEXT/PLAIN"; + +} + + + +function get_part($stream, $msg_number, $mime_type, $structure = false, $part_number = false) { + + if(!$structure) { + $structure = imap_fetchstructure($stream, $msg_number); + } + + if($structure) { + if($mime_type == get_mime_type($structure)) { + if(!$part_number) { + $part_number = "1"; + } + $text = imap_fetchbody($stream, $msg_number, $part_number); + if($structure->encoding == 3) { + return imap_base64($text); + } else if($structure->encoding == 4) { + return imap_qprint($text); + } else { + return $text; + } + } + + if($structure->type == 1) /* multipart */ { + while(list($index, $sub_structure) = each($structure->parts)) { + if($part_number) { + $prefix = $part_number . '.'; + } else { + $prefix = ''; + } + $data = get_part($stream, $msg_number, $mime_type, $sub_structure,$prefix . ($index + 1)); + if($data) { + return $data; + } + } // END OF WHILE + } // END OF MULTIPART + } // END OF STRUTURE + return false; + +} // END OF FUNCTION + + \ No newline at end of file diff --git a/code/ryzom/tools/server/ryzom_ams/ams_lib/ingame_templates/show_queue.tpl b/code/ryzom/tools/server/ryzom_ams/ams_lib/ingame_templates/show_queue.tpl new file mode 100644 index 000000000..eeda5813e --- /dev/null +++ b/code/ryzom/tools/server/ryzom_ams/ams_lib/ingame_templates/show_queue.tpl @@ -0,0 +1,222 @@ +{block name=content} + + + + + + + + +
+ + + + +
+ + + + + + + + +
Todo ticketsAll ticketsAll open ticketsTicket ArchiveNot Assigned Tickets
+
+
+ + + + + + + + + + + + +

Ticket Queue: {$queue_view}

+ + + + + + + + + + + + +{/block} + diff --git a/code/ryzom/tools/server/ryzom_ams/www/config.php b/code/ryzom/tools/server/ryzom_ams/www/config.php index 7f0bfc4a0..690d47c4b 100644 --- a/code/ryzom/tools/server/ryzom_ams/www/config.php +++ b/code/ryzom/tools/server/ryzom_ams/www/config.php @@ -19,7 +19,7 @@ $cfg['db']['lib']['name'] = 'ryzom_ams_lib'; $cfg['db']['lib']['user'] = 'shard'; $cfg['db']['lib']['pass'] = ''; -$cfg['db']['shard']['host'] = 'localhosti'; +$cfg['db']['shard']['host'] = 'localhost'; $cfg['db']['shard']['port'] = '3306'; $cfg['db']['shard']['name'] = 'nel'; $cfg['db']['shard']['user'] = 'shard'; @@ -31,6 +31,10 @@ $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']['host'] = 'test.com'; + //----------------------------------------------------------------------------------------- // If true= the server will add automatically unknown user in the database // (in nel.user= nel.permission= ring.ring_user and ring.characters
+ + +
+
+ + + +
+ + + {if isset($ACTION_RESULT)} + +
+ + + +
+

Tickets

+

+

+ + + + + + + + + + + + + + + + +
Show + + tickets + + to + + : + + or + + + + +
+
+

+

+ + + + + + + + + + + + {foreach from=$tickets item=ticket} + + + + + + + + + + + {/foreach} +
IDTitleAssignedTimestampCategoryStatusSupportGroupActions
{$ticket.tId}{$ticket.title}{if $ticket.assignedText neq ""} {$ticket.assignedText}{else} {$not_assigned} {/if}{$ticket.timestamp}{$ticket.category}{if $ticket.status eq 0}{else if $ticket.status eq 1}{else if $ticket.status eq 2}{/if}{$ticket.statusText} + + {if $ticket.forwardedGroupName eq "0"} + {$public_sgroup} + {else} + {$ticket.forwardedGroupName} + {/if} + + + {if $ticket.assigned eq 0} +
+ + + +
+ {else if $ticket.assigned eq $user_id} +
+ + + +
+ {/if} +
+

+
+ + + + {foreach from=$links item=link} + + {/foreach} + + +
«{$link}»
+
+
+ + + + + + +
+ {if isset($ACTION_RESULT) and $ACTION_RESULT eq "SUCCESS_ASSIGNED"} +

+ {$success_assigned} +

+ {else if isset($ACTION_RESULT) and $ACTION_RESULT eq "SUCCESS_UNASSIGNED"} +

+ {$success_unassigned} +

+ {else if isset($ACTION_RESULT) and $ACTION_RESULT eq "TICKET_NOT_EXISTING"} +

+ {$ticket_not_existing} +

+ {else if isset($ACTION_RESULT) and $ACTION_RESULT eq "ALREADY_ASSIGNED"} +

+ {$ticket_already_assigned} +

+ {else if isset($ACTION_RESULT) and $ACTION_RESULT eq "NOT_ASSIGNED"} +

+ {$ticket_not_assigned} +

+ {/if} +
+ + {/if} +
+
+
+ +