summaryrefslogtreecommitdiff
path: root/src/F2M.php
diff options
context:
space:
mode:
authoruckelman <uckelman@nomic.net>2010-04-20 22:00:24 +0000
committeruckelman <uckelman@nomic.net>2010-04-20 22:00:24 +0000
commit2ebfb781447380ccfd895c2ba7a77fc22e360d97 (patch)
tree40126e35aba97357cb213b66a597c1ec10cd8999 /src/F2M.php
parent4286e46d678bdd687aeb0c17ea7093fcdcc4b24f (diff)
* Added attachment support.
git-svn-id: https://vassalengine.svn.sourceforge.net/svnroot/vassalengine/site-src/trunk@6726 67b53d14-2c14-4ace-a08f-0dab2b34000c
Diffstat (limited to 'src/F2M.php')
-rw-r--r--src/F2M.php109
1 files changed, 72 insertions, 37 deletions
diff --git a/src/F2M.php b/src/F2M.php
index a3f30a5..4c5c904 100644
--- a/src/F2M.php
+++ b/src/F2M.php
@@ -1,15 +1,13 @@
<?php
try {
- send_to_lists($user, $mode, $data, $post_data);
+ send_to_lists($config, $user, $mode, $data, $post_data);
}
catch (Exception $e) {
trigger_error($e, E_USER_ERROR);
}
-# TODO: handle attachments
-
-function send_to_lists($user, $mode, $data, $post_data) {
+function send_to_lists($config, $user, $mode, $data, $post_data) {
print '<p>';
var_dump($data);
@@ -17,7 +15,6 @@ function send_to_lists($user, $mode, $data, $post_data) {
print '</p>';
require_once('Mail.php');
-# require_once('Mail/mime.php');
require_once(__DIR__ . '/Bridge.php');
require_once(__DIR__ . '/PhpBB3.php');
@@ -58,7 +55,7 @@ function send_to_lists($user, $mode, $data, $post_data) {
if ($mode == 'reply') {
$firstId = $data['topic_first_post_id'];
$firstMessageId = $bridge->getMessageId($firstId);
- if ($firstMessageId === null) {
+ if ($firstMessageId === false) {
throw new Exception('unrecognized post id: ' . $firstId);
}
@@ -76,10 +73,7 @@ function send_to_lists($user, $mode, $data, $post_data) {
'Subject' => $subject,
'Date' => $date,
'Message-Id' => $messageId,
- 'X-BeenThere' => $forumURL,
- 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed',
- 'MIME-Version' => '1.0',
- 'Conten-Transfer-Encoding' => '8bit'
+ 'X-BeenThere' => $forumURL
);
if ($inReplyTo !== null) {
@@ -96,43 +90,84 @@ function send_to_lists($user, $mode, $data, $post_data) {
$text = htmlspecialchars_decode($text);
$text = wordwrap($text, 72);
- # Add the bridge footer
- $postURL = "$forumURL/viewtopic.php?p=$postId#p$postId";
+# TODO: BBCode to Markdown (?)
+ # Build the bridge footer
+ $postURL = "$forumURL/viewtopic.php?p=$postId#p$postId";
$footer = <<<EOF
-
_______________________________________________
Read this topic online here:
$postURL
EOF;
- $body = $text . $footer;
-
-/*
- $msg = $data['message'];
- $msg = nl2br($msg);
- $msg = str_replace(':' . $data['bbcode_uid'], '', $msg);
+ $body = null;
- $parser = new HTML_BBCodeParser();
- $parser->setText($msg);
- $parser->parse();
- $html = $parser->getParsed();
-
- $mime = new Mail_mime("\n");
- $mime->setTXTBody($text);
- $mime->setHTMLBody($html);
-
- $body = $mime->get(array(
- 'text_encoding' => '8bit',
- 'html_encoding' => 'quoted-printable',
- 'head_charset' => 'iso-8859-1',
- 'text_charset' => 'utf-8',
- 'html_charset' => 'iso-8859-1'
- ));
+ # Handle attachements, if any
+ if (empty($data['attachment_data'])) {
+ # No attachments, send a plain email
+ $body = $text . "\n" . $footer;
+ $headers['Content-Type'] = 'text/plain; charset=UTF-8; format=flowed';
+ $headers['Content-Transfer-Encoding'] = '8bit';
+ }
+ else {
+ # Attachments, build a MIME email
+ require_once('Mail/mimePart.php');
+
+ $headers['MIME-Version'] = '1.0';
+
+ $params = array('content_type' => 'multipart/mixed');
+ $mime = new Mail_mimePart('', $params);
+
+ # Build the main body
+ $params = array(
+ 'content_type' => 'text/plain',
+ 'charset' => 'utf-8',
+ 'encoding' => '8bit',
+ 'disposition' => 'inline'
+ );
+ $mime->addSubPart($text, $params);
+
+ # Build each attachment
+ foreach ($data['attachment_data'] as $a) {
+ $attachId = $a['attach_id'];
+ $adata = $phpbb->getAttachmentData($attachId);
+ if ($adata === false) {
+ throw new Exception('unrecognized attachment id: ' . $attachId);
+ }
+
+ $afile = $phpbb_root_path . $config['upload_path'] . '/' .
+ utf8_basename($adata['physical_filename']);
+
+ $bytes = file_get_contents($afile);
+ if ($bytes === false) {
+ throw new Exception('failed to read file: ' . $afile);
+ }
+
+ $params = array(
+ 'content_type' => $adata['mimetype'],
+ 'encoding' => 'base64',
+ 'disposition' => 'attachment',
+ 'dfilename' => $adata['real_filename'],
+ 'description' => $adata['attach_comment']
+ );
+ $mime->addSubPart($bytes, $params);
+ }
- $headers = $mime->headers($headers);
-*/
+ # Build footer
+ $params = array(
+ 'content_type' => 'text/plain',
+ 'charset' => 'utf-8',
+ 'encoding' => '8bit',
+ 'disposition' => 'inline'
+ );
+ $mime->addSubPart($footer, $params);
+
+ # Encode the message
+ $msg = $mime->encode();
+ $headers = array_merge($headers, $msg['headers']);
+ $body = $msg['body'];
+ }
$mailer = Mail::factory('sendmail');