Révision 01dfd3b5
Ajouté par Assos Assos il y a plus de 3 ans
drupal7/includes/mail.inc | ||
---|---|---|
12 | 12 |
*/ |
13 | 13 |
define('MAIL_LINE_ENDINGS', isset($_SERVER['WINDIR']) || (isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Win32') !== FALSE) ? "\r\n" : "\n"); |
14 | 14 |
|
15 |
|
|
16 |
/** |
|
17 |
* Special characters, defined in RFC_2822. |
|
18 |
*/ |
|
19 |
define('MAIL_RFC_2822_SPECIALS', '()<>[]:;@\,."'); |
|
20 |
|
|
15 | 21 |
/** |
16 | 22 |
* Composes and optionally sends an e-mail message. |
17 | 23 |
* |
... | ... | |
148 | 154 |
// Return-Path headers should have a domain authorized to use the originating |
149 | 155 |
// SMTP server. |
150 | 156 |
$headers['From'] = $headers['Sender'] = $headers['Return-Path'] = $default_from; |
157 |
|
|
158 |
if (variable_get('mail_display_name_site_name', FALSE)) { |
|
159 |
$display_name = variable_get('site_name', 'Drupal'); |
|
160 |
$headers['From'] = drupal_mail_format_display_name($display_name) . ' <' . $default_from . '>'; |
|
161 |
} |
|
151 | 162 |
} |
152 |
if ($from) { |
|
163 |
if ($from && $from != $default_from) {
|
|
153 | 164 |
$headers['From'] = $from; |
154 | 165 |
} |
155 | 166 |
$message['headers'] = $headers; |
... | ... | |
557 | 568 |
return $output . $footnotes; |
558 | 569 |
} |
559 | 570 |
|
571 |
/** |
|
572 |
* Return a RFC-2822 compliant "display-name" component. |
|
573 |
* |
|
574 |
* The "display-name" component is used in mail header "Originator" fields |
|
575 |
* (From, Sender, Reply-to) to give a human-friendly description of the |
|
576 |
* address, i.e. From: My Display Name <xyz@example.org>. RFC-822 and |
|
577 |
* RFC-2822 define its syntax and rules. This method gets as input a string |
|
578 |
* to be used as "display-name" and formats it to be RFC compliant. |
|
579 |
* |
|
580 |
* @param string $string |
|
581 |
* A string to be used as "display-name". |
|
582 |
* |
|
583 |
* @return string |
|
584 |
* A RFC compliant version of the string, ready to be used as |
|
585 |
* "display-name" in mail originator header fields. |
|
586 |
*/ |
|
587 |
function drupal_mail_format_display_name($string) { |
|
588 |
// Make sure we don't process html-encoded characters. They may create |
|
589 |
// unneeded trouble if left encoded, besides they will be correctly |
|
590 |
// processed if decoded. |
|
591 |
$string = decode_entities($string); |
|
592 |
|
|
593 |
// If string contains non-ASCII characters it must be (short) encoded |
|
594 |
// according to RFC-2047. The output of a "B" (Base64) encoded-word is |
|
595 |
// always safe to be used as display-name. |
|
596 |
$safe_display_name = mime_header_encode($string, TRUE); |
|
597 |
|
|
598 |
// Encoded-words are always safe to be used as display-name because don't |
|
599 |
// contain any RFC 2822 "specials" characters. However |
|
600 |
// mimeHeaderEncode() encodes a string only if it contains any |
|
601 |
// non-ASCII characters, and leaves its value untouched (un-encoded) if |
|
602 |
// ASCII only. For this reason in order to produce a valid display-name we |
|
603 |
// still need to make sure there are no "specials" characters left. |
|
604 |
if (preg_match('/[' . preg_quote(MAIL_RFC_2822_SPECIALS) . ']/', $safe_display_name)) { |
|
605 |
|
|
606 |
// If string is already quoted, it may or may not be escaped properly, so |
|
607 |
// don't trust it and reset. |
|
608 |
if (preg_match('/^"(.+)"$/', $safe_display_name, $matches)) { |
|
609 |
$safe_display_name = str_replace(array('\\\\', '\\"'), array('\\', '"'), $matches[1]); |
|
610 |
} |
|
611 |
|
|
612 |
// Transform the string in a RFC-2822 "quoted-string" by wrapping it in |
|
613 |
// double-quotes. Also make sure '"' and '\' occurrences are escaped. |
|
614 |
$safe_display_name = '"' . str_replace(array('\\', '"'), array('\\\\', '\\"'), $safe_display_name) . '"'; |
|
615 |
} |
|
616 |
|
|
617 |
return $safe_display_name; |
|
618 |
} |
|
619 |
|
|
560 | 620 |
/** |
561 | 621 |
* Wraps words on a single line. |
562 | 622 |
* |
563 |
* Callback for array_walk() winthin drupal_wrap_mail().
|
|
623 |
* Callback for array_walk() within drupal_wrap_mail(). |
|
564 | 624 |
*/ |
565 | 625 |
function _drupal_wrap_mail_line(&$line, $key, $values) { |
566 | 626 |
// Use soft-breaks only for purely quoted or unindented text. |
Formats disponibles : Unified diff
Udpate to 7.77