bbca93180643ecc49b8f58a69ed3177dd0760ad6
[squirrelmail.git] / class / deliver / Deliver.class.php
1 <?php
2 /**
3 * Deliver.class.php
4 *
5 * Copyright (c) 1999-2005 The SquirrelMail Project Team
6 * Licensed under the GNU GPL. For full terms see the file COPYING.
7 *
8 * This contains all the functions needed to send messages through
9 * a delivery backend.
10 *
11 * @version $Id$
12 * @author Marc Groot Koerkamp
13 * @package squirrelmail
14 */
15
16 /**
17 * Deliver Class - called to actually deliver the message
18 *
19 * This class is called by compose.php and other code that needs
20 * to send messages. All delivery functionality should be centralized
21 * in this class.
22 *
23 * Do not place UI code in this class, as UI code should be placed in templates
24 * going forward.
25 *
26 * @author Marc Groot Koerkamp
27 * @package squirrelmail
28 */
29 class Deliver {
30
31 /**
32 * function mail - send the message parts to the SMTP stream
33 *
34 * @param Message $message Message class to send
35 * @param resource $stream file handle to the SMTP stream
36 *
37 * @return integer $raw_length
38 */
39 function mail($message, $stream=false) {
40 $rfc822_header = $message->rfc822_header;
41 if (count($message->entities)) {
42 $boundary = $this->mimeBoundary();
43 $rfc822_header->content_type->properties['boundary']='"'.$boundary.'"';
44 } else {
45 $boundary='';
46 }
47 $raw_length = 0;
48 $reply_rfc822_header = (isset($message->reply_rfc822_header)
49 ? $message->reply_rfc822_header : '');
50 $header = $this->prepareRFC822_Header($rfc822_header, $reply_rfc822_header, $raw_length);
51
52 if ($stream) {
53 $this->preWriteToStream($header);
54 $this->writeToStream($stream, $header);
55 }
56 $this->writeBody($message, $stream, $raw_length, $boundary);
57 return $raw_length;
58 }
59
60 /**
61 * function writeBody - generate and write the mime boundaries around each part to the stream
62 *
63 * Recursively formats and writes the MIME boundaries of the $message
64 * to the output stream.
65 *
66 * @param Message $message Message object to transform
67 * @param resource $stream SMTP output stream
68 * @param integer &$length_raw raw length of the message (part)
69 * as returned by mail fn
70 * @param string $boundary custom boundary to call, usually for subparts
71 *
72 * @return void
73 */
74 function writeBody($message, $stream, &$length_raw, $boundary='') {
75 // calculate boundary in case of multidimensional mime structures
76 if ($boundary && $message->entity_id && count($message->entities)) {
77 if (strpos($boundary,'_part_')) {
78 $boundary = substr($boundary,0,strpos($boundary,'_part_'));
79 }
80 $boundary_new = $boundary . '_part_'.$message->entity_id;
81 } else {
82 $boundary_new = $boundary;
83 }
84 if ($boundary && !$message->rfc822_header) {
85 $s = '--'.$boundary."\r\n";
86 $s .= $this->prepareMIME_Header($message, $boundary_new);
87 $length_raw += strlen($s);
88 if ($stream) {
89 $this->preWriteToStream($s);
90 $this->writeToStream($stream, $s);
91 }
92 }
93 $this->writeBodyPart($message, $stream, $length_raw);
94
95 $last = false;
96 for ($i=0, $entCount=count($message->entities);$i<$entCount;$i++) {
97 $msg = $this->writeBody($message->entities[$i], $stream, $length_raw, $boundary_new);
98 if ($i == $entCount-1) $last = true;
99 }
100 if ($boundary && $last) {
101 $s = "--".$boundary_new."--\r\n\r\n";
102 $length_raw += strlen($s);
103 if ($stream) {
104 $this->preWriteToStream($s);
105 $this->writeToStream($stream, $s);
106 }
107 }
108 }
109
110 /**
111 * function writeBodyPart - write each individual mimepart
112 *
113 * Recursively called by WriteBody to write each mime part to the SMTP stream
114 *
115 * @param Message $message Message object to transform
116 * @param resource $stream SMTP output stream
117 * @param integer &$length length of the message part
118 * as returned by mail fn
119 *
120 * @return void
121 */
122 function writeBodyPart($message, $stream, &$length) {
123 if ($message->mime_header) {
124 $type0 = $message->mime_header->type0;
125 } else {
126 $type0 = $message->rfc822_header->content_type->type0;
127 }
128
129 $body_part_trailing = $last = '';
130 switch ($type0)
131 {
132 case 'text':
133 case 'message':
134 if ($message->body_part) {
135 $body_part = $message->body_part;
136 // remove NUL characters
137 $body_part = str_replace("\0",'',$body_part);
138 $length += $this->clean_crlf($body_part);
139 if ($stream) {
140 $this->preWriteToStream($body_part);
141 $this->writeToStream($stream, $body_part);
142 }
143 $last = $body_part;
144 } elseif ($message->att_local_name) {
145 $filename = $message->att_local_name;
146 $file = fopen ($filename, 'rb');
147 while ($body_part = fgets($file, 4096)) {
148 $length += $this->clean_crlf($body_part);
149 if ($stream) {
150 $this->preWriteToStream($body_part);
151 $this->writeToStream($stream, $body_part);
152 }
153 $last = $body_part;
154 }
155 fclose($file);
156 }
157 break;
158 default:
159 if ($message->body_part) {
160 $body_part = $message->body_part;
161 $length += $this->clean_crlf($body_part);
162 if ($stream) {
163 $this->writeToStream($stream, $body_part);
164 }
165 } elseif ($message->att_local_name) {
166 $filename = $message->att_local_name;
167 $file = fopen ($filename, 'rb');
168 while ($tmp = fread($file, 570)) {
169 $body_part = chunk_split(base64_encode($tmp));
170 $length += $this->clean_crlf($body_part);
171 if ($stream) {
172 $this->writeToStream($stream, $body_part);
173 }
174 }
175 fclose($file);
176 }
177 break;
178 }
179 $body_part_trailing = '';
180 if ($last && substr($last,-1) != "\n") {
181 $body_part_trailing = "\r\n";
182 }
183 if ($body_part_trailing) {
184 $length += strlen($body_part_trailing);
185 if ($stream) {
186 $this->preWriteToStream($body_part_trailing);
187 $this->writeToStream($stream, $body_part_trailing);
188 }
189 }
190 }
191
192 /**
193 * function clean_crlf - change linefeeds and newlines to legal characters
194 *
195 * The SMTP format only allows CRLF as line terminators.
196 * This function replaces illegal teminators with the correct terminator.
197 *
198 * @param string &$s string to clean linefeeds on
199 *
200 * @return void
201 */
202 function clean_crlf(&$s) {
203 $s = str_replace("\r\n", "\n", $s);
204 $s = str_replace("\r", "\n", $s);
205 $s = str_replace("\n", "\r\n", $s);
206 return strlen($s);
207 }
208
209 /**
210 * function strip_crlf - strip linefeeds and newlines from a string
211 *
212 * The SMTP format only allows CRLF as line terminators.
213 * This function strips all line terminators from the string.
214 *
215 * @param string &$s string to clean linefeeds on
216 *
217 * @return void
218 */
219 function strip_crlf(&$s) {
220 $s = str_replace("\r\n ", '', $s);
221 $s = str_replace("\r", '', $s);
222 $s = str_replace("\n", '', $s);
223 }
224
225 /**
226 * function preWriteToStream - reserved for extended functionality
227 *
228 * This function is not yet implemented.
229 * Reserved for extended functionality.
230 *
231 * @param string &$s string to operate on
232 *
233 * @return void
234 */
235 function preWriteToStream(&$s) {
236 }
237
238 /**
239 * function writeToStream - write data to the SMTP stream
240 *
241 * @param resource $stream SMTP output stream
242 * @param string $data string with data to send to the SMTP stream
243 *
244 * @return void
245 */
246 function writeToStream($stream, $data) {
247 fputs($stream, $data);
248 }
249
250 /**
251 * function initStream - reserved for extended functionality
252 *
253 * This function is not yet implemented.
254 * Reserved for extended functionality.
255 *
256 * @param Message $message Message object
257 * @param string $host host name or IP to connect to
258 * @param string $user username to log into the SMTP server with
259 * @param string $pass password to log into the SMTP server with
260 * @param integer $length
261 *
262 * @return handle $stream file handle resource to SMTP stream
263 */
264 function initStream($message, $length=0, $host='', $port='', $user='', $pass='') {
265 return $stream;
266 }
267
268 /**
269 * function getBCC - reserved for extended functionality
270 *
271 * This function is not yet implemented.
272 * Reserved for extended functionality.
273 *
274 */
275 function getBCC() {
276 return false;
277 }
278
279 /**
280 * function prepareMIME_Header - creates the mime header
281 *
282 * @param Message $message Message object to act on
283 * @param string $boundary mime boundary from fn MimeBoundary
284 *
285 * @return string $header properly formatted mime header
286 */
287 function prepareMIME_Header($message, $boundary) {
288 $mime_header = $message->mime_header;
289 $rn="\r\n";
290 $header = array();
291
292 $contenttype = 'Content-Type: '. $mime_header->type0 .'/'.
293 $mime_header->type1;
294 if (count($message->entities)) {
295 $contenttype .= ";\r\n " . 'boundary="'.$boundary.'"';
296 }
297 if (isset($mime_header->parameters['name'])) {
298 $contenttype .= '; name="'.
299 encodeHeader($mime_header->parameters['name']). '"';
300 }
301 if (isset($mime_header->parameters['charset'])) {
302 $charset = $mime_header->parameters['charset'];
303 $contenttype .= '; charset="'.
304 encodeHeader($charset). '"';
305 }
306
307 $header[] = $contenttype . $rn;
308 if ($mime_header->description) {
309 $header[] = 'Content-Description: ' . $mime_header->description . $rn;
310 }
311 if ($mime_header->encoding) {
312 $header[] = 'Content-Transfer-Encoding: ' . $mime_header->encoding . $rn;
313 } else {
314 if ($mime_header->type0 == 'text' || $mime_header->type0 == 'message') {
315 $header[] = 'Content-Transfer-Encoding: 8bit' . $rn;
316 } else {
317 $header[] = 'Content-Transfer-Encoding: base64' . $rn;
318 }
319 }
320 if ($mime_header->id) {
321 $header[] = 'Content-ID: ' . $mime_header->id . $rn;
322 }
323 if ($mime_header->disposition) {
324 $disposition = $mime_header->disposition;
325 $contentdisp = 'Content-Disposition: ' . $disposition->name;
326 if ($disposition->getProperty('filename')) {
327 $contentdisp .= '; filename="'.
328 encodeHeader($disposition->getProperty('filename')). '"';
329 }
330 $header[] = $contentdisp . $rn;
331 }
332 if ($mime_header->md5) {
333 $header[] = 'Content-MD5: ' . $mime_header->md5 . $rn;
334 }
335 if ($mime_header->language) {
336 $header[] = 'Content-Language: ' . $mime_header->language . $rn;
337 }
338
339 $cnt = count($header);
340 $hdr_s = '';
341 for ($i = 0 ; $i < $cnt ; $i++) {
342 $hdr_s .= $this->foldLine($header[$i], 78,str_pad('',4));
343 }
344 $header = $hdr_s;
345 $header .= $rn; /* One blank line to separate mimeheader and body-entity */
346 return $header;
347 }
348
349 /**
350 * function prepareRFC822_Header - prepares the RFC822 header string from Rfc822Header object(s)
351 *
352 * This function takes the Rfc822Header object(s) and formats them
353 * into the RFC822Header string to send to the SMTP server as part
354 * of the SMTP message.
355 *
356 * @param Rfc822Header $rfc822_header
357 * @param Rfc822Header $reply_rfc822_header
358 * @param integer &$raw_length length of the message
359 *
360 * @return string $header
361 */
362 function prepareRFC822_Header($rfc822_header, $reply_rfc822_header, &$raw_length) {
363 global $domain, $version, $username, $skip_SM_header;
364
365 /* if server var SERVER_NAME not available, use $domain */
366 if(!sqGetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER)) {
367 $SERVER_NAME = $domain;
368 }
369
370 sqGetGlobalVar('REMOTE_ADDR', $REMOTE_ADDR, SQ_SERVER);
371 sqGetGlobalVar('REMOTE_PORT', $REMOTE_PORT, SQ_SERVER);
372 sqGetGlobalVar('REMOTE_HOST', $REMOTE_HOST, SQ_SERVER);
373 sqGetGlobalVar('HTTP_VIA', $HTTP_VIA, SQ_SERVER);
374 sqGetGlobalVar('HTTP_X_FORWARDED_FOR', $HTTP_X_FORWARDED_FOR, SQ_SERVER);
375
376 $rn = "\r\n";
377
378 /* This creates an RFC 822 date */
379 $date = date('D, j M Y H:i:s ', mktime()) . $this->timezone();
380 /* Create a message-id */
381 $message_id = '<' . $REMOTE_PORT . '.' . $REMOTE_ADDR . '.';
382 $message_id .= time() . '.squirrel@' . $SERVER_NAME .'>';
383 /* Make an RFC822 Received: line */
384 if (isset($REMOTE_HOST)) {
385 $received_from = "$REMOTE_HOST ([$REMOTE_ADDR])";
386 } else {
387 $received_from = $REMOTE_ADDR;
388 }
389 if (isset($HTTP_VIA) || isset ($HTTP_X_FORWARDED_FOR)) {
390 if (!isset($HTTP_X_FORWARDED_FOR) || $HTTP_X_FORWARDED_FOR == '') {
391 $HTTP_X_FORWARDED_FOR = 'unknown';
392 }
393 $received_from .= " (proxying for $HTTP_X_FORWARDED_FOR)";
394 }
395 $header = array();
396 if ( !isset($skip_SM_header) || !$skip_SM_header )
397 {
398 $header[] = "Received: from $received_from" . $rn;
399 $header[] = " (SquirrelMail authenticated user $username)" . $rn;
400 $header[] = " by $SERVER_NAME with HTTP;" . $rn;
401 $header[] = " $date" . $rn;
402 }
403 /* Insert the rest of the header fields */
404 $header[] = 'Message-ID: '. $message_id . $rn;
405 if ($reply_rfc822_header->message_id) {
406 $rep_message_id = $reply_rfc822_header->message_id;
407 // $this->strip_crlf($message_id);
408 $header[] = 'In-Reply-To: '.$rep_message_id . $rn;
409 $references = $this->calculate_references($reply_rfc822_header);
410 $header[] = 'References: '.$references . $rn;
411 }
412 $header[] = "Date: $date" . $rn;
413 $header[] = 'Subject: '.encodeHeader($rfc822_header->subject) . $rn;
414 $header[] = 'From: '. $rfc822_header->getAddr_s('from',",$rn ",true) . $rn;
415
416 // folding address list [From|To|Cc|Bcc] happens by using ",$rn<space>" as delimiter
417 // Do not use foldLine for that.
418
419 // RFC2822 if from contains more then 1 address
420 if (count($rfc822_header->from) > 1) {
421 $header[] = 'Sender: '. $rfc822_header->getAddr_s('sender',',',true) . $rn;
422 }
423 if (count($rfc822_header->to)) {
424 $header[] = 'To: '. $rfc822_header->getAddr_s('to',",$rn ",true) . $rn;
425 }
426 if (count($rfc822_header->cc)) {
427 $header[] = 'Cc: '. $rfc822_header->getAddr_s('cc',",$rn ",true) . $rn;
428 }
429 if (count($rfc822_header->reply_to)) {
430 $header[] = 'Reply-To: '. $rfc822_header->getAddr_s('reply_to',',',true) . $rn;
431 }
432 /* Sendmail should return true. Default = false */
433 $bcc = $this->getBcc();
434 if (count($rfc822_header->bcc)) {
435 $s = 'Bcc: '. $rfc822_header->getAddr_s('bcc',",$rn ",true) . $rn;
436 if (!$bcc) {
437 $raw_length += strlen($s);
438 } else {
439 $header[] = $s;
440 }
441 }
442 /* Identify SquirrelMail */
443 $header[] = 'User-Agent: SquirrelMail/' . $version . $rn;
444 /* Do the MIME-stuff */
445 $header[] = 'MIME-Version: 1.0' . $rn;
446 $contenttype = 'Content-Type: '. $rfc822_header->content_type->type0 .'/'.
447 $rfc822_header->content_type->type1;
448 if (count($rfc822_header->content_type->properties)) {
449 foreach ($rfc822_header->content_type->properties as $k => $v) {
450 if ($k && $v) {
451 $contenttype .= ';' .$k.'='.$v;
452 }
453 }
454 }
455 $header[] = $contenttype . $rn;
456 if ($encoding = $rfc822_header->encoding) {
457 $header[] = 'Content-Transfer-Encoding: ' . $encoding . $rn;
458 }
459 if ($rfc822_header->dnt) {
460 $dnt = $rfc822_header->getAddr_s('dnt');
461 /* Pegasus Mail */
462 $header[] = 'X-Confirm-Reading-To: '.$dnt. $rn;
463 /* RFC 2298 */
464 $header[] = 'Disposition-Notification-To: '.$dnt. $rn;
465 }
466 if ($rfc822_header->priority) {
467 switch($rfc822_header->priority)
468 {
469 case 1:
470 $header[] = 'X-Priority: 1 (Highest)'.$rn;
471 $header[] = 'Importance: High'. $rn; break;
472 case 5:
473 $header[] = 'X-Priority: 5 (Lowest)'.$rn;
474 $header[] = 'Importance: Low'. $rn; break;
475 default: break;
476 }
477 }
478 /* Insert headers from the $more_headers array */
479 if(count($rfc822_header->more_headers)) {
480 reset($rfc822_header->more_headers);
481 foreach ($rfc822_header->more_headers as $k => $v) {
482 $header[] = $k.': '.$v .$rn;
483 }
484 }
485 $cnt = count($header);
486 $hdr_s = '';
487
488 for ($i = 0 ; $i < $cnt ; $i++) {
489 $sKey = substr($header[$i],0,strpos($header[$i],':'));
490 switch ($sKey)
491 {
492 case 'Message-ID':
493 case 'In-Reply_To':
494 $hdr_s .= $header[$i];
495 break;
496 case 'References':
497 $sRefs = substr($header[$i],12);
498 $aRefs = explode(' ',$sRefs);
499 $sLine = 'References:';
500 foreach ($aRefs as $sReference) {
501 if (strlen($sLine)+strlen($sReference) >76) {
502 $hdr_s .= $sLine;
503 $sLine = $rn . ' ' . $sReference;
504 } else {
505 $sLine .= ' '. $sReference;
506 }
507 }
508 $hdr_s .= $sLine;
509 break;
510 case 'To':
511 case 'Cc':
512 case 'Bcc':
513 case 'From':
514 $hdr_s .= $header[$i];
515 break;
516 default: $hdr_s .= $this->foldLine($header[$i], 78, str_pad('',4)); break;
517 }
518 }
519 $header = $hdr_s;
520 $header .= $rn; /* One blank line to separate header and body */
521 $raw_length += strlen($header);
522 return $header;
523 }
524
525 /**
526 * function foldLine - for cleanly folding of headerlines
527 *
528 * @param string $line
529 * @param integer $length length to fold the line at
530 * @param string $pre prefix the line with...
531 *
532 * @return string $line folded line with trailing CRLF
533 */
534 function foldLine($line, $length, $pre='') {
535 $line = substr($line,0, -2);
536 $length -= 2; /* do not fold between \r and \n */
537 $cnt = strlen($line);
538 if ($cnt > $length) { /* try folding */
539 $fold_string = "\r\n " . $pre;
540 $bFirstFold = false;
541 $aFoldLine = array();
542 while (strlen($line) > $length) {
543 $fold = false;
544 /* handle encoded parts */
545 if (preg_match('/(=\?([^?]*)\?(Q|B)\?([^?]*)\?=)(\s+|.*)/Ui',$line,$regs)) {
546 $fold_tmp = $regs[1];
547 if (!trim($regs[5])) {
548 $fold_tmp .= $regs[5];
549 }
550 $iPosEnc = strpos($line,$fold_tmp);
551 $iLengthEnc = strlen($fold_tmp);
552 $iPosEncEnd = $iPosEnc+$iLengthEnc;
553 if ($iPosEnc < $length && (($iPosEncEnd) > $length)) {
554 $fold = true;
555 /* fold just before the start of the encoded string */
556 if ($iPosEnc) {
557 $aFoldLine[] = substr($line,0,$iPosEnc);
558 }
559 $line = substr($line,$iPosEnc);
560 if (!$bFirstFold) {
561 $bFirstFold = true;
562 $length -= strlen($fold_string);
563 }
564 if ($iLengthEnc > $length) { /* place the encoded
565 string on a separate line and do not fold inside it*/
566 /* minimize foldstring */
567 $fold_string = "\r\n ";
568 $aFoldLine[] = substr($line,0,$iLengthEnc);
569 $line = substr($line,$iLengthEnc);
570 }
571 } else if ($iPosEnc < $length) { /* the encoded string fits into the foldlength */
572 /*remainder */
573 $sLineRem = substr($line,$iPosEncEnd,$length - $iPosEncEnd);
574 if (preg_match('/^(=\?([^?]*)\?(Q|B)\?([^?]*)\?=)(.*)/Ui',$sLineRem) || !preg_match('/[=,;\s]/',$sLineRem)) {
575 /*impossible to fold clean in the next part -> fold after the enc string */
576 $aFoldLine[] = substr($line,0,$iPosEncEnd);
577 $line = substr($line,$iPosEncEnd);
578 $fold = true;
579 if (!$bFirstFold) {
580 $bFirstFold = true;
581 $length -= strlen($fold_string);
582 }
583 }
584 }
585 }
586 if (!$fold) {
587 $line_tmp = substr($line,0,$length);
588 $iFoldPos = false;
589 /* try to fold at logical places */
590 switch (true)
591 {
592 case ($iFoldPos = strrpos($line_tmp,',')): break;
593 case ($iFoldPos = strrpos($line_tmp,';')): break;
594 case ($iFoldPos = strrpos($line_tmp,' ')): break;
595 case ($iFoldPos = strrpos($line_tmp,'=')): break;
596 default: break;
597 }
598
599 if (!$iFoldPos) { /* clean folding didn't work */
600 $iFoldPos = $length;
601 }
602 $aFoldLine[] = substr($line,0,$iFoldPos+1);
603 $line = substr($line,$iFoldPos+1);
604 if (!$bFirstFold) {
605 $bFirstFold = true;
606 $length -= strlen($fold_string);
607 }
608 }
609 }
610 /*$reconstruct the line */
611 if ($line) {
612 $aFoldLine[] = $line;
613 }
614 $line = implode($fold_string,$aFoldLine);
615 }
616 return $line."\r\n";
617 }
618
619 /**
620 * function mimeBoundary - calculates the mime boundary to use
621 *
622 * This function will generate a random mime boundary base part
623 * for the message if the boundary has not already been set.
624 *
625 * @return string $mimeBoundaryString random mime boundary string
626 */
627 function mimeBoundary () {
628 static $mimeBoundaryString;
629
630 if ( !isset( $mimeBoundaryString ) ||
631 $mimeBoundaryString == '') {
632 $mimeBoundaryString = '----=_' . date( 'YmdHis' ) . '_' .
633 mt_rand( 10000, 99999 );
634 }
635 return $mimeBoundaryString;
636 }
637
638 /**
639 * function timezone - Time offset for correct timezone
640 *
641 * @return string $result with timezone and offset
642 */
643 function timezone () {
644 global $invert_time;
645
646 $diff_second = date('Z');
647 if ($invert_time) {
648 $diff_second = - $diff_second;
649 }
650 if ($diff_second > 0) {
651 $sign = '+';
652 } else {
653 $sign = '-';
654 }
655 $diff_second = abs($diff_second);
656 $diff_hour = floor ($diff_second / 3600);
657 $diff_minute = floor (($diff_second-3600*$diff_hour) / 60);
658 $zonename = '('.strftime('%Z').')';
659 $result = sprintf ("%s%02d%02d %s", $sign, $diff_hour, $diff_minute,
660 $zonename);
661 return ($result);
662 }
663
664 /**
665 * function calculate_references - calculate correct Referer string
666 *
667 * @param Rfc822Header $hdr message header to calculate from
668 *
669 * @return string $refer concatenated and trimmed Referer string
670 */
671 function calculate_references($hdr) {
672 $refer = $hdr->references;
673 $message_id = $hdr->message_id;
674 $in_reply_to = $hdr->in_reply_to;
675 if (strlen($refer) > 2) {
676 $refer .= ' ' . $message_id;
677 } else {
678 if ($in_reply_to) {
679 $refer .= $in_reply_to . ' ' . $message_id;
680 } else {
681 $refer .= $message_id;
682 }
683 }
684 trim($refer);
685 return $refer;
686 }
687 }
688 ?>