4960ec8e |
1 | <?php |
2 | |
69298c28 |
3 | /** |
4 | * Deliver.class.php |
5 | * |
76911253 |
6 | * Copyright (c) 1999-2003 The SquirrelMail Project Team |
69298c28 |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
9 | * This contains all the functions needed to send messages through |
10 | * a delivery backend. |
11 | * |
12 | * $Id$ |
13 | */ |
14 | |
4960ec8e |
15 | class Deliver { |
16 | |
59387d1c |
17 | function mail($message, $stream=false) { |
3b53d87f |
18 | $rfc822_header = $message->rfc822_header; |
19 | if (count($message->entities)) { |
59387d1c |
20 | $boundary = $this->mimeBoundary(); |
1274f430 |
21 | $rfc822_header->content_type->properties['boundary']='"'.$boundary.'"'; |
3b53d87f |
22 | } else { |
23 | $boundary=''; |
24 | } |
75b14a70 |
25 | $raw_length = 0; |
1274f430 |
26 | $reply_rfc822_header = (isset($message->reply_rfc822_header) |
27 | ? $message->reply_rfc822_header : ''); |
75b14a70 |
28 | $header = $this->prepareRFC822_Header($rfc822_header, $reply_rfc822_header, $raw_length); |
29 | |
3b53d87f |
30 | if ($stream) { |
59387d1c |
31 | $this->preWriteToStream($header); |
32 | $this->writeToStream($stream, $header); |
3b53d87f |
33 | } |
59387d1c |
34 | $this->writeBody($message, $stream, $raw_length, $boundary); |
3b53d87f |
35 | return $raw_length; |
36 | } |
37 | |
38 | function writeBody($message, $stream, &$length_raw, $boundary='') { |
1274f430 |
39 | if ($boundary && !$message->rfc822_header) { |
3b53d87f |
40 | $s = '--'.$boundary."\r\n"; |
41 | $s .= $this->prepareMIME_Header($message, $boundary); |
42 | $length_raw += strlen($s); |
43 | if ($stream) { |
44 | $this->preWriteToStream($s); |
45 | $this->writeToStream($stream, $s); |
46 | } |
47 | } |
59387d1c |
48 | $this->writeBodyPart($message, $stream, $length_raw); |
3b53d87f |
49 | $boundary_depth = substr_count($message->entity_id,'.'); |
50 | if ($boundary_depth) { |
51 | $boundary .= '_part'.$boundary_depth; |
52 | } |
1274f430 |
53 | $last = false; |
3b53d87f |
54 | for ($i=0, $entCount=count($message->entities);$i<$entCount;$i++) { |
59387d1c |
55 | $msg = $this->writeBody($message->entities[$i], $stream, $length_raw, $boundary); |
1274f430 |
56 | if ($i == $entCount-1) $last = true; |
3b53d87f |
57 | } |
1274f430 |
58 | if ($boundary && $last) { |
252737e1 |
59 | $s = "--".$boundary."--\r\n\r\n"; |
3b53d87f |
60 | $length_raw += strlen($s); |
61 | if ($stream) { |
62 | $this->preWriteToStream($s); |
63 | $this->writeToStream($stream, $s); |
64 | } |
65 | } |
66 | } |
67 | |
68 | function writeBodyPart($message, $stream, &$length) { |
1274f430 |
69 | if ($message->mime_header) { |
70 | $type0 = $message->mime_header->type0; |
71 | } else { |
72 | $type0 = $message->rfc822_header->content_type->type0; |
73 | } |
252737e1 |
74 | |
75 | $body_part_trailing = $last = ''; |
1274f430 |
76 | switch ($type0) { |
3b53d87f |
77 | case 'text': |
78 | case 'message': |
79 | if ($message->body_part) { |
80 | $body_part = $message->body_part; |
81 | $length += $this->clean_crlf($body_part); |
82 | if ($stream) { |
83 | $this->preWriteToStream($body_part); |
59387d1c |
84 | $this->writeToStream($stream, $body_part); |
3b53d87f |
85 | } |
252737e1 |
86 | $last = $body_part; |
3b53d87f |
87 | } elseif ($message->att_local_name) { |
88 | $filename = $message->att_local_name; |
89 | $file = fopen ($filename, 'rb'); |
252737e1 |
90 | while ($body_part = fgets($file, 4096)) { |
91 | $length += $this->clean_crlf($body_part); |
3b53d87f |
92 | if ($stream) { |
252737e1 |
93 | $this->preWriteToStream($body_part); |
94 | $this->writeToStream($stream, $body_part); |
59387d1c |
95 | } |
252737e1 |
96 | $last = $body_part; |
3b53d87f |
97 | } |
98 | fclose($file); |
99 | } |
100 | break; |
101 | default: |
102 | if ($message->body_part) { |
103 | $body_part = $message->body_part; |
104 | $length += $this->clean_crlf($body_part); |
105 | if ($stream) { |
59387d1c |
106 | $this->writeToStream($stream, $body_part); |
59387d1c |
107 | } |
3b53d87f |
108 | } elseif ($message->att_local_name) { |
109 | $filename = $message->att_local_name; |
110 | $file = fopen ($filename, 'rb'); |
252737e1 |
111 | $encoded = ''; |
1274f430 |
112 | while ($tmp = fread($file, 570)) { |
252737e1 |
113 | $body_part = chunk_split(base64_encode($tmp)); |
114 | $length += $this->clean_crlf($body_part); |
3b53d87f |
115 | if ($stream) { |
252737e1 |
116 | $this->writeToStream($stream, $body_part); |
3b53d87f |
117 | } |
118 | } |
119 | fclose($file); |
120 | } |
121 | break; |
122 | } |
252737e1 |
123 | $body_part_trailing = ''; |
124 | if ($last && substr($last,-1) != "\n") { |
125 | $body_part_trailing = "\r\n"; |
126 | } |
127 | if ($body_part_trailing) { |
128 | $length += strlen($body_part_trailing); |
129 | if ($stream) { |
130 | $this->preWriteToStream($body_part_trailing); |
131 | $this->writeToStream($stream, $body_part_trailing); |
132 | } |
1274f430 |
133 | } |
3b53d87f |
134 | } |
135 | |
69298c28 |
136 | function clean_crlf(&$s) { |
3b53d87f |
137 | $s = str_replace("\r\n", "\n", $s); |
138 | $s = str_replace("\r", "\n", $s); |
139 | $s = str_replace("\n", "\r\n", $s); |
140 | return strlen($s); |
141 | } |
e4f9307a |
142 | |
143 | function strip_crlf(&$s) { |
144 | $s = str_replace("\r\n ", '', $s); |
145 | $s = str_replace("\r", '', $s); |
146 | $s = str_replace("\n", '', $s); |
147 | } |
3b53d87f |
148 | |
69298c28 |
149 | function preWriteToStream(&$s) { |
3b53d87f |
150 | } |
151 | |
152 | function writeToStream($stream, $data) { |
1274f430 |
153 | fputs($stream, $data); |
3b53d87f |
154 | } |
155 | |
156 | function initStream($message, $length=0, $host='', $port='', $user='', $pass='') { |
157 | return $stream; |
158 | } |
59387d1c |
159 | |
0dab3bfb |
160 | function getBcc() { |
59387d1c |
161 | return false; |
162 | } |
3b53d87f |
163 | |
164 | function prepareMIME_Header($message, $boundary) { |
59387d1c |
165 | $mime_header = $message->mime_header; |
166 | $rn="\r\n"; |
4960ec8e |
167 | $header = array(); |
3b53d87f |
168 | |
59387d1c |
169 | $contenttype = 'Content-Type: '. $mime_header->type0 .'/'. |
170 | $mime_header->type1; |
3b53d87f |
171 | if (count($message->entities)) { |
172 | $contenttype .= ";\r\n " . 'boundary="'.$boundary.'"'; |
173 | } |
4960ec8e |
174 | if (isset($mime_header->parameters['name'])) { |
1274f430 |
175 | $contenttype .= '; name="'. |
4960ec8e |
176 | encodeHeader($mime_header->parameters['name']). '"'; |
177 | } |
1274f430 |
178 | if (isset($mime_header->parameters['charset'])) { |
179 | $charset = $mime_header->parameters['charset']; |
180 | $contenttype .= '; charset="'. |
181 | encodeHeader($charset). '"'; |
182 | } |
183 | |
184 | |
4960ec8e |
185 | $header[] = $contenttype . $rn; |
186 | if ($mime_header->description) { |
187 | $header[] .= 'Content-Description: ' . $mime_header->description . $rn; |
188 | } |
189 | if ($mime_header->encoding) { |
1274f430 |
190 | $encoding = $mime_header->encoding; |
4960ec8e |
191 | $header[] .= 'Content-Transfer-Encoding: ' . $mime_header->encoding . $rn; |
1274f430 |
192 | } else { |
193 | if ($mime_header->type0 == 'text' || $mime_header->type0 == 'message') { |
194 | $header[] .= 'Content-Transfer-Encoding: 8bit' . $rn; |
195 | } else { |
196 | $header[] .= 'Content-Transfer-Encoding: base64' . $rn; |
197 | } |
4960ec8e |
198 | } |
199 | if ($mime_header->id) { |
200 | $header[] .= 'Content-ID: ' . $mime_header->id . $rn; |
201 | } |
202 | if ($mime_header->disposition) { |
1274f430 |
203 | $disposition = $mime_header->disposition; |
204 | $contentdisp = 'Content-Disposition: ' . $disposition->name; |
205 | if ($disposition->getProperty('filename')) { |
206 | $contentdisp .= '; filename="'. |
207 | encodeHeader($disposition->getProperty('filename')). '"'; |
4960ec8e |
208 | } |
209 | $header[] = $contentdisp . $rn; |
210 | } |
211 | if ($mime_header->md5) { |
212 | $header[] .= 'Content-MD5: ' . $mime_header->md5 . $rn; |
213 | } |
214 | if ($mime_header->language) { |
215 | $header[] .= 'Content-Language: ' . $mime_header->language . $rn; |
216 | } |
217 | |
218 | $cnt = count($header); |
219 | $hdr_s = ''; |
220 | for ($i = 0 ; $i < $cnt ; $i++) { |
75b14a70 |
221 | $hdr_s .= $this->foldLine($header[$i], 78,str_pad('',4)); |
4960ec8e |
222 | } |
223 | $header = $hdr_s; |
3b53d87f |
224 | $header .= $rn; /* One blank line to separate mimeheader and body-entity */ |
225 | return $header; |
4960ec8e |
226 | } |
227 | |
75b14a70 |
228 | function prepareRFC822_Header($rfc822_header, $reply_rfc822_header, &$raw_length) { |
60a46e65 |
229 | global $domain, $version, $username; |
230 | |
231 | /* if server var SERVER_NAME not available, use $domain */ |
232 | if(!sqGetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER)) { |
233 | $SERVER_NAME = $domain; |
234 | } |
235 | |
236 | sqGetGlobalVar('REMOTE_ADDR', $REMOTE_ADDR, SQ_SERVER); |
237 | sqGetGlobalVar('REMOTE_PORT', $REMOTE_PORT, SQ_SERVER); |
238 | sqGetGlobalVar('REMOTE_HOST', $REMOTE_HOST, SQ_SERVER); |
239 | sqGetGlobalVar('HTTP_VIA', $HTTP_VIA, SQ_SERVER); |
240 | sqGetGlobalVar('HTTP_X_FORWARDED_FOR', $HTTP_X_FORWARDED_FOR, SQ_SERVER); |
241 | |
59387d1c |
242 | $rn = "\r\n"; |
223872cb |
243 | |
4960ec8e |
244 | /* This creates an RFC 822 date */ |
47f06eb3 |
245 | $date = date('D, j M Y H:i:s ', mktime()) . $this->timezone(); |
4960ec8e |
246 | /* Create a message-id */ |
247 | $message_id = '<' . $REMOTE_PORT . '.' . $REMOTE_ADDR . '.'; |
248 | $message_id .= time() . '.squirrel@' . $SERVER_NAME .'>'; |
249 | /* Make an RFC822 Received: line */ |
59387d1c |
250 | if (isset($REMOTE_HOST)) { |
251 | $received_from = "$REMOTE_HOST ([$REMOTE_ADDR])"; |
252 | } else { |
253 | $received_from = $REMOTE_ADDR; |
254 | } |
255 | if (isset($HTTP_VIA) || isset ($HTTP_X_FORWARDED_FOR)) { |
47f06eb3 |
256 | if (!isset($HTTP_X_FORWARDED_FOR) || $HTTP_X_FORWARDED_FOR == '') { |
59387d1c |
257 | $HTTP_X_FORWARDED_FOR = 'unknown'; |
258 | } |
259 | $received_from .= " (proxying for $HTTP_X_FORWARDED_FOR)"; |
260 | } |
261 | $header = array(); |
262 | $header[] = "Received: from $received_from" . $rn; |
263 | $header[] = " (SquirrelMail authenticated user $username)" . $rn; |
264 | $header[] = " by $SERVER_NAME with HTTP;" . $rn; |
265 | $header[] = " $date" . $rn; |
266 | /* Insert the rest of the header fields */ |
267 | $header[] = 'Message-ID: '. $message_id . $rn; |
1274f430 |
268 | if ($reply_rfc822_header->message_id) { |
e4f9307a |
269 | $rep_message_id = $reply_rfc822_header->message_id; |
270 | // $this->strip_crlf($message_id); |
271 | $header[] = 'In-Reply-To: '.$rep_message_id . $rn; |
1274f430 |
272 | $references = $this->calculate_references($reply_rfc822_header); |
59387d1c |
273 | $header[] = 'References: '.$references . $rn; |
274 | } |
275 | $header[] = "Date: $date" . $rn; |
276 | $header[] = 'Subject: '.encodeHeader($rfc822_header->subject) . $rn; |
a1386fbf |
277 | $header[] = 'From: '. $rfc822_header->getAddr_s('from',',',true) . $rn; |
59387d1c |
278 | /* RFC2822 if from contains more then 1 address */ |
279 | if (count($rfc822_header->from) > 1) { |
a1386fbf |
280 | $header[] = 'Sender: '. $rfc822_header->getAddr_s('sender',',',true) . $rn; |
59387d1c |
281 | } |
75b14a70 |
282 | if (count($rfc822_header->to)) { |
a1386fbf |
283 | $header[] = 'To: '. $rfc822_header->getAddr_s('to',',',true) . $rn; |
75b14a70 |
284 | } |
59387d1c |
285 | if (count($rfc822_header->cc)) { |
a1386fbf |
286 | $header[] = 'Cc: '. $rfc822_header->getAddr_s('cc',',',true) . $rn; |
59387d1c |
287 | } |
288 | if (count($rfc822_header->reply_to)) { |
a1386fbf |
289 | $header[] = 'Reply-To: '. $rfc822_header->getAddr_s('reply_to',',',true) . $rn; |
59387d1c |
290 | } |
291 | /* Sendmail should return true. Default = false */ |
1274f430 |
292 | $bcc = $this->getBcc(); |
75b14a70 |
293 | if (count($rfc822_header->bcc)) { |
a1386fbf |
294 | $s = 'Bcc: '. $rfc822_header->getAddr_s('bcc',',',true) . $rn; |
75b14a70 |
295 | if (!$bcc) { |
296 | $s = $this->foldLine($s, 78, str_pad('',4)); |
297 | $raw_length += strlen($s); |
298 | } else { |
299 | $header[] = $s; |
300 | } |
59387d1c |
301 | } |
302 | /* Identify SquirrelMail */ |
3f6add30 |
303 | $header[] = 'User-Agent: SquirrelMail/' . $version . $rn; |
59387d1c |
304 | /* Do the MIME-stuff */ |
3f6add30 |
305 | $header[] = 'MIME-Version: 1.0' . $rn; |
59387d1c |
306 | $contenttype = 'Content-Type: '. $rfc822_header->content_type->type0 .'/'. |
307 | $rfc822_header->content_type->type1; |
308 | if (count($rfc822_header->content_type->properties)) { |
1274f430 |
309 | foreach ($rfc822_header->content_type->properties as $k => $v) { |
310 | if ($k && $v) { |
311 | $contenttype .= ';' .$k.'='.$v; |
312 | } |
59387d1c |
313 | } |
314 | } |
315 | $header[] = $contenttype . $rn; |
bfebbda2 |
316 | if ($encoding = $rfc822_header->encoding) { |
317 | $header[] .= 'Content-Transfer-Encoding: ' . $encoding . $rn; |
318 | } |
59387d1c |
319 | if ($rfc822_header->dnt) { |
320 | $dnt = $rfc822_header->getAddr_s('dnt'); |
321 | /* Pegasus Mail */ |
322 | $header[] = 'X-Confirm-Reading-To: '.$dnt. $rn; |
323 | /* RFC 2298 */ |
324 | $header[] = 'Disposition-Notification-To: '.$dnt. $rn; |
325 | } |
326 | if ($rfc822_header->priority) { |
327 | $prio = $rfc822_header->priority; |
328 | $header[] = 'X-Priority: '.$prio. $rn; |
329 | switch($prio) { |
330 | case 1: $header[] = 'Importance: High'. $rn; break; |
331 | case 3: $header[] = 'Importance: Normal'. $rn; break; |
332 | case 5: $header[] = 'Importance: Low'. $rn; break; |
333 | default: break; |
334 | } |
335 | } |
336 | /* Insert headers from the $more_headers array */ |
337 | if(count($rfc822_header->more_headers)) { |
338 | reset($rfc822_header->more_headers); |
339 | foreach ($rfc822_header->more_headers as $k => $v) { |
340 | $header[] = $k.': '.$v .$rn; |
341 | } |
c422e824 |
342 | } |
59387d1c |
343 | $cnt = count($header); |
344 | $hdr_s = ''; |
5d2a7b15 |
345 | |
59387d1c |
346 | for ($i = 0 ; $i < $cnt ; $i++) { |
5d2a7b15 |
347 | $sKey = substr($header[$i],0,strpos($header[$i],':')); |
348 | switch ($sKey) |
349 | { |
350 | case 'Message-ID': |
351 | case 'In-Reply_To': |
352 | $hdr_s .= $header[$i]; |
353 | break; |
354 | case 'References': |
355 | $sRefs = substr($header[$i],12); |
356 | $aRefs = explode(' ',$sRefs); |
357 | $sLine = 'References:'; |
358 | foreach ($aRefs as $sReference) { |
359 | if (strlen($sLine)+strlen($sReference) >76) { |
360 | $hdr_s .= $sLine; |
361 | $sLine = $rn . ' ' . $sReference; |
362 | } else { |
363 | $sLine .= ' '. $sReference; |
364 | } |
365 | } |
366 | $hdr_s .= $sLine; |
367 | break; |
368 | default: $hdr_s .= $this->foldLine($header[$i], 78, str_pad('',4)); break; |
369 | } |
59387d1c |
370 | } |
c422e824 |
371 | |
59387d1c |
372 | $header = $hdr_s; |
373 | $header .= $rn; /* One blank line to separate header and body */ |
75b14a70 |
374 | $raw_length += strlen($header); |
59387d1c |
375 | return $header; |
4960ec8e |
376 | } |
377 | |
378 | /* |
379 | * function for cleanly folding of headerlines |
380 | */ |
1274f430 |
381 | function foldLine($line, $length, $pre='') { |
e4f9307a |
382 | $line = substr($line,0, -2); |
fb1d6cb6 |
383 | $length -= 2; /* do not fold between \r and \n */ |
384 | $cnt = strlen($line); |
385 | if ($cnt > $length) { /* try folding */ |
386 | $fold_string = "\r\n " . $pre; |
387 | $bFirstFold = false; |
388 | $aFoldLine = array(); |
389 | while (strlen($line) > $length) { |
390 | $fold = false; |
391 | /* handle encoded parts */ |
223872cb |
392 | if (preg_match('/(=\?([^?]*)\?(Q|B)\?([^?]*)\?=)(.*)/Ui',$line,$regs)) { |
fb1d6cb6 |
393 | $fold_tmp = $regs[1]; |
394 | $iPosEnc = strpos($line,$fold_tmp); |
395 | $iLengthEnc = strlen($fold_tmp); |
c422e824 |
396 | $iPosEncEnd = $iPosEnc+$iLengthEnc; |
397 | if ($iPosEnc < $length && (($iPosEncEnd) > $length)) { |
fb1d6cb6 |
398 | $fold = true; |
399 | /* fold just before the start of the encoded string */ |
400 | $aFoldLine[] = substr($line,0,$iPosEnc); |
401 | $line = substr($line,$iPosEnc); |
402 | if (!$bFirstFold) { |
403 | $bFirstFold = true; |
404 | $length -= strlen($fold_string); |
405 | } |
406 | if ($iLengthEnc > $length) { /* place the encoded |
407 | string on a separate line and do not fold inside it*/ |
223872cb |
408 | /* minimize foldstring */ |
409 | $fold_string = "\r\n "; |
410 | $aFoldLine[] = substr($line,0,$iLengthEnc); |
411 | $line = substr($line,$iLengthEnc); |
412 | } |
c422e824 |
413 | } else if ($iPosEnc < $length) { /* the encoded string fits into the foldlength */ |
fb1d6cb6 |
414 | /*remainder */ |
fb1d6cb6 |
415 | $sLineRem = substr($line,$iPosEncEnd,$length - $iPosEncEnd); |
c422e824 |
416 | if (preg_match('/^(=\?([^?]*)\?(Q|B)\?([^?]*)\?=)(.*)/Ui',$sLineRem) || !preg_match('/[=,;\s]/',$sLineRem)) { |
fb1d6cb6 |
417 | /*impossible to fold clean in the next part -> fold after the enc string */ |
418 | $aFoldLine[] = substr($line,0,$iPosEncEnd+1); |
419 | $line = substr($line,$iPosEncEnd+1); |
420 | $fold = true; |
421 | if (!$bFirstFold) { |
422 | $bFirstFold = true; |
423 | $length -= strlen($fold_string); |
424 | } |
223872cb |
425 | } |
fb1d6cb6 |
426 | } |
427 | } |
428 | if (!$fold) { |
429 | $line_tmp = substr($line,0,$length); |
430 | $iFoldPos = false; |
431 | /* try to fold at logical places */ |
432 | switch (true) |
433 | { |
434 | case ($iFoldPos = strrpos($line_tmp,',')): break; |
435 | case ($iFoldPos = strrpos($line_tmp,';')): break; |
436 | case ($iFoldPos = strrpos($line_tmp,' ')): break; |
437 | case ($iFoldPos = strrpos($line_tmp,'=')): break; |
438 | default: break; |
439 | } |
440 | |
441 | if (!$iFoldPos) { /* clean folding didn't work */ |
442 | $iFoldPos = $length; |
443 | } |
444 | $aFoldLine[] = substr($line,0,$iFoldPos+1); |
445 | $line = substr($line,$iFoldPos+1); |
446 | if (!$bFirstFold) { |
447 | $bFirstFold = true; |
448 | $length -= strlen($fold_string); |
449 | } |
450 | } |
451 | } |
452 | /*$reconstruct the line */ |
453 | if ($line) { |
454 | $aFoldLine[] = $line; |
455 | } |
456 | $line = implode($fold_string,$aFoldLine); |
457 | } |
223872cb |
458 | |
fb1d6cb6 |
459 | return $line."\r\n"; |
460 | } |
3b53d87f |
461 | |
59387d1c |
462 | function mimeBoundary () { |
463 | static $mimeBoundaryString; |
3b53d87f |
464 | |
59387d1c |
465 | if ( !isset( $mimeBoundaryString ) || |
466 | $mimeBoundaryString == '') { |
467 | $mimeBoundaryString = '----=_' . date( 'YmdHis' ) . '_' . |
468 | mt_rand( 10000, 99999 ); |
469 | } |
470 | return $mimeBoundaryString; |
3b53d87f |
471 | } |
472 | |
59387d1c |
473 | /* Time offset for correct timezone */ |
474 | function timezone () { |
475 | global $invert_time; |
3b53d87f |
476 | |
59387d1c |
477 | $diff_second = date('Z'); |
478 | if ($invert_time) { |
479 | $diff_second = - $diff_second; |
480 | } |
481 | if ($diff_second > 0) { |
482 | $sign = '+'; |
483 | } else { |
484 | $sign = '-'; |
485 | } |
486 | $diff_second = abs($diff_second); |
487 | $diff_hour = floor ($diff_second / 3600); |
488 | $diff_minute = floor (($diff_second-3600*$diff_hour) / 60); |
489 | $zonename = '('.strftime('%Z').')'; |
490 | $result = sprintf ("%s%02d%02d %s", $sign, $diff_hour, $diff_minute, |
3b53d87f |
491 | $zonename); |
59387d1c |
492 | return ($result); |
493 | } |
3b53d87f |
494 | |
1274f430 |
495 | function calculate_references($hdr) { |
496 | $refer = $hdr->references; |
e4f9307a |
497 | $message_id = $hdr->message_id; |
498 | $in_reply_to = $hdr->in_reply_to; |
59387d1c |
499 | if (strlen($refer) > 2) { |
e4f9307a |
500 | $refer .= ' ' . $message_id; |
59387d1c |
501 | } else { |
e4f9307a |
502 | if ($in_reply_to) { |
503 | $refer .= $in_reply_to . ' ' . $message_id; |
59387d1c |
504 | } else { |
e4f9307a |
505 | $refer .= $message_id; |
59387d1c |
506 | } |
507 | } |
508 | trim($refer); |
509 | return $refer; |
510 | } |
511 | } |
4960ec8e |
512 | ?> |