summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruckelman <uckelman@nomic.net>2010-05-09 21:13:52 +0000
committeruckelman <uckelman@nomic.net>2010-05-09 21:13:52 +0000
commit0c631686f12ffcedd8a1b6545e94a4537ef10d77 (patch)
tree9bec839fec87df000dd3620a5112a39a46a25bd8
parent2223ec1cabbb3c8788ff7087da53ab214232d649 (diff)
Added getFlattenedParts() for conversion to phpBB-ish message.
git-svn-id: https://vassalengine.svn.sourceforge.net/svnroot/vassalengine/site-src/trunk@6832 67b53d14-2c14-4ace-a08f-0dab2b34000c
-rw-r--r--src/EmailMessage.php69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/EmailMessage.php b/src/EmailMessage.php
index 9313329..7eb6201 100644
--- a/src/EmailMessage.php
+++ b/src/EmailMessage.php
@@ -43,6 +43,13 @@ abstract class EmailMessage implements Message {
return $this->msg;
}
+ public function getFlattenedParts() {
+ $text = '';
+ $attachments = array();
+ self::flatten_parts($text, $attachments);
+ return array($text, $attachments);
+ }
+
protected static function decode_raw_message($input) {
$params['include_bodies'] = true;
$params['decode_bodies'] = true;
@@ -64,6 +71,68 @@ abstract class EmailMessage implements Message {
$addr = Mail_RFC822::parseAddressList($s);
return strtolower($addr[0]->mailbox . '@' . $addr[0]->host);
}
+
+ protected static function flatten_parts($part, &$text, &$attachments) {
+ switch ($part->ctype_primary) {
+ case 'multipart':
+ if (!isset($part->parts)) {
+ throw new Exception('multipart without parts!');
+ }
+
+ foreach ($part->parts as $subpart) {
+ flatten_parts($subpart, $text, $attachments);
+ }
+ break;
+
+ case 'text':
+ # text/* parts go into the message body.
+ if (!isset($part->body)) {
+ throw new Exception('text without body!');
+ }
+
+ $text .= $part->body;
+ break;
+
+ default:
+ # Everything else goes into phpBB as an attachment.
+ if (!isset($part->body)) {
+ throw new Exception('attachment without body!');
+ }
+
+ # try to find a filename
+ $filename = '';
+ if (isset($part->d_parameters)) {
+ if (array_key_exists('filename', $part->d_parameters)) {
+ $filename = $part->d_parameters['filename'];
+ }
+ else if (array_key_exists('name', $part->d_parameters)) {
+ $filename = $part->d_parameters['name'];
+ }
+ }
+
+ if ($filename == '') {
+ if (isset($part->ctype_parameters)) {
+ if (array_key_exists('name', $part->ctype_parameters)) {
+ $filename = $part->d_parameters['name'];
+ }
+ }
+ }
+
+ $mimetype = $part->ctype_primary . '/' . $part->ctype_secondary;
+
+ $params = array(
+ 'filename' => $filename,
+ 'mimetype' => $mimetype,
+ 'data' => $part->body
+ );
+
+ if (array_key_exists('content-description', $part->headers)) {
+ $params['comment'] = $part->headers['content-description'];
+ }
+
+ $attachments[] = $params;
+ }
+ }
}
?>