- /** 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($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.
- **/
- $id = $message["INFO"]["ID"];
- $urlmailbox = urlencode($message["INFO"]["MAILBOX"]);
-
- if (containsType($message, "text", "html", $ent_num)) {
- $body = decodeBody($message["ENTITIES"][$ent_num]["BODY"], $message["ENTITIES"][$ent_num]["ENCODING"]);
- } else if (containsType($message, "text", "plain", $ent_num)) {
- $body = decodeBody($message["ENTITIES"][$ent_num]["BODY"], $message["ENTITIES"][$ent_num]["ENCODING"]);
- }
- // add other primary displaying message types here
- else {
- // find any type that's displayable
- if (containsType($message, "text", "any_type", $ent_num)) {
- $body = decodeBody($message["ENTITIES"][$ent_num]["BODY"], $message["ENTITIES"][$ent_num]["ENCODING"]);
- } else if (containsType($message, "message", "any_type", $ent_num)) {
- $body = decodeBody($message["ENTITIES"][$ent_num]["BODY"], $message["ENTITIES"][$ent_num]["ENCODING"]);
+ // I did most of the MIME stuff yesterday (June 20, 2000), but I couldn't
+ // figure out how to do this part, so I decided to go to bed. I woke up
+ // in the morning and had a flash of insight. I went to the white-board
+ // and scribbled it out, then spent a bit programming it, and this is the
+ // result. Nothing complicated, but I think my brain was fried yesterday.
+ // Funny how that happens some times.
+ //
+ // This gets properties in a nested parenthesisized list. For example,
+ // this would get passed something like: ("attachment" ("filename" "luke.tar.gz"))
+ // This returns an array called $props with all paired up properties.
+ // It ignores the "attachment" for now, maybe that should change later
+ // down the road. In this case, what is returned is:
+ // $props[0]["name"] = "filename";
+ // $props[0]["value"] = "luke.tar.gz";
+ function mime_get_props ($props, $structure) {
+ global $debug_mime;
+ while (strlen($structure) > 0) {
+ $structure = trim($structure);
+ $char = substr($structure, 0, 1);
+
+ if ($char == "\"") {
+ $pos = 1;
+ $char = substr($structure, $pos, 1);
+ while ($char != "\"" && $pos < strlen($structure)) {
+ $tmp .= $char;
+ $pos++;
+ $char = substr($structure, $pos, 1);
+ }
+ $structure = trim(substr($structure, strlen($tmp) + 2));
+ $char = substr($structure, 0, 1);
+
+ if ($char == "\"") {
+ $pos = 1;
+ $char = substr($structure, $pos, 1);
+ while ($char != "\"" && $pos < strlen($structure)) {
+ $value .= $char;
+ $pos++;
+ $char = substr($structure, $pos, 1);
+ }
+ $structure = trim(substr($structure, strlen($tmp) + 2));
+
+ $k = count($props);
+ $props[$k]["name"] = strtolower($tmp);
+ $props[$k]["value"] = $value;
+ } else if ($char == "(") {
+ $end = mime_match_parenthesis (0, $structure);
+ $sub = substr($structure, 1, $end-1);
+ $props = mime_get_props($props, $sub);
+ $structure = substr($structure, strlen($sub) + 2);
+ }
+ return $props;
+ } else if ($char == "(") {
+ $end = mime_match_parenthesis (0, $structure);
+ $sub = substr($structure, 1, $end-1);
+ $props = mime_get_props($props, $sub);
+ $structure = substr($structure, strlen($sub) + 2);
+ return $props;
+ } else {
+ return $props;
+ }
+ }
+ }
+
+ // Matches parenthesis. It will return the position of the matching
+ // parenthesis in $structure. For instance, if $structure was:
+ // ("text" "plain" ("val1name", "1") nil ... )
+ // x x
+ // then this would return 42 to match up those two.
+ function mime_match_parenthesis ($pos, $structure) {
+ $char = substr($structure, $pos, 1);
+
+ // ignore all extra characters
+ // If inside of a string, skip string -- Boundary IDs and other
+ // things can have ) in them.
+ while ($pos < strlen($structure)) {
+ $pos++;
+ $char = substr($structure, $pos, 1);
+ if ($char == ")") {
+ return $pos;
+ } else if ($char == '"') {
+ $pos ++;
+ while (substr($structure, $pos, 1) != '"' &&
+ $pos < strlen($structure)) {
+ $pos ++;
+ }
+ } else if ($char == "(") {
+ $pos = mime_match_parenthesis ($pos, $structure);