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