Mailinglist
 All Data Structures Files Functions Variables Pages
Data Structures | Functions
MailinglistMessage.class.php File Reference

Definition of MailinglistMessage (and related) classes. More...

Go to the source code of this file.

Data Structures

class  MailinglistHeader
 class MailinglistHeader More...
 
class  MailinglistMessagePart
 MailinglistMessagePart A class to represent a piece of a email message. More...
 
class  MailinglistMessage
 Class defining the contents of an e-mail message. More...
 

Functions

 mailinglist_message_rfc2047 ($string)
 mailinglist_message_rfc2047() More...
 

Detailed Description

Definition of MailinglistMessage (and related) classes.

References: RFC5322 (which superceeds RFC822 and RFC2822) EMail Format RFC2045, RFC2046, RFC2047, RFC2048, RFC2049 MIME Format RFC6657 Update charset

Definition in file MailinglistMessage.class.php.

Function Documentation

mailinglist_message_rfc2047 (   $string)

mailinglist_message_rfc2047()

do rfc2047 conversion on a string.

Parameters
stringthe string to parse.
Returns
the string with rfc2047 conversions done.

Tries to be more general than just taking a single atom so can be used on things like the subject header.

Todo:
should insure that the string is bounded by atom boundries.

Definition at line 26 of file MailinglistMessage.class.php.

Referenced by MailinglistHeader\get_atom(), and MailinglistMessagePart\header().

26  {
27 
28  if (is_array($string)) {
29  $result = array();
30  foreach ($string as $idx => $value) {
31  $result[$idx] = mailinglist_message_rfc2047($value);
32  }
33  }
34  else {
35  // RFC 2047 Processing
36  // Look for tokens like: =?charset?encoding?text?=
37  //
38  $result = "";
39  while ($string) {
40  $pos = strpos($string, '=?');
41  if ($pos === FALSE) {
42  $result .= $string;
43  $string = "";
44  break;
45  }
46  if ($pos > 0) {
47  $result .= substr($string, 0, $pos);
48  $string = substr($string, $pos);
49  }
50  $pos0 = strpos($string, '?=');
51  if ($pos0 === FALSE) { // no end, so no more encoded-words
52  $result .= $string;
53  $string = "";
54  break;
55  }
56  $pos1 = strpos($string, ' ');
57  if ($pos1 !== FALSE AND $pos1 < $pos0) {
58  $result .= substr($string, 0, 2);
59  $string = substr($string, 2);
60  continue;
61  }
62  $pos1 = strpos($string, "\t");
63  if ($pos1 !== FALSE AND $pos1 < $pos0) {
64  $result .= substr($string, 0, 2);
65  $string = substr($string, 2);
66  continue;
67  }
68  $pos1 = strpos($string, '?', 2);
69  if ($pos1 >= $pos0) {
70  // not enough ? in between
71  $result .= substr($string, 0, 2);
72  $string = substr($string, 2);
73  continue;
74  }
75  $charset = substr($string, 2, $pos1-2);
76  $pos2 = strpos($string, '?', $pos1+1);
77  if ($pos2 >= $pos0) {
78  // not enough ? in between
79  $result .= substr($string, 0, 2);
80  $string = substr($string, 2);
81  continue;
82  }
83  $encoding = substr($string, $pos1+1, $pos2 - $pos1 - 1);
84  $text = substr($string, $pos2+1, $pos0 - $pos2 -1);
85  $string = substr($string, $pos0+2);
86  switch (strtolower($encoding)) {
87  case 'b':
88  $text = base64_decode($text);
89  break;
90  case 'q':
91  $text = quoted_printable_decode($text);
92  break;
93  default:
94  // We don't know what to do, so just pass it on.
95  $text = '=?' . $charset . '?' . $encoding . '?=';
96  break;
97  }
98  $text = iconv($charset, 'UTF-8', $text);
99  $result .= $text;
100  }
101  }
102  return $result;
103  }
mailinglist_message_rfc2047($string)
mailinglist_message_rfc2047()

Here is the caller graph for this function: