Page MenuHomePhabricator

Windows SMTP server not able to parse E-mail address format
Closed, ResolvedPublic

Description

Author: superoni

Description:
Directly e-mailing a user will not perform properly while using Windows' builtin
SMTP server (Windows 2000 Server, Windows 2003 Server).

Normal notification e-mails work such as change notifications, password reminders.

However, if you try e-mailing directly a user, it fails possibly due to the way
it formats the e-mail address by combining the wiki user name like so:

Here is a sample of a SMTP log when this happens:

2006-02-13 19:44:59 127.0.0.1 W2K-US2 HELO - +W2K-US2 250 31 SMTP
2006-02-13 19:44:59 127.0.0.1 W2K-US2 MAIL - +FROM:<wikiadmin@XXXXXX.com> 250 46
SMTP
2006-02-13 19:44:59 127.0.0.1 W2K-US2 RCPT -
+TO:<David.forester+<david.forester@XXXXXX.com>> 501 27 SMTP
2006-02-13 19:44:59 127.0.0.1 W2K-US2 QUIT - W2K-US2 240 56 SMTP


Version: 1.5.x
Severity: normal
OS: Windows XP
Platform: PC

Details

Reference
bz4979

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 9:05 PM
bzimport set Reference to bz4979.
bzimport added a subscriber: Unknown Object (MLST).

Comment: this is very dependent on the several windows versions.

tom.giesberg wrote:

Per http://us2.php.net/manual/en/function.mail.php, under Windows "the to parameter should
not be an address in the form of "Something <someone@example.com>"". As such, you can address
this by going to UserMailer.php and modify the MailAddress toString() function from:

if( $this->name != '') {
  return wfQuotedPrintable( $this->name ) . " <" . $this->address . ">";
} else {
  return $this->address;
}

to:

if( $this->name != '' && $_ENV['OS']!='Windows_NT') {
[Everything else the same]

This will result in a simple email address that Windows' mail() implementation can handle.

mediawiki_bugzilla wrote:

(In reply to comment #2)
I would suggest adding the "Something <someone@example.com>"-style address to
the $headers variable and then modify the call to the mail()-function like so:

Start in line 118:

		$headers =
			"MIME-Version: 1.0\n" .
			"Content-type: text/plain; charset={$wgOutputEncoding}\n" .
			"Content-Transfer-Encoding: 8bit\n" .
			"X-Mailer: MediaWiki mailer\n".
			'From: ' . $from->toString() . "\n"/* CHANGE START */.
			"To: {$dest}\n"/* CHANGE END */;

And change line 134 to:

		mail( $to->address, wfQuotedPrintable( $subject ), $body, $headers );

This approach would be more portable.

Have you tested that? My recollection is that the broken function on Windows
reads the value from the From: header.

dgilman wrote:

I followed Comment #3 and my system was able to send emails to another Win2k3
SMTP box (our relay system).
HOWEVER:
I now have two new problems (must be my fat fingers):

  1. "Could not send confirmation mail. Check address for invalid characters." -

but the email goes forth!

  1. Any edit of a page results in "Sorry! We could not process your edit due to a

loss of session data. Please try again. If it still doesn't work, try logging
out and logging back in." Which doesn't go away when I logout, restart Apache,
etc. I have a 2nd wiki- it doesn't send email (yet) but it also gives this
second error.

I post this here as they both appeared as a result of fixing the above and wish
for others to properly execute your advice and not mess up as I have.

robchur wrote:

*** Bug 6659 has been marked as a duplicate of this bug. ***

carl.duisberg wrote:

The bug is in UserMailer.php, function userMailer(). In version 1.7.1 there are
two lines setting $dest:

if (is_array( $wgSMTP )) {
...
(1) $dest = $to->address;
} else {
...
(2) $dest = $to->toString();

Line (1) is correct. Line (2) is wrong it causes the problem as is also
described in the code comment:
// Note: The to parameter cannot be an address in the form of "Something
<someone@example.com>".

Please change line (2) to
$dest = $to->address;

carl.duisberg wrote:

Patch for UserMailer.php

attachment patch.txt ignored as obsolete

carl.duisberg wrote:

Unified patch for UserMailer.php

attachment patch.txt ignored as obsolete

carl.duisberg wrote:

Patch vor UserMailer.php (revision 15871): $dest = $to->address;

Sorry for saving the same patch thrice. Had no SVN on my computer.

Attached:

robchur wrote:

Should now be fixed in SVN trunk, r16285.

sselden wrote:

After using the fix in comment #7 I received this error, but email was sent
sucessfully.
Error sending mail: mail() [function.mail]: It is not safe to rely on the
system's timezone settings. Please use the date.timezone setting, the TZ
environment variable or the date_default_timezone_set() function. In case you
used any of those methods and you are still getting this warning, you most
likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for
'-7.0/DST' instead

carl.duisberg wrote:

(In reply to comment #11)

Should now be fixed in SVN trunk, r16285.

Neither in 1.7.1
(http://svn.wikimedia.org/svnroot/mediawiki/branches/REL1_7/phase3/includes/UserMailer.php)
nor in snapshot work
(http://svn.wikimedia.org/svnroot/mediawiki/branches/snapshot-work/includes/UserMailer.php)
the problem is fixed (r16418).

provoost wrote:

I'm not sure if this adds anything new to the discussion, but anyway...
I had the same problem with 'my' windows webserver in combination with
(probably) a windows smtp server. I am running version 1.6.8 (because of php4).
The log from the smtp server reads:

9/08/06 10:41:22 SMTP-OU 52C1ABFFDBE9423DA6A4E6F230F81E91.MAI 452
193.93.174.20 EHLO EHLO WSLEASENOBOR01.noborders.nl
250-wsspam02.livemail.nl 34 96
09/08/06 10:41:22 SMTP-OU 52C1ABFFDBE9423DA6A4E6F230F81E91.MAI 452
193.93.174.20 MAIL MAIL FROM:<info@noborders.nl> SIZE=840 250 Ok 40
8
09/08/06 10:41:22 SMTP-OU 52C1ABFFDBE9423DA6A4E6F230F81E91.MAI 452
193.93.174.20 RCPT RCPT TO:<Zirrio <sirio@noborders.nl> 501 Bad
address syntax 38 24
09/08/06 10:41:22 SMTP-OU 52C1ABFFDBE9423DA6A4E6F230F81E91.MAI 452
193.93.174.20 QUIT QUIT 221 Bye 6 9
09/08/06 10:41:23 SMTP-OU B4DED6E0F5DC4D848A73A3448EA91E9B.MAI 452
193.93.174.20

Apparently, the problem is the address syntax:
<Zirrio <sirio@noborders.nl>
in stead of just
sirio@noborders.nl

http://archives.neohapsis.com/archives/php/2004-08/0007.html describes a similar
problem.

I 'solved' it by changing includes/UserMailer.php around line 57

Replace:

function toString() {

		if( $this->name != '' ) {
			return wfQuotedPrintable( $this->name ) . " <" . $this->address . ">";
		} else {
			return $this->address;
		}

}

by:

function toString() {

			return $this->address;

}

Can this problem also be fixed for 1.6.8 branch?

carl.duisberg wrote:

Fixed in mediawiki
http://svn.wikimedia.org/svnroot/mediawiki/branches/snapshot-work/includes/UserMailer.php,
r16404, by not createing "Joe Bloggs <joe@bloggs.com>" format email addresses in
windows at all (see MailAddress::toString()).