X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=scripts%2Fmaildaemon.php;h=b9facec1a56f2cd38a673c5134ca585c9dfc27b3;hb=78564c21d46d56a2cf413b9ba804d5a60430f06e;hp=6d850751482d032845409c86fc9576b3a0b71afd;hpb=edbc0c665cc65875b4d14b79939233b1c9c06bb6;p=quix0rs-gnu-social.git diff --git a/scripts/maildaemon.php b/scripts/maildaemon.php index 6d85075148..b9facec1a5 100755 --- a/scripts/maildaemon.php +++ b/scripts/maildaemon.php @@ -34,15 +34,18 @@ require_once('Mail/mimeDecode.php'); # FIXME: we use both Mail_mimeDecode and mailparse # Need to move everything to mailparse -class MailerDaemon { +class MailerDaemon +{ - function __construct() { + function __construct() + { } - function handle_message($fname='php://stdin') { + function handle_message($fname='php://stdin') + { list($from, $to, $msg) = $this->parse_message($fname); if (!$from || !$to || !$msg) { - $this->error(NULL, _('Could not parse message.')); + $this->error(null, _('Could not parse message.')); } common_log(LOG_INFO, "Mail from $from to $to: " .substr($msg, 0, 20)); $user = $this->user_from($from); @@ -66,15 +69,17 @@ class MailerDaemon { $this->add_notice($user, $msg); } - function error($from, $msg) { + function error($from, $msg) + { file_put_contents("php://stderr", $msg . "\n"); exit(1); } - function user_from($from_hdr) { + function user_from($from_hdr) + { $froms = mailparse_rfc822_parse_addresses($from_hdr); if (!$froms) { - return NULL; + return null; } $from = $froms[0]; $addr = common_canonical_email($from['address']); @@ -85,7 +90,8 @@ class MailerDaemon { return $user; } - function user_match_to($user, $to_hdr) { + function user_match_to($user, $to_hdr) + { $incoming = $user->incomingemail; $tos = mailparse_rfc822_parse_addresses($to_hdr); foreach ($tos as $to) { @@ -96,7 +102,8 @@ class MailerDaemon { return false; } - function handle_command($user, $from, $msg) { + function handle_command($user, $from, $msg) + { $inter = new CommandInterpreter(); $cmd = $inter->handle_command($user, $msg); if ($cmd) { @@ -106,7 +113,8 @@ class MailerDaemon { return false; } - function respond($from, $to, $response) { + function respond($from, $to, $response) + { $headers['From'] = $to; $headers['To'] = $from; @@ -115,11 +123,13 @@ class MailerDaemon { return mail_send(array($from), $headers, $response); } - function log($level, $msg) { + function log($level, $msg) + { common_log($level, 'MailDaemon: '.$msg); } - function add_notice($user, $msg) { + function add_notice($user, $msg) + { // should test // $msg_shortened = common_shorten_links($msg); // if (mb_strlen($msg_shortened) > 140) ERROR and STOP @@ -133,14 +143,15 @@ class MailerDaemon { 'Added notice ' . $notice->id . ' from user ' . $user->nickname); } - function parse_message($fname) { + function parse_message($fname) + { $contents = file_get_contents($fname); $parsed = Mail_mimeDecode::decode(array('input' => $contents, 'include_bodies' => true, 'decode_headers' => true, 'decode_bodies' => true)); if (!$parsed) { - return NULL; + return null; } $from = $parsed->headers['from']; @@ -166,11 +177,13 @@ class MailerDaemon { return array($from, $to, $msg); } - function unsupported_type($type) { - $this->error(NULL, "Unsupported message type: " . $type); + function unsupported_type($type) + { + $this->error(null, "Unsupported message type: " . $type); } - function cleanup_msg($msg) { + function cleanup_msg($msg) + { $lines = explode("\n", $msg); $output = '';