summaryrefslogtreecommitdiff
path: root/src/list_post_receive.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/list_post_receive.php')
-rw-r--r--src/list_post_receive.php81
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";
+}
+
+?>