mime.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?
  2. /** mime.php
  3. **
  4. ** This contains the functions necessary to detect and decode MIME messages.
  5. **/
  6. function decodeMime($body, $bound, $type0, $type1) {
  7. if ($type0 == "multipart") {
  8. if ($body[0] == "")
  9. $i = 1;
  10. else
  11. $i = 0;
  12. $bound = trim($bound);
  13. $bound = "--$bound";
  14. while ($i < count($body)) {
  15. if (trim($body[$i]) == $bound) {
  16. $j = $i + 1;
  17. $p = 0;
  18. while (substr(trim($body[$j]), 0, strlen($bound)) != $bound) {
  19. $entity[$p] = $body[$j];
  20. $j++;
  21. $p++;
  22. }
  23. fetchEntityHeader($imapConnection, $entity, $ent_type0, $ent_type1, $ent_bound);
  24. $entity = decodeMime($entity, $ent_bound, $ent_type0, $ent_type1);
  25. $q = count($full_message);
  26. $full_message[$q] = $entity;
  27. }
  28. $i++;
  29. }
  30. } else if ($type0 == "text") {
  31. $entity_msg["TYPE0"] = "text";
  32. if ($type1 == "plain") {
  33. $entity_msg["TYPE1"] = "plain";
  34. for ($p = 0;$p < count($body);$p++) {
  35. $entity_msg["BODY"][$p] = parsePlainTextMessage($body[$p]);
  36. }
  37. } else if ($type1 == "html") {
  38. $entity_msg["TYPE1"] = "html";
  39. $entity_msg["BODY"] = $body;
  40. }
  41. $full_message[0] = $entity_msg;
  42. }
  43. return $full_message;
  44. }
  45. ?>