summaryrefslogtreecommitdiff
path: root/maildaemon.php
diff options
context:
space:
mode:
authorEvan Prodromou <evan@prodromou.name>2008-07-19 10:20:58 -0400
committerEvan Prodromou <evan@prodromou.name>2008-07-19 10:20:58 -0400
commit1d7450ca16cc210ea0ed4a7f68f2e6bff83b00fa (patch)
tree0f80d7ea99b4075328b2c12fdf6a5c1db7df8693 /maildaemon.php
parent53f59ca9d27de3b31923a6e658fe8b20463d12f0 (diff)
use mailparse
darcs-hash:20080719142058-84dde-60908b20612ee8965015b96d7e279de28cd9b112.gz
Diffstat (limited to 'maildaemon.php')
-rwxr-xr-xmaildaemon.php36
1 files changed, 33 insertions, 3 deletions
diff --git a/maildaemon.php b/maildaemon.php
index e6a345630..ba88774bf 100755
--- a/maildaemon.php
+++ b/maildaemon.php
@@ -42,26 +42,47 @@ class MailerDaemon {
$this->error(NULL, _t('Could not parse message.'));
}
common_log(LOG_INFO, "Mail from $from to $to: " .substr($msg, 0, 20));
- $user = User::staticGet('email', common_canonical_email($from));
+ $user = $this->user_from($from);
if (!$user) {
$this->error($from, _('Not a registered user.'));
return false;
}
- if ($user->incomingemail != common_canonical_email($to)) {
+ if (!$this->user_match_to($user, $to)) {
$this->error($from, _('Sorry, that is not your incoming email address.'));
}
$response = $this->handle_command($user, $msg);
if ($response) {
$this->respond($from, $to, $response);
}
+ $msg = $this->cleanup_msg($msg);
$this->add_notice($user, $msg);
}
function error($from, $msg) {
- file_put_contents("php://stderr", $msg);
+ file_put_contents("php://stderr", $msg . "\n");
exit(1);
}
+ function user_from($from_hdr) {
+ $froms = mailparse_rfc822_parse_addresses($from_hdr);
+ if (!$froms) {
+ return NULL;
+ }
+ $from = $froms[0];
+ return User::staticGet('email', common_canonical_email($from['address']));
+ }
+
+ function user_match_to($user, $to_hdr) {
+ $incoming = $user->incomingemail;
+ $tos = mailparse_rfc822_parse_addresses($to_hdr);
+ foreach ($tos as $to) {
+ if (strcasecmp($incoming, $to['address']) == 0) {
+ return true;
+ }
+ }
+ return false;
+ }
+
function handle_command($user, $msg) {
return false;
}
@@ -122,7 +143,9 @@ class MailerDaemon {
if (!$parsed) {
return NULL;
}
+
$from = $parsed->headers['from'];
+
$to = $parsed->headers['to'];
$type = $parsed->ctype_primary . '/' . $parsed->ctype_secondary;
@@ -147,6 +170,13 @@ class MailerDaemon {
function unsupported_type($type) {
$this->error(NULL, "Unsupported message type: " . $type);
}
+
+ function cleanup_msg($msg) {
+ # XXX: signatures
+ # XXX: quoting
+ preg_replace('/\s+/', ' ', $msg);
+ return $msg;
+ }
}
$md = new MailerDaemon();