diff options
author | uckelman <uckelman@nomic.net> | 2010-04-30 21:38:50 +0000 |
---|---|---|
committer | uckelman <uckelman@nomic.net> | 2010-04-30 21:38:50 +0000 |
commit | e3f6bc31ff1e108de52faae926d96a73df32557e (patch) | |
tree | a2cb04492d116aeb686355f3451249a624135de6 /src/list_post_receive.php | |
parent | 340fc57f4573f7b623edad830244f1f5096ab8ab (diff) |
mv M2F.php list_post_receive.php.
git-svn-id: https://vassalengine.svn.sourceforge.net/svnroot/vassalengine/site-src/trunk@6797 67b53d14-2c14-4ace-a08f-0dab2b34000c
Diffstat (limited to 'src/list_post_receive.php')
-rw-r--r-- | src/list_post_receive.php | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/list_post_receive.php b/src/list_post_receive.php new file mode 100644 index 0000000..0896324 --- /dev/null +++ b/src/list_post_receive.php @@ -0,0 +1,81 @@ +<?php + +# TODO: logging! +# TODO: translation of quoting to bbcode? + +try { + require_once(__DIR__ . '/Bridge.php'); + require_once(__DIR__ . '/MailmanLib.php'); + require_once(__DIR__ . '/MailmanMessage.php'); + require_once(__DIR__ . '/PhpBB3.php'); + + # Read the message from STDIN + $url = 'php://stdin'; + + $input = read_raw_message($url); + $msg = new MailmanMessage($input); + + $messageId = $msg->getMessageId(); + $inReplyTo = $msg->getInReplyTo(); + $rererences = $msg->getReferences(); + + $bridge = new Bridge(); + $editId = $bridge->registerByMessageId($messageId, $inReplyTo); + + try { + if ($editId === false) { + # This message has already been processed, bail out + print 'Message id already seen, skipping: ' . $messageId . "\n"; + exit; + } + + $phpbb = new PhpBB3(); + + $forumId = $topicId = null; + $postType = null; + + if ($inReplyTo) { + # Possibly a reply to an existing topic + $parentId = $bridge->getPostId($inReplyTo); + if ($parentId === false) { + throw new Exception('unrecognized Reply-To: ' . $inReplyTo); + } + + $ids = $phpbb->getTopicAndForumIds($parentId); + if ($ids === false) { + throw new Exception('unrecognized parent id: ' . $parentId); + } + + # Found the parent's forum and topic, post to those + $forumId = $ids['forum_id']; + $topicId = $ids['topic_id']; + $postType = 'reply'; + } + else { + # A message starting a new topic, post to default forum for its source + $forumId = $bridge->getDefaultForumId($msg->getSource()); + if ($forumId === false) { + throw new Exception('unrecognized source: ' . $msg->getSource()); + } + + $postType = 'post'; + } + +# FIXME: the subject and body may be charset encoded---need to decode these +# before posting! + + # Post the message to the forum + $postId = $phpbb->postMessage($postType, $forumId, $topicId, $msg); + $bridge->setPostId($messageId, $postId); + } + catch (Exception $e) { + # Bridging failed, unregister message. + $bridge->unregisterMessage($editId); + throw $e; + } +} +catch (Exception $e) { + print "$e\n"; +} + +?> |