KD2 Framework  Check-in [fd1b58234a]

Overview
Comment:SMTP/Mail: Fix issues with quotes and commas in from
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | 7.3
Files: files | file ages | folders
SHA1: fd1b58234a746b03a473699cd2b045287ae64df8
User & Date: bohwaz on 2022-06-07 18:32:44
Other Links: branch diff | manifest | tags
Context
2022-06-07
18:36
SMTP: Fix array map check-in: 8900cf4923 user: bohwaz tags: 7.3
18:32
SMTP/Mail: Fix issues with quotes and commas in from check-in: fd1b58234a user: bohwaz tags: 7.3
12:53
SMTP: handle quoted quotes correctly in From/To headers check-in: 4260ed5925 user: bohwaz tags: 7.3
Changes

Modified src/lib/KD2/Mail_Message.php from [3514548811] to [aff51bb933].

699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
		// Don't encode spam report here as we want it to be readable in the source
		if ($key == 'X-Spam-Report') {
			return $value;
		}

		if (in_array($key, ['From', 'Cc', 'To', 'Bcc', 'Reply-To']))
		{
			if (!preg_match('/^((?:"?(?P<name>.*?)"?)\s*<(?P<namedEmail>[^>]+)>|(?P<email>.+))$/', $value, $matches))
			{
				return $value;
			}

			if (!empty($matches['name']))
			{
				$matches['name'] = str_replace('"', '', $matches['name']);
				return '"' . $this->_encodeHeaderValue(trim($matches['name'])) . '" <' . $matches['namedEmail'] . '>';
			}

			return $value;
		}

		if (!$this->is_utf8($value)) {







|






<







699
700
701
702
703
704
705
706
707
708
709
710
711
712

713
714
715
716
717
718
719
		// Don't encode spam report here as we want it to be readable in the source
		if ($key == 'X-Spam-Report') {
			return $value;
		}

		if (in_array($key, ['From', 'Cc', 'To', 'Bcc', 'Reply-To']))
		{
			if (!preg_match('/^((?:"?(?P<name>(?:(?!\\").)*?)"?)\s*<(?P<namedEmail>[^>]+)>|(?P<email>.+))$/', $value, $matches))
			{
				return $value;
			}

			if (!empty($matches['name']))
			{

				return '"' . $this->_encodeHeaderValue(trim($matches['name'])) . '" <' . $matches['namedEmail'] . '>';
			}

			return $value;
		}

		if (!$this->is_utf8($value)) {

Modified src/lib/KD2/SMTP.php from [30ceaf342b] to [8441c736c3].

392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
	 * @param  mixed  $headers Additional headers, either as an array of key=>value pairs or a string
	 * @return boolean		   TRUE if success, exception if it fails
	 */
	public function send($r, $subject = null, $message = null, $headers = [])
	{
		if (is_object($r) && $r instanceof Mail_Message) {
			$message = $r->output();
			$to = $r->getTo() + $r->getCc();
			$from = current(self::extractEmailAddresses($r->getHeader('Return-Path') ?: $r->getHeader('From')));
		}
		else {
			$msg = $this->buildMessage($r, $subject, $message, $headers);
			extract($msg);
		}








|







392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
	 * @param  mixed  $headers Additional headers, either as an array of key=>value pairs or a string
	 * @return boolean		   TRUE if success, exception if it fails
	 */
	public function send($r, $subject = null, $message = null, $headers = [])
	{
		if (is_object($r) && $r instanceof Mail_Message) {
			$message = $r->output();
			$to = array_map([self::class, 'extractEmailAddresses'], implode(', ', $r->getTo() + $r->getCc()));
			$from = current(self::extractEmailAddresses($r->getHeader('Return-Path') ?: $r->getHeader('From')));
		}
		else {
			$msg = $this->buildMessage($r, $subject, $message, $headers);
			extract($msg);
		}