summaryrefslogtreecommitdiff
path: root/src/M2F.php
blob: 48e1c330f1758f9b53655595b4b4daa657bd5ba7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php

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);

$bridge = new Bridge();

$seen = !$bridge->registerMessage($msg->getMessageId(),
                                  $msg->getInReplyTo(),
                                  $msg->getReferences());

if ($seen) {
  # This message has already been processed.
  print "Message id already seen, skipping: $messageId\n";
  exit;
}

$phpbb = new PhpBB3();

$inReplyTo = $msg->getInReplyTo();

$forumId = $topicId = -1;
$postType = null;

if ($inReplyTo) { 
  # A reply to an existing topic
# FIXME: we don't want exceptions here?
  $parentId = $bridge->getPostId($inReplyTo);
  $ids = $phpbb->getTopicAndForumIds($parentId);
  $forumId = $ids['forum_id'];
  $topicId = $ids['topic_id'];
  $postType = 'reply';
}
else {
  # A message starting a new topic
  $forumId = $bridge->getDefaultForumId($msg->getSource());
  $postType = 'post';
}

# Post the message to the forum
$phpbb->postMessage($postType, $forumId, $topicId, $msg);

$bridge->setPostId($messageId, $postId);

?>