"; - $body .= "ATTACHMENTS:"; - $body .= " |
";
- $num = 0;
+ if ($message->header->type0 == "multipart" &&
+ $message->header->type1 == "alternative" &&
+ $show_html_default && ! $textOnly) {
+ $entity = findDisplayEntityHTML($message);
+ if ($entity != 0)
+ return $entity;
+ }
+
+ // Show text/plain or text/html -- the first one we find.
+ if ($message->header->type0 == 'text' &&
+ ($message->header->type1 == 'plain' ||
+ $message->header->type1 == 'html') &&
+ isset($message->header->entity_id))
+ return $message->header->entity_id;
- for ($i = 0; $i < count($message["ENTITIES"]); $i++) {
- /** If we've displayed this entity, go to the next one **/
- if ($ent_num == $i)
- continue;
+ for ($i=0; isset($message->entities[$i]); $i++) {
+ $entity = findDisplayEntity($message->entities[$i], $textOnly);
+ if ($entity != 0)
+ return $entity;
+ }
+
+ return 0;
+ }
+
+ // Shows the HTML version
+ function findDisplayEntityHTML ($message) {
+ if ($message->header->type0 == 'text' &&
+ $message->header->type1 == 'html' &&
+ isset($message->header->entity_id))
+ return $message->header->entity_id;
+ for ($i = 0; isset($message->entities[$i]); $i ++) {
+ $entity = findDisplayEntityHTML($message->entities[$i]);
+ if ($entity != 0)
+ return $entity;
+ }
+ return 0;
+ }
- $type0 = strtolower($message["ENTITIES"][$i]["TYPE0"]);
- $type1 = strtolower($message["ENTITIES"][$i]["TYPE1"]);
+ /** This returns a parsed string called $body. That string can then
+ be displayed as the actual message in the HTML. It contains
+ everything needed, including HTML Tags, Attachments at the
+ bottom, etc.
+ **/
+ function formatBody($imap_stream, $message, $color, $wrap_at) {
+ // this if statement checks for the entity to show as the
+ // primary message. To add more of them, just put them in the
+ // order that is their priority.
+ global $startMessage, $username, $key, $imapServerAddress, $imapPort;
- $num++;
- $filename = $message["ENTITIES"][$i]["FILENAME"];
- if (trim($filename) == "") {
- $display_filename = "untitled$i";
- } else {
- $display_filename = $filename;
- }
+ $id = $message->header->id;
+ $urlmailbox = urlencode($message->header->mailbox);
- $urlMailbox = urlencode($message["INFO"]["MAILBOX"]);
- $id = $message["INFO"]["ID"];
- $body .= " " . $display_filename . " (TYPE: $type0/$type1) "; - } + // Get the right entity and redefine message to be this entity + // Pass the 0 to mean that we want the 'best' viewable one + $ent_num = findDisplayEntity ($message, 0); + $body_message = getEntity($message, $ent_num); + if (($body_message->header->type0 == "text") || + ($body_message->header->type0 == "rfc822")) { + + $body = mime_fetch_body ($imap_stream, $id, $ent_num); + $body = decodeBody($body, $body_message->header->encoding); + + // If there are other types that shouldn't be formatted, add + // them here + if ($body_message->header->type1 != "html") { + translateText($body, $wrap_at, $body_message->header->charset); + } + + $body .= " "; + + /** Display the ATTACHMENTS: message if there's more than one part **/ $body .= " |
\n"; + $body .= _("Attachments") . ':'; + $body .= " |
---|
\n";
+
+ $body .= " |