diff options
-rw-r--r-- | src/F2M.php | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/src/F2M.php b/src/F2M.php index 4c5c904..510cfa4 100644 --- a/src/F2M.php +++ b/src/F2M.php @@ -14,6 +14,19 @@ function send_to_lists($config, $user, $mode, $data, $post_data) { var_dump($post_data); print '</p>'; + # Check the mode + switch ($mode) { + case 'post': + case 'reply': + case 'quote': + break; # Mail this post + case 'edit': # TODO + case 'delete': # TODO + return; + default: + throw new Exception('unrecognized mode: ' . $mode); + } + require_once('Mail.php'); require_once(__DIR__ . '/Bridge.php'); @@ -52,16 +65,19 @@ function send_to_lists($config, $user, $mode, $data, $post_data) { $inReplyTo = null; $references = null; - if ($mode == 'reply') { - $firstId = $data['topic_first_post_id']; + if ($mode == 'reply' || $mode == 'quote') { + $firstId = $data['topic_first_post_id']; $firstMessageId = $bridge->getMessageId($firstId); if ($firstMessageId === false) { throw new Exception('unrecognized post id: ' . $firstId); } -# FIXME: try to build better References by matching, maybe? +# TODO: try to build better References by matching, maybe? $inReplyTo = $references = $firstMessageId; } + else if ($mode == 'edit') { + $inReplyTo = $bridge->getMessageId($postId); + } $forumURL = 'http://' . $_SERVER['SERVER_NAME'] . dirname($_SERVER['SCRIPT_NAME']); @@ -90,6 +106,18 @@ function send_to_lists($config, $user, $mode, $data, $post_data) { $text = htmlspecialchars_decode($text); $text = wordwrap($text, 72); + if ($mode == 'edit') { + $edit_notice = <<<EOF +[This message has been edited.] + +EOF; + + $edit_header = 'Edit: '; + + $text = $edit_notice . $text; + $headers['Subject'] = $edit_header . $headers['Subject']; + } + # TODO: BBCode to Markdown (?) # Build the bridge footer @@ -171,6 +199,8 @@ EOF; $mailer = Mail::factory('sendmail'); +# FIXME: edited messages break the bijection between post and message ids! + # Register the message $seen = !$bridge->registerMessage($postId, $messageId, $inReplyTo, $references); |