19d470aa |
1 | <?php |
2 | |
3 | /** |
4 | * Rfc822Header.class.php |
5 | * |
76911253 |
6 | * Copyright (c) 2003 The SquirrelMail Project Team |
19d470aa |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
9 | * This contains functions needed to handle mime messages. |
10 | * |
11 | * $Id$ |
2b646597 |
12 | * @package squirrelmail |
19d470aa |
13 | */ |
14 | |
2b646597 |
15 | /** |
19d470aa |
16 | * input: header_string or array |
2b646597 |
17 | * @package squirrelmail |
19d470aa |
18 | */ |
19 | class Rfc822Header { |
20 | var $date = '', |
21 | $subject = '', |
22 | $from = array(), |
23 | $sender = '', |
24 | $reply_to = array(), |
b268e66b |
25 | $mail_followup_to = array(), |
19d470aa |
26 | $to = array(), |
27 | $cc = array(), |
28 | $bcc = array(), |
29 | $in_reply_to = '', |
30 | $message_id = '', |
340d67c2 |
31 | $references = '', |
19d470aa |
32 | $mime = false, |
33 | $content_type = '', |
34 | $disposition = '', |
35 | $xmailer = '', |
36 | $priority = 3, |
37 | $dnt = '', |
f1232547 |
38 | $encoding = '', |
19d470aa |
39 | $mlist = array(), |
40 | $more_headers = array(); /* only needed for constructing headers |
41 | in smtp.php */ |
42 | function parseHeader($hdr) { |
43 | if (is_array($hdr)) { |
44 | $hdr = implode('', $hdr); |
45 | } |
19d470aa |
46 | /* First we unfold the header */ |
0185d212 |
47 | $hdr = trim(str_replace(array("\r\n\t", "\r\n "),array(' ', ' '), $hdr)); |
19d470aa |
48 | |
49 | /* Now we can make a new header array with */ |
50 | /* each element representing a headerline */ |
51 | $hdr = explode("\r\n" , $hdr); |
52 | foreach ($hdr as $line) { |
53 | $pos = strpos($line, ':'); |
54 | if ($pos > 0) { |
55 | $field = substr($line, 0, $pos); |
340d67c2 |
56 | if (!strstr($field,' ')) { /* valid field */ |
57 | $value = trim(substr($line, $pos+1)); |
58 | $this->parseField($field, $value); |
59 | } |
19d470aa |
60 | } |
61 | } |
62 | if ($this->content_type == '') { |
63 | $this->parseContentType('text/plain; charset=us-ascii'); |
64 | } |
65 | } |
66 | |
67 | function stripComments($value) { |
68 | $result = ''; |
19d470aa |
69 | $cnt = strlen($value); |
70 | for ($i = 0; $i < $cnt; ++$i) { |
71 | switch ($value{$i}) { |
72 | case '"': |
73 | $result .= '"'; |
74 | while ((++$i < $cnt) && ($value{$i} != '"')) { |
75 | if ($value{$i} == '\\') { |
76 | $result .= '\\'; |
77 | ++$i; |
78 | } |
79 | $result .= $value{$i}; |
80 | } |
81 | $result .= $value{$i}; |
82 | break; |
83 | case '(': |
84 | $depth = 1; |
85 | while (($depth > 0) && (++$i < $cnt)) { |
86 | switch($value{$i}) { |
87 | case '\\': |
88 | ++$i; |
89 | break; |
90 | case '(': |
91 | ++$depth; |
92 | break; |
93 | case ')': |
94 | --$depth; |
95 | break; |
96 | default: |
97 | break; |
98 | } |
99 | } |
100 | break; |
101 | default: |
102 | $result .= $value{$i}; |
103 | break; |
104 | } |
105 | } |
106 | return $result; |
107 | } |
108 | |
109 | function parseField($field, $value) { |
110 | $field = strtolower($field); |
111 | switch($field) { |
112 | case 'date': |
340d67c2 |
113 | $value = $this->stripComments($value); |
19d470aa |
114 | $d = strtr($value, array(' ' => ' ')); |
115 | $d = explode(' ', $d); |
116 | $this->date = getTimeStamp($d); |
117 | break; |
118 | case 'subject': |
119 | $this->subject = $value; |
120 | break; |
121 | case 'from': |
122 | $this->from = $this->parseAddress($value,true); |
123 | break; |
124 | case 'sender': |
125 | $this->sender = $this->parseAddress($value); |
126 | break; |
127 | case 'reply-to': |
128 | $this->reply_to = $this->parseAddress($value, true); |
129 | break; |
b268e66b |
130 | case 'mail-followup-to': |
131 | $this->mail_followup_to = $this->parseAddress($value, true); |
132 | break; |
19d470aa |
133 | case 'to': |
134 | $this->to = $this->parseAddress($value, true); |
135 | break; |
136 | case 'cc': |
137 | $this->cc = $this->parseAddress($value, true); |
138 | break; |
139 | case 'bcc': |
140 | $this->bcc = $this->parseAddress($value, true); |
141 | break; |
142 | case 'in-reply-to': |
143 | $this->in_reply_to = $value; |
144 | break; |
145 | case 'message-id': |
340d67c2 |
146 | $value = $this->stripComments($value); |
19d470aa |
147 | $this->message_id = $value; |
148 | break; |
340d67c2 |
149 | case 'references': |
150 | $value = $this->stripComments($value); |
151 | $this->references = $value; |
152 | break; |
153 | case 'x-confirm-reading-to': |
154 | case 'return-receipt-to': |
19d470aa |
155 | case 'disposition-notification-to': |
340d67c2 |
156 | $value = $this->stripComments($value); |
19d470aa |
157 | $this->dnt = $this->parseAddress($value); |
158 | break; |
159 | case 'mime-version': |
340d67c2 |
160 | $value = $this->stripComments($value); |
19d470aa |
161 | $value = str_replace(' ', '', $value); |
162 | $this->mime = ($value == '1.0' ? true : $this->mime); |
163 | break; |
164 | case 'content-type': |
340d67c2 |
165 | $value = $this->stripComments($value); |
19d470aa |
166 | $this->parseContentType($value); |
167 | break; |
168 | case 'content-disposition': |
340d67c2 |
169 | $value = $this->stripComments($value); |
19d470aa |
170 | $this->parseDisposition($value); |
171 | break; |
172 | case 'user-agent': |
173 | case 'x-mailer': |
340d67c2 |
174 | $this->xmailer = $value; |
19d470aa |
175 | break; |
176 | case 'x-priority': |
177 | $this->priority = $value; |
178 | break; |
179 | case 'list-post': |
340d67c2 |
180 | $value = $this->stripComments($value); |
19d470aa |
181 | $this->mlist('post', $value); |
182 | break; |
183 | case 'list-reply': |
340d67c2 |
184 | $value = $this->stripComments($value); |
19d470aa |
185 | $this->mlist('reply', $value); |
186 | break; |
187 | case 'list-subscribe': |
340d67c2 |
188 | $value = $this->stripComments($value); |
19d470aa |
189 | $this->mlist('subscribe', $value); |
190 | break; |
191 | case 'list-unsubscribe': |
340d67c2 |
192 | $value = $this->stripComments($value); |
19d470aa |
193 | $this->mlist('unsubscribe', $value); |
194 | break; |
195 | case 'list-archive': |
340d67c2 |
196 | $value = $this->stripComments($value); |
19d470aa |
197 | $this->mlist('archive', $value); |
198 | break; |
199 | case 'list-owner': |
340d67c2 |
200 | $value = $this->stripComments($value); |
19d470aa |
201 | $this->mlist('owner', $value); |
202 | break; |
203 | case 'list-help': |
340d67c2 |
204 | $value = $this->stripComments($value); |
19d470aa |
205 | $this->mlist('help', $value); |
206 | break; |
ba4d5a32 |
207 | case 'list-id': |
208 | $value = $this->stripComments($value); |
209 | $this->mlist('id', $value); |
210 | break; |
19d470aa |
211 | default: |
212 | break; |
213 | } |
214 | } |
14882b16 |
215 | |
216 | function getAddressTokens($address) { |
217 | $aTokens = array(); |
218 | $aAddress = array(); |
14882b16 |
219 | $aSpecials = array('(' ,'<' ,',' ,';' ,':'); |
220 | $aReplace = array(' (',' <',' ,',' ;',' :'); |
221 | $address = str_replace($aSpecials,$aReplace,$address); |
55243181 |
222 | $iCnt = strlen($address); |
14882b16 |
223 | $i = 0; |
224 | while ($i < $iCnt) { |
225 | $cChar = $address{$i}; |
226 | switch($cChar) |
227 | { |
228 | case '<': |
229 | $iEnd = strpos($address,'>',$i+1); |
230 | if (!$iEnd) { |
231 | $sToken = substr($address,$i); |
232 | $i = $iCnt; |
233 | } else { |
234 | $sToken = substr($address,$i,$iEnd - $i +1); |
235 | $i = $iEnd; |
236 | } |
237 | $sToken = str_replace($aReplace, $aSpecials,$sToken); |
1f0269d6 |
238 | if($sToken) $aTokens[] = $sToken; |
14882b16 |
239 | break; |
240 | case '"': |
241 | $iEnd = strpos($address,$cChar,$i+1); |
0b4d4be7 |
242 | if ($iEnd) { |
243 | // skip escaped quotes |
244 | $prev_char = $address{$iEnd-1}; |
245 | while ($prev_char === '\\' && substr($address,$iEnd-2,2) !== '\\\\') { |
246 | $iEnd = strpos($address,$cChar,$iEnd+1); |
247 | if ($iEnd) { |
248 | $prev_char = $address{$iEnd-1}; |
249 | } else { |
250 | $prev_char = false; |
251 | } |
252 | } |
253 | } |
14882b16 |
254 | if (!$iEnd) { |
255 | $sToken = substr($address,$i); |
256 | $i = $iCnt; |
257 | } else { |
258 | // also remove the surrounding quotes |
259 | $sToken = substr($address,$i+1,$iEnd - $i -1); |
260 | $i = $iEnd; |
261 | } |
262 | $sToken = str_replace($aReplace, $aSpecials,$sToken); |
72956ab6 |
263 | if ($sToken) $aTokens[] = $sToken; |
14882b16 |
264 | break; |
265 | case '(': |
0b4d4be7 |
266 | array_pop($aTokens); //remove inserted space |
14882b16 |
267 | $iEnd = strpos($address,')',$i); |
268 | if (!$iEnd) { |
269 | $sToken = substr($address,$i); |
270 | $i = $iCnt; |
271 | } else { |
55243181 |
272 | $iDepth = 1; |
273 | $iComment = $i; |
274 | while (($iDepth > 0) && (++$iComment < $iCnt)) { |
275 | $cCharComment = $address{$iComment}; |
276 | switch($cCharComment) { |
277 | case '\\': |
278 | ++$iComment; |
279 | break; |
280 | case '(': |
281 | ++$iDepth; |
282 | break; |
283 | case ')': |
284 | --$iDepth; |
285 | break; |
286 | default: |
287 | break; |
288 | } |
289 | } |
290 | if ($iDepth == 0) { |
291 | $sToken = substr($address,$i,$iComment - $i +1); |
292 | $i = $iComment; |
293 | } else { |
294 | $sToken = substr($address,$i,$iEnd - $i + 1); |
295 | $i = $iEnd; |
296 | } |
14882b16 |
297 | } |
0b4d4be7 |
298 | // check the next token in case comments appear in the middle of email addresses |
299 | $prevToken = end($aTokens); |
300 | if (!in_array($prevToken,$aSpecials,true)) { |
43c0e295 |
301 | if ($i+1<strlen($address) && !in_array($address{$i+1},$aSpecials,true)) { |
0b4d4be7 |
302 | $iEnd = strpos($address,' ',$i+1); |
303 | if ($iEnd) { |
304 | $sNextToken = trim(substr($address,$i+1,$iEnd - $i -1)); |
305 | $i = $iEnd-1; |
306 | } else { |
a5ae4bc8 |
307 | $sNextToken = trim(substr($address,$i+1)); |
0b4d4be7 |
308 | $i = $iCnt; |
309 | } |
310 | // remove the token |
311 | array_pop($aTokens); |
312 | // create token and add it again |
313 | $sNewToken = $prevToken . $sNextToken; |
1f0269d6 |
314 | if($sNewToken) $aTokens[] = $sNewToken; |
0b4d4be7 |
315 | } |
316 | } |
14882b16 |
317 | $sToken = str_replace($aReplace, $aSpecials,$sToken); |
1f0269d6 |
318 | if($sToken) $aTokens[] = $sToken; |
14882b16 |
319 | break; |
320 | case ',': |
0b4d4be7 |
321 | case ':': |
14882b16 |
322 | case ';': |
323 | case ' ': |
324 | $aTokens[] = $cChar; |
325 | break; |
326 | default: |
327 | $iEnd = strpos($address,' ',$i+1); |
328 | if ($iEnd) { |
329 | $sToken = trim(substr($address,$i,$iEnd - $i)); |
330 | $i = $iEnd-1; |
331 | } else { |
332 | $sToken = trim(substr($address,$i)); |
333 | $i = $iCnt; |
334 | } |
335 | if ($sToken) $aTokens[] = $sToken; |
336 | } |
337 | ++$i; |
338 | } |
339 | return $aTokens; |
340 | } |
341 | function createAddressObject(&$aStack,&$aComment,&$sEmail,$sGroup='') { |
0b4d4be7 |
342 | //$aStack=explode(' ',implode('',$aStack)); |
14882b16 |
343 | if (!$sEmail) { |
344 | while (count($aStack) && !$sEmail) { |
345 | $sEmail = trim(array_pop($aStack)); |
346 | } |
347 | } |
348 | if (count($aStack)) { |
349 | $sPersonal = trim(implode('',$aStack)); |
350 | } else { |
351 | $sPersonal = ''; |
352 | } |
353 | if (!$sPersonal && count($aComment)) { |
354 | $sComment = trim(implode(' ',$aComment)); |
355 | $sPersonal .= $sComment; |
356 | } |
357 | $oAddr =& new AddressStructure(); |
358 | if ($sPersonal && substr($sPersonal,0,2) == '=?') { |
359 | $oAddr->personal = encodeHeader($sPersonal); |
360 | } else { |
361 | $oAddr->personal = $sPersonal; |
362 | } |
0b4d4be7 |
363 | // $oAddr->group = $sGroup; |
14882b16 |
364 | $iPosAt = strpos($sEmail,'@'); |
365 | if ($iPosAt) { |
366 | $oAddr->mailbox = substr($sEmail, 0, $iPosAt); |
367 | $oAddr->host = substr($sEmail, $iPosAt+1); |
368 | } else { |
369 | $oAddr->mailbox = $sEmail; |
370 | $oAddr->host = false; |
371 | } |
14882b16 |
372 | $sEmail = ''; |
373 | $aStack = $aComment = array(); |
374 | return $oAddr; |
375 | } |
376 | |
e74ba378 |
377 | /* |
378 | * parseAddress: recursive function for parsing address strings and store |
379 | * them in an address stucture object. |
380 | * input: $address = string |
381 | * $ar = boolean (return array instead of only the |
382 | * first element) |
14882b16 |
383 | * $addr_ar = array with parsed addresses // obsolete |
384 | * $group = string // obsolete |
e74ba378 |
385 | * $host = string (default domainname in case of |
386 | * addresses without a domainname) |
387 | * $lookup = callback function (for lookup address |
388 | * strings which are probably nicks |
389 | * (without @ ) ) |
390 | * output: array with addressstructure objects or only one |
391 | * address_structure object. |
340d67c2 |
392 | * personal name: encoded: =?charset?Q|B?string?= |
393 | * quoted: "string" |
394 | * normal: string |
395 | * email : <mailbox@host> |
396 | * : mailbox@host |
397 | * This function is also used for validating addresses returned from compose |
14882b16 |
398 | * That's also the reason that the function became a little bit huge |
e74ba378 |
399 | */ |
340d67c2 |
400 | |
14882b16 |
401 | function parseAddress($address,$ar=false,$aAddress=array(),$sGroup='',$sHost='',$lookup=false) { |
402 | $aTokens = $this->getAddressTokens($address); |
403 | $sPersonal = $sEmail = $sComment = $sGroup = ''; |
404 | $aStack = $aComment = array(); |
405 | foreach ($aTokens as $sToken) { |
406 | $cChar = $sToken{0}; |
407 | switch ($cChar) |
340d67c2 |
408 | { |
409 | case '=': |
14882b16 |
410 | case '"': |
411 | case ' ': |
412 | $aStack[] = $sToken; |
340d67c2 |
413 | break; |
14882b16 |
414 | case '(': |
415 | $aComment[] = substr($sToken,1,-1); |
340d67c2 |
416 | break; |
3fcadedb |
417 | case ';': |
14882b16 |
418 | if ($sGroup) { |
29f842a4 |
419 | $aAddress[] = $this->createAddressObject($aStack,$aComment,$sEmail,$sGroup); |
14882b16 |
420 | $oAddr = end($aAddress); |
0b4d4be7 |
421 | if(!$oAddr || ((isset($oAddr)) && !$oAddr->mailbox && !$oAddr->personal)) { |
422 | $sEmail = $sGroup . ':;'; |
423 | } |
424 | $aAddress[] = $this->createAddressObject($aStack,$aComment,$sEmail,$sGroup); |
14882b16 |
425 | $sGroup = ''; |
426 | $aStack = $aComment = array(); |
427 | break; |
340d67c2 |
428 | } |
14882b16 |
429 | case ',': |
430 | $aAddress[] = $this->createAddressObject($aStack,$aComment,$sEmail,$sGroup); |
431 | break; |
432 | case ':': |
29f842a4 |
433 | $sGroup = trim(implode(' ',$aStack)); |
0b4d4be7 |
434 | $sGroup = preg_replace('/\s+/',' ',$sGroup); |
14882b16 |
435 | $aStack = array(); |
436 | break; |
437 | case '<': |
438 | $sEmail = trim(substr($sToken,1,-1)); |
439 | break; |
440 | case '>': |
441 | /* skip */ |
442 | break; |
443 | default: $aStack[] = $sToken; break; |
19d470aa |
444 | } |
445 | } |
14882b16 |
446 | /* now do the action again for the last address */ |
447 | $aAddress[] = $this->createAddressObject($aStack,$aComment,$sEmail); |
448 | /* try to lookup the addresses in case of invalid email addresses */ |
449 | $aProcessedAddress = array(); |
450 | foreach ($aAddress as $oAddr) { |
451 | $aAddrBookAddress = array(); |
452 | if (!$oAddr->host) { |
453 | $grouplookup = false; |
340d67c2 |
454 | if ($lookup) { |
14882b16 |
455 | $aAddr = call_user_func_array($lookup,array($oAddr->mailbox)); |
456 | if (isset($aAddr['email'])) { |
457 | if (strpos($aAddr['email'],',')) { |
458 | $grouplookup = true; |
459 | $aAddrBookAddress = $this->parseAddress($aAddr['email'],true); |
460 | } else { |
461 | $iPosAt = strpos($aAddr['email'], '@'); |
462 | $oAddr->mailbox = substr($aAddr['email'], 0, $iPosAt); |
463 | $oAddr->host = substr($aAddr['email'], $iPosAt+1); |
464 | if (isset($aAddr['name'])) { |
465 | $oAddr->personal = $aAddr['name']; |
466 | } else { |
467 | $oAddr->personal = encodeHeader($sPersonal); |
468 | } |
469 | } |
470 | } |
340d67c2 |
471 | } |
14882b16 |
472 | if (!$grouplookup && !$oAddr->mailbox) { |
473 | $oAddr->mailbox = trim($sEmail); |
474 | if ($sHost && $oAddr->mailbox) { |
475 | $oAddr->host = $sHost; |
340d67c2 |
476 | } |
8b53b4ba |
477 | } else if (!$grouplookup && !$oAddr->host) { |
478 | if ($sHost && $oAddr->mailbox) { |
479 | $oAddr->host = $sHost; |
480 | } |
481 | } |
14882b16 |
482 | } |
483 | if (!$aAddrBookAddress && $oAddr->mailbox) { |
484 | $aProcessedAddress[] = $oAddr; |
485 | } else { |
486 | $aProcessedAddress = array_merge($aProcessedAddress,$aAddrBookAddress); |
487 | } |
340d67c2 |
488 | } |
14882b16 |
489 | if ($ar) { |
490 | return $aProcessedAddress; |
19d470aa |
491 | } else { |
14882b16 |
492 | return $aProcessedAddress[0]; |
19d470aa |
493 | } |
14882b16 |
494 | } |
19d470aa |
495 | |
496 | function parseContentType($value) { |
497 | $pos = strpos($value, ';'); |
498 | $props = ''; |
499 | if ($pos > 0) { |
500 | $type = trim(substr($value, 0, $pos)); |
38d6fba7 |
501 | $props = trim(substr($value, $pos+1)); |
19d470aa |
502 | } else { |
503 | $type = $value; |
504 | } |
505 | $content_type = new ContentType($type); |
506 | if ($props) { |
507 | $properties = $this->parseProperties($props); |
508 | if (!isset($properties['charset'])) { |
509 | $properties['charset'] = 'us-ascii'; |
510 | } |
511 | $content_type->properties = $this->parseProperties($props); |
512 | } |
513 | $this->content_type = $content_type; |
514 | } |
2ddf00ae |
515 | |
516 | /* RFC2184 */ |
517 | function processParameters($aParameters) { |
518 | $aResults = array(); |
519 | $aCharset = array(); |
520 | // handle multiline parameters |
521 | foreach($aParameters as $key => $value) { |
522 | if ($iPos = strpos($key,'*')) { |
523 | $sKey = substr($key,0,$iPos); |
524 | if (!isset($aResults[$sKey])) { |
525 | $aResults[$sKey] = $value; |
526 | if (substr($key,-1) == '*') { // parameter contains language/charset info |
527 | $aCharset[] = $sKey; |
528 | } |
529 | } else { |
530 | $aResults[$sKey] .= $value; |
531 | } |
532 | } |
533 | } |
534 | foreach ($aCharset as $key) { |
535 | $value = $aResults[$key]; |
536 | // extract the charset & language |
537 | $charset = substr($value,0,strpos($value,"'")); |
538 | $value = substr($value,strlen($charset)+1); |
539 | $language = substr($value,0,strpos($value,"'")); |
540 | $value = substr($value,strlen($charset)+1); |
541 | // FIX ME What's the status of charset decode with language information ???? |
542 | $value = charset_decode($charset,$value); |
543 | $aResults[$key] = $value; |
544 | } |
545 | return $aResults; |
546 | } |
19d470aa |
547 | |
548 | function parseProperties($value) { |
549 | $propArray = explode(';', $value); |
550 | $propResultArray = array(); |
551 | foreach ($propArray as $prop) { |
552 | $prop = trim($prop); |
553 | $pos = strpos($prop, '='); |
554 | if ($pos > 0) { |
555 | $key = trim(substr($prop, 0, $pos)); |
556 | $val = trim(substr($prop, $pos+1)); |
557 | if ($val{0} == '"') { |
558 | $val = substr($val, 1, -1); |
559 | } |
560 | $propResultArray[$key] = $val; |
561 | } |
562 | } |
2ddf00ae |
563 | return $this->processParameters($propResultArray); |
19d470aa |
564 | } |
565 | |
566 | function parseDisposition($value) { |
567 | $pos = strpos($value, ';'); |
568 | $props = ''; |
569 | if ($pos > 0) { |
570 | $name = trim(substr($value, 0, $pos)); |
fc9269ec |
571 | $props = trim(substr($value, $pos+1)); |
19d470aa |
572 | } else { |
573 | $name = $value; |
574 | } |
575 | $props_a = $this->parseProperties($props); |
576 | $disp = new Disposition($name); |
577 | $disp->properties = $props_a; |
578 | $this->disposition = $disp; |
579 | } |
580 | |
581 | function mlist($field, $value) { |
582 | $res_a = array(); |
583 | $value_a = explode(',', $value); |
584 | foreach ($value_a as $val) { |
585 | $val = trim($val); |
586 | if ($val{0} == '<') { |
587 | $val = substr($val, 1, -1); |
588 | } |
589 | if (substr($val, 0, 7) == 'mailto:') { |
590 | $res_a['mailto'] = substr($val, 7); |
591 | } else { |
592 | $res_a['href'] = $val; |
593 | } |
594 | } |
595 | $this->mlist[$field] = $res_a; |
596 | } |
597 | |
598 | /* |
599 | * function to get the addres strings out of the header. |
600 | * Arguments: string or array of strings ! |
601 | * example1: header->getAddr_s('to'). |
602 | * example2: header->getAddr_s(array('to', 'cc', 'bcc')) |
603 | */ |
2c9ecd11 |
604 | function getAddr_s($arr, $separator = ',',$encoded=false) { |
19d470aa |
605 | $s = ''; |
606 | |
607 | if (is_array($arr)) { |
608 | foreach($arr as $arg) { |
2c9ecd11 |
609 | if ($this->getAddr_s($arg, $separator, $encoded)) { |
19d470aa |
610 | $s .= $separator . $result; |
611 | } |
612 | } |
613 | $s = ($s ? substr($s, 2) : $s); |
614 | } else { |
2c9ecd11 |
615 | $addr = $this->{$arr}; |
19d470aa |
616 | if (is_array($addr)) { |
617 | foreach ($addr as $addr_o) { |
618 | if (is_object($addr_o)) { |
2c9ecd11 |
619 | if ($encoded) { |
620 | $s .= $addr_o->getEncodedAddress() . $separator; |
621 | } else { |
622 | $s .= $addr_o->getAddress() . $separator; |
623 | } |
19d470aa |
624 | } |
625 | } |
626 | $s = substr($s, 0, -strlen($separator)); |
627 | } else { |
628 | if (is_object($addr)) { |
2c9ecd11 |
629 | if ($encoded) { |
630 | $s .= $addr->getEncodedAddress(); |
631 | } else { |
632 | $s .= $addr->getAddress(); |
633 | } |
19d470aa |
634 | } |
635 | } |
636 | } |
637 | return $s; |
638 | } |
639 | |
640 | function getAddr_a($arg, $excl_arr = array(), $arr = array()) { |
641 | if (is_array($arg)) { |
642 | foreach($arg as $argument) { |
643 | $arr = $this->getAddr_a($argument, $excl_arr, $arr); |
644 | } |
645 | } else { |
340d67c2 |
646 | $addr = $this->{$arg}; |
19d470aa |
647 | if (is_array($addr)) { |
648 | foreach ($addr as $next_addr) { |
649 | if (is_object($next_addr)) { |
650 | if (isset($next_addr->host) && ($next_addr->host != '')) { |
651 | $email = $next_addr->mailbox . '@' . $next_addr->host; |
652 | } else { |
653 | $email = $next_addr->mailbox; |
654 | } |
655 | $email = strtolower($email); |
656 | if ($email && !isset($arr[$email]) && !isset($excl_arr[$email])) { |
657 | $arr[$email] = $next_addr->personal; |
658 | } |
659 | } |
660 | } |
661 | } else { |
662 | if (is_object($addr)) { |
663 | $email = $addr->mailbox; |
664 | $email .= (isset($addr->host) ? '@' . $addr->host : ''); |
665 | $email = strtolower($email); |
666 | if ($email && !isset($arr[$email]) && !isset($excl_arr[$email])) { |
667 | $arr[$email] = $addr->personal; |
668 | } |
669 | } |
670 | } |
671 | } |
672 | return $arr; |
673 | } |
d0719411 |
674 | |
675 | function findAddress($address, $recurs = false) { |
340d67c2 |
676 | $result = false; |
d0719411 |
677 | if (is_array($address)) { |
340d67c2 |
678 | $i=0; |
d0719411 |
679 | foreach($address as $argument) { |
680 | $match = $this->findAddress($argument, true); |
340d67c2 |
681 | $last = end($match); |
682 | if ($match[1]) { |
683 | return $i; |
684 | } else { |
685 | if (count($match[0]) && !$result) { |
686 | $result = $i; |
687 | } |
688 | } |
689 | ++$i; |
690 | } |
691 | } else { |
692 | if (!is_array($this->cc)) $this->cc = array(); |
693 | $srch_addr = $this->parseAddress($address); |
694 | $results = array(); |
695 | foreach ($this->to as $to) { |
696 | if ($to->host == $srch_addr->host) { |
697 | if ($to->mailbox == $srch_addr->mailbox) { |
698 | $results[] = $srch_addr; |
699 | if ($to->personal == $srch_addr->personal) { |
700 | if ($recurs) { |
701 | return array($results, true); |
702 | } else { |
703 | return true; |
704 | } |
705 | } |
706 | } |
707 | } |
d0719411 |
708 | } |
340d67c2 |
709 | foreach ($this->cc as $cc) { |
710 | if ($cc->host == $srch_addr->host) { |
711 | if ($cc->mailbox == $srch_addr->mailbox) { |
712 | $results[] = $srch_addr; |
713 | if ($cc->personal == $srch_addr->personal) { |
714 | if ($recurs) { |
715 | return array($results, true); |
716 | } else { |
717 | return true; |
718 | } |
719 | } |
720 | } |
721 | } |
722 | } |
723 | if ($recurs) { |
724 | return array($results, false); |
725 | } elseif (count($result)) { |
726 | return true; |
727 | } else { |
728 | return false; |
729 | } |
730 | } |
1465f80c |
731 | //exit; |
340d67c2 |
732 | return $result; |
d0719411 |
733 | } |
19d470aa |
734 | |
735 | function getContentType($type0, $type1) { |
736 | $type0 = $this->content_type->type0; |
737 | $type1 = $this->content_type->type1; |
738 | return $this->content_type->properties; |
739 | } |
740 | } |
741 | |
742 | ?> |