Bug 1294027 - use mail sender's address for SMTP MAIL FROM (updated tests). r=jorgk

This commit is contained in:
rene 2018-01-18 14:20:59 +01:00
Родитель 20e3d50e1a
Коммит fae4e0db76
15 изменённых файлов: 144 добавлений и 57 удалений

Просмотреть файл

@ -1,5 +1,5 @@
From: Invalid User <invalid@foo.invalid>
To: =?UTF-8?B?RnLDqcOpZGxlLCBUZXN0?= <to@foo.invalid>
From: Invalid User <from_A@foo.invalid>
To: =?UTF-8?B?RnLDqcOpZGxlLCBUZXN0?= <to_A@foo.invalid>
Subject: Big email
012345678901234567890123456789012345678901234567890123456789

Просмотреть файл

@ -1,5 +1,5 @@
From: from@foo.invalid
To: to@foo.invalid
From: from_B@foo.invalid
To: to_B@foo.invalid
Subject: test mail
this email is in dos format because that is what the interface requires

Просмотреть файл

@ -24,6 +24,7 @@ function promptPasswordPS(aParent, aDialogTitle, aText, aPassword,
var server;
var kIdentityMail = "identity@foo.invalid";
var kSender = "from@foo.invalid";
var kTo = "to@foo.invalid";
var kUsername = "test.smtp@fakeserver";
@ -64,7 +65,7 @@ add_task(function *() {
// Start the fake SMTP server
server.start();
var smtpServer = getBasicSmtpServer(server.port);
var identity = getSmtpIdentity(kSender, smtpServer);
var identity = getSmtpIdentity(kIdentityMail, smtpServer);
// This time with auth
test = "Auth sendMailMessage";
@ -73,7 +74,7 @@ add_task(function *() {
smtpServer.socketType = Ci.nsMsgSocketType.plain;
smtpServer.username = kUsername;
MailServices.smtp.sendMailMessage(testFile, kTo, identity,
MailServices.smtp.sendMailMessage(testFile, kTo, identity, kSender,
null, null, null, null,
false, {}, {});
@ -87,7 +88,7 @@ add_task(function *() {
"AUTH PLAIN " + AuthPLAIN.encodeLine(kUsername, kPassword2),
"AUTH LOGIN",
"AUTH PLAIN " + AuthPLAIN.encodeLine(kUsername, kPassword1),
"MAIL FROM:<" + kSender + "> BODY=8BITMIME SIZE=155",
"MAIL FROM:<" + kSender + "> BODY=8BITMIME SIZE=159",
"RCPT TO:<" + kTo + ">",
"DATA"]);

Просмотреть файл

@ -14,10 +14,13 @@ var sentFolder;
var originalData;
var finished = false;
var identity = null;
var testFile = do_get_file("data/429891_testcase.eml");
var kSender = "from@foo.invalid";
var kTo = "to@foo.invalid";
var kTestFileSender = "from_A@foo.invalid";
var kTestFileRecipient = "to_A@foo.invalid";
var kIdentityMail = "identity@foo.invalid";
var msgSendLater = Cc["@mozilla.org/messengercompose/sendlater;1"]
.getService(Ci.nsIMsgSendLater);
@ -57,8 +60,9 @@ msll.prototype = {
do_check_transaction(server.playTransaction(),
["EHLO test",
"MAIL FROM:<" + kSender + "> BODY=8BITMIME SIZE=" + originalData.length,
"RCPT TO:<" + kTo + ">",
"MAIL FROM:<" + kTestFileSender +
"> BODY=8BITMIME SIZE=" + originalData.length,
"RCPT TO:<" + kTestFileRecipient + ">",
"DATA"]);
// Compare data file to what the server received
@ -183,7 +187,7 @@ function run_test() {
let incomingServer = MailServices.accounts.createIncomingServer("test", "localhost", "pop3");
smtpServer = getBasicSmtpServer(0);
identity = getSmtpIdentity(kSender, smtpServer);
identity = getSmtpIdentity(kIdentityMail, smtpServer);
account.addIdentity(identity);
account.defaultIdentity = identity;
@ -199,8 +203,12 @@ function run_test() {
var compFields = Cc["@mozilla.org/messengercompose/composefields;1"]
.createInstance(Ci.nsIMsgCompFields);
compFields.from = identity.email;
compFields.to = kTo;
// Setting the compFields sender and recipient to any value is required to
// survive mime_sanity_check_fields in nsMsgCompUtils.cpp.
// Sender and recipient are required for sendMessageFile but SMTP
// transaction values will be used directly from mail body.
compFields.from = "irrelevant@foo.invalid";
compFields.to = "irrelevant@foo.invalid";
var msgSend = Cc["@mozilla.org/messengercompose/send;1"]
.createInstance(Ci.nsIMsgSend);

Просмотреть файл

@ -15,7 +15,10 @@ var identity = null;
var testFile1 = do_get_file("data/429891_testcase.eml");
var testFile2 = do_get_file("data/message1.eml");
var kSender = "from@foo.invalid";
var kTestFile1Sender = "from_A@foo.invalid";
var kTestFile1Recipient = "to_A@foo.invalid";
var kIdentityMail = "identity@foo.invalid";
var kTo = "to@foo.invalid";
var gMsgSendLater;
@ -56,8 +59,9 @@ msll.prototype = {
do_check_transaction(server.playTransaction(),
["EHLO test",
"MAIL FROM:<" + kSender + "> BODY=8BITMIME SIZE=" + originalData.length,
"RCPT TO:<" + kTo + ">",
"MAIL FROM:<" + kTestFile1Sender +
"> BODY=8BITMIME SIZE=" + originalData.length,
"RCPT TO:<" + kTestFile1Recipient + ">",
"DATA"]);
// Compare data file to what the server received
@ -108,7 +112,7 @@ function run_test() {
server = setupServerDaemon();
server.start();
var smtpServer = getBasicSmtpServer(server.port);
identity = getSmtpIdentity(kSender, smtpServer);
identity = getSmtpIdentity(kIdentityMail, smtpServer);
account.addIdentity(identity);
account.defaultIdentity = identity;
@ -124,8 +128,12 @@ function run_test() {
var compFields = Cc["@mozilla.org/messengercompose/composefields;1"]
.createInstance(Ci.nsIMsgCompFields);
compFields.from = identity.email;
compFields.to = kTo;
// Setting the compFields sender and recipient to any value is required to
// survive mime_sanity_check_fields in nsMsgCompUtils.cpp.
// Sender and recipient are required for sendMessageFile but SMTP
// transaction values will be used directly from mail body.
compFields.from = "irrelevant@foo.invalid";
compFields.to = "irrelevant@foo.invalid";
var msgSend = Cc["@mozilla.org/messengercompose/send;1"]
.createInstance(Ci.nsIMsgSend);

Просмотреть файл

@ -11,11 +11,15 @@ Components.utils.import("resource:///modules/mailServices.js");
var test = null;
var server;
var kIdentityMail = "identity@foo.invalid";
var kSender = "from@foo.invalid";
var kTo = "to@foo.invalid";
var kUsername = "testsmtp";
var kPassword = "smtptest";
var kTestFileSender = "from_B@foo.invalid";
var kTestFileRecipient = "to_B@foo.invalid";
function test_RFC2821() {
// Test file
@ -26,16 +30,18 @@ function test_RFC2821() {
server.start();
var smtpServer = getBasicSmtpServer(server.port);
var identity = getSmtpIdentity(kSender, smtpServer);
var identity = getSmtpIdentity(kIdentityMail, smtpServer);
// Handle the server in a try/catch/finally loop so that we always will stop
// the server if something fails.
try {
// Just a basic test to check we're sending mail correctly.
test = "Basic sendMailMessage";
MailServices.smtp.sendMailMessage(testFile, kTo, identity,
// First do test with identity email address used for smtp MAIL FROM.
Services.prefs.setBoolPref("mail.smtp.useSenderForSmtpMailFrom", false);
MailServices.smtp.sendMailMessage(testFile, kTo, identity, kSender,
null, null, null, null,
false, {}, {});
@ -43,13 +49,30 @@ function test_RFC2821() {
var transaction = server.playTransaction();
do_check_transaction(transaction, ["EHLO test",
"MAIL FROM:<" + kSender + "> BODY=8BITMIME SIZE=155",
"MAIL FROM:<" + kIdentityMail + "> BODY=8BITMIME SIZE=159",
"RCPT TO:<" + kTo + ">",
"DATA"]);
server.resetTest();
// This time with auth
// Now do the same test with sender's email address used for smtp MAIL FROM.
Services.prefs.setBoolPref("mail.smtp.useSenderForSmtpMailFrom", true);
MailServices.smtp.sendMailMessage(testFile, kTo, identity, kSender,
null, null, null, null,
false, {}, {});
server.performTest();
var transaction = server.playTransaction();
do_check_transaction(transaction, ["EHLO test",
"MAIL FROM:<" + kSender + "> BODY=8BITMIME SIZE=159",
"RCPT TO:<" + kTo + ">",
"DATA"]);
server.resetTest();
// This time with auth.
test = "Auth sendMailMessage";
smtpServer.authMethod = Ci.nsMsgAuthMethod.passwordCleartext;
@ -57,7 +80,10 @@ function test_RFC2821() {
smtpServer.username = kUsername;
smtpServer.password = kPassword;
MailServices.smtp.sendMailMessage(testFile, kTo, identity,
// First do test with identity email address used for smtp MAIL FROM.
Services.prefs.setBoolPref("mail.smtp.useSenderForSmtpMailFrom", false);
MailServices.smtp.sendMailMessage(testFile, kTo, identity, kSender,
null, null, null, null,
false, {}, {});
@ -66,10 +92,27 @@ function test_RFC2821() {
var transaction = server.playTransaction();
do_check_transaction(transaction, ["EHLO test",
"AUTH PLAIN " + AuthPLAIN.encodeLine(kUsername, kPassword),
"MAIL FROM:<" + kSender + "> BODY=8BITMIME SIZE=155",
"MAIL FROM:<" + kIdentityMail + "> BODY=8BITMIME SIZE=159",
"RCPT TO:<" + kTo + ">",
"DATA"]);
server.resetTest();
// Now do the same test with sender's email address used for smtp MAIL FROM.
Services.prefs.setBoolPref("mail.smtp.useSenderForSmtpMailFrom", true);
MailServices.smtp.sendMailMessage(testFile, kTo, identity, kSender,
null, null, null, null,
false, {}, {});
server.performTest();
var transaction = server.playTransaction();
do_check_transaction(transaction, ["EHLO test",
"AUTH PLAIN " + AuthPLAIN.encodeLine(kUsername, kPassword),
"MAIL FROM:<" + kSender + "> BODY=8BITMIME SIZE=159",
"RCPT TO:<" + kTo + ">",
"DATA"]);
} catch (e) {
do_throw(e);

Просмотреть файл

@ -22,9 +22,10 @@ var originalData;
var finished = false;
var identity = null;
var testFile = do_get_file("data/429891_testcase.eml");
var kTestFileSender = "from_A@foo.invalid";
var kTestFileRecipient = "to_A@foo.invalid";
var kSender = "from@foo.invalid";
var kTo = "to@foo.invalid";
var kIdentityMail = "identity@foo.invalid";
var kToEncodedDisplayName = "=?UTF-8?B?RnLDqcOpZGxlLCBUZXN0?="; // "Fréédle, Test"
var msgSendLater = Cc["@mozilla.org/messengercompose/sendlater;1"]
@ -69,8 +70,9 @@ msll.prototype = {
do_check_transaction(server.playTransaction(),
["EHLO test",
"MAIL FROM:<" + kSender + "> BODY=8BITMIME SIZE=" + originalData.length,
"RCPT TO:<" + kTo + ">",
"MAIL FROM:<" + kTestFileSender +
"> BODY=8BITMIME SIZE=" + originalData.length,
"RCPT TO:<" + kTestFileRecipient + ">",
"DATA"]);
// Compare data file to what the server received
@ -191,7 +193,7 @@ function run_test() {
let incomingServer = MailServices.accounts.createIncomingServer("test", "localhost", "pop3");
smtpServer = getBasicSmtpServer(1);
identity = getSmtpIdentity(kSender, smtpServer);
identity = getSmtpIdentity(kIdentityMail, smtpServer);
account.addIdentity(identity);
account.defaultIdentity = identity;
@ -207,8 +209,12 @@ function run_test() {
var compFields = Cc["@mozilla.org/messengercompose/composefields;1"]
.createInstance(Ci.nsIMsgCompFields);
compFields.from = identity.email;
compFields.to = kToEncodedDisplayName + " <" + kTo + ">";
// Setting the compFields sender and recipient to any value is required to
// survive mime_sanity_check_fields in nsMsgCompUtils.cpp.
// Sender and recipient are required for sendMessageFile but SMTP
// transaction values will be used directly from mail body.
compFields.from = "irrelevant@foo.invalid";
compFields.to = "irrelevant@foo.invalid";
var msgSend = Cc["@mozilla.org/messengercompose/send;1"]
.createInstance(Ci.nsIMsgSend);

Просмотреть файл

@ -28,6 +28,17 @@ var gMsgFile =
do_get_file("data/message1.eml"),
do_get_file("data/429891_testcase.eml")
];
var kTestFileSender =
[
"from_B@foo.invalid",
"from_A@foo.invalid"
];
var kTestFileRecipient =
[
"to_B@foo.invalid",
"to_A@foo.invalid"
];
var gMsgFileData = [];
var gMsgOrder = [];
var gCurTestNum = 0;
@ -39,8 +50,7 @@ var gLastSentMessage = 0;
// 2 = sendUnsentMessages has exited.
var gMessageSendStatus = 0;
var kSender = "from@foo.invalid";
var kTo = "to@foo.invalid";
var kIdentityMail = "identity@foo.invalid";
var msgSendLater = Cc["@mozilla.org/messengercompose/sendlater;1"]
.getService(Ci.nsIMsgSendLater);
@ -54,8 +64,8 @@ msll.prototype = {
checkMessageSend: function(aCurrentMessage) {
do_check_transaction(server.playTransaction(),
["EHLO test",
"MAIL FROM:<" + kSender + "> BODY=8BITMIME SIZE=" + gMsgFileData[gMsgOrder[aCurrentMessage - 1]].length,
"RCPT TO:<" + kTo + ">",
"MAIL FROM:<" + kTestFileSender[gMsgOrder[aCurrentMessage - 1]] + "> BODY=8BITMIME SIZE=" + gMsgFileData[gMsgOrder[aCurrentMessage - 1]].length,
"RCPT TO:<" + kTestFileRecipient[gMsgOrder[aCurrentMessage - 1]] + ">",
"DATA"]);
// Compare data file to what the server received
@ -139,8 +149,12 @@ function sendMessageLater(aTestFileIndex)
var compFields = Cc["@mozilla.org/messengercompose/composefields;1"]
.createInstance(Ci.nsIMsgCompFields);
compFields.from = identity.email;
compFields.to = kTo;
// Setting the compFields sender and recipient to any value is required to
// survive mime_sanity_check_fields in nsMsgCompUtils.cpp.
// Sender and recipient are required for sendMessageFile but SMTP
// transaction values will be used directly from mail body.
compFields.from = "irrelevant@foo.invalid";
compFields.to = "irrelevant@foo.invalid";
var msgSend = Cc["@mozilla.org/messengercompose/send;1"]
.createInstance(Ci.nsIMsgSend);
@ -233,7 +247,7 @@ function run_test() {
let incomingServer = MailServices.accounts.createIncomingServer("test", "localhost", "pop3");
smtpServer = getBasicSmtpServer(1);
identity = getSmtpIdentity(kSender, smtpServer);
identity = getSmtpIdentity(kIdentityMail, smtpServer);
account.addIdentity(identity);
account.defaultIdentity = identity;

Просмотреть файл

@ -11,6 +11,7 @@ Components.utils.import("resource:///modules/mailServices.js");
var test = null;
var server;
var kIdentityMail = "identity@foo.invalid";
var kSender = "from@foo.invalid";
var kTo = "to@foo.invalid";
@ -27,7 +28,7 @@ function test_8bitmime(aStrictMime, aServer8bit) {
server.start();
var smtpServer = getBasicSmtpServer(server.port);
var identity = getSmtpIdentity(kSender, smtpServer);
var identity = getSmtpIdentity(kIdentityMail, smtpServer);
// Handle the server in a try/catch/finally loop so that we always will stop
// the server if something fails.
@ -38,7 +39,7 @@ function test_8bitmime(aStrictMime, aServer8bit) {
Services.prefs.setBoolPref("mail.strictly_mime", aStrictMime);
MailServices.smtp.sendMailMessage(testFile, kTo, identity,
MailServices.smtp.sendMailMessage(testFile, kTo, identity, kSender,
null, null, null, null,
false, {}, {});
@ -48,7 +49,7 @@ function test_8bitmime(aStrictMime, aServer8bit) {
do_check_transaction(transaction, ["EHLO test",
"MAIL FROM:<" + kSender +
(!aStrictMime && aServer8bit ?
"> BODY=8BITMIME SIZE=155" : "> SIZE=155"),
"> BODY=8BITMIME SIZE=159" : "> SIZE=159"),
"RCPT TO:<" + kTo + ">",
"DATA"]);

Просмотреть файл

@ -15,9 +15,10 @@ var identity;
var kUsername = "fred";
var kPassword = "wilma";
var kIdentityMail = "identity@foo.invalid";
var kSender = "from@foo.invalid";
var kTo = "to@foo.invalid";
var MAILFROM = "MAIL FROM:<" + kSender + "> BODY=8BITMIME SIZE=155";
var MAILFROM = "MAIL FROM:<" + kSender + "> BODY=8BITMIME SIZE=159";
var RCPTTO = "RCPT TO:<" + kTo + ">";
var AUTHPLAIN = "AUTH PLAIN " + AuthPLAIN.encodeLine(kUsername, kPassword);
@ -74,7 +75,7 @@ function nextTest() {
smtpServer.authMethod = curTest.clientAuthMethod;
// Run test
MailServices.smtp.sendMailMessage(testFile, kTo, identity,
MailServices.smtp.sendMailMessage(testFile, kTo, identity, kSender,
null, null, null, null,
false, {}, {});
server.performTest();
@ -105,7 +106,7 @@ function run_test() {
smtpServer.socketType = Ci.nsMsgSocketType.plain;
smtpServer.username = kUsername;
smtpServer.password = kPassword;
identity = getSmtpIdentity(kSender, smtpServer);
identity = getSmtpIdentity(kIdentityMail, smtpServer);
testFile = do_get_file("data/message1.eml");

Просмотреть файл

@ -9,6 +9,7 @@ load("../../../resources/passwordStorage.js");
var server;
var kIdentityMail = "identity@foo.invalid";
var kSender = "from@foo.invalid";
var kTo = "to@foo.invalid";
var kUsername = "testsmtp";
@ -43,7 +44,7 @@ add_task(function *() {
// Start the fake SMTP server
server.start();
var smtpServer = getBasicSmtpServer(server.port);
var identity = getSmtpIdentity(kSender, smtpServer);
var identity = getSmtpIdentity(kIdentityMail, smtpServer);
// This time with auth
test = "Auth sendMailMessage";
@ -52,7 +53,7 @@ add_task(function *() {
smtpServer.socketType = Ci.nsMsgSocketType.plain;
smtpServer.username = kUsername;
MailServices.smtp.sendMailMessage(testFile, kTo, identity,
MailServices.smtp.sendMailMessage(testFile, kTo, identity, kSender,
null, null, null, null,
false, {}, {});
@ -61,7 +62,7 @@ add_task(function *() {
var transaction = server.playTransaction();
do_check_transaction(transaction, ["EHLO test",
"AUTH PLAIN " + AuthPLAIN.encodeLine(kUsername, kPassword),
"MAIL FROM:<" + kSender + "> BODY=8BITMIME SIZE=155",
"MAIL FROM:<" + kSender + "> BODY=8BITMIME SIZE=159",
"RCPT TO:<" + kTo + ">",
"DATA"]);

Просмотреть файл

@ -20,6 +20,7 @@ load("../../../resources/passwordStorage.js");
var server;
var attempt = 0;
var kIdentityMail = "identity@foo.invalid";
var kSender = "from@foo.invalid";
var kTo = "to@foo.invalid";
var kUsername = "testsmtp";
@ -80,7 +81,7 @@ add_task(function *() {
server.start();
var smtpServer = getBasicSmtpServer(server.port);
var identity = getSmtpIdentity(kSender, smtpServer);
var identity = getSmtpIdentity(kIdentityMail, smtpServer);
// Handle the server in a try/catch/finally loop so that we always will stop
// the server if something fails.
@ -94,7 +95,7 @@ add_task(function *() {
dump("Send\n");
MailServices.smtp.sendMailMessage(testFile, kTo, identity,
MailServices.smtp.sendMailMessage(testFile, kTo, identity, kSender,
null, null, null, null,
false, {}, {});

Просмотреть файл

@ -20,6 +20,7 @@ load("../../../resources/passwordStorage.js");
var server;
var attempt = 0;
var kIdentityMail = "identity@foo.invalid";
var kSender = "from@foo.invalid";
var kTo = "to@foo.invalid";
var kUsername = "testsmtp";
@ -95,7 +96,7 @@ add_task(function *() {
// Start the fake SMTP server
server.start();
var smtpServer = getBasicSmtpServer(server.port);
var identity = getSmtpIdentity(kSender, smtpServer);
var identity = getSmtpIdentity(kIdentityMail, smtpServer);
// This time with auth
test = "Auth sendMailMessage";
@ -106,7 +107,7 @@ add_task(function *() {
dump("Send\n");
MailServices.smtp.sendMailMessage(testFile, kTo, identity,
MailServices.smtp.sendMailMessage(testFile, kTo, identity, kSender,
null, null, null, null,
false, {}, {});
@ -126,7 +127,7 @@ add_task(function *() {
"AUTH LOGIN",
// then we enter the correct password
"AUTH PLAIN " + AuthPLAIN.encodeLine(kUsername, kValidPassword),
"MAIL FROM:<" + kSender + "> BODY=8BITMIME SIZE=155",
"MAIL FROM:<" + kSender + "> BODY=8BITMIME SIZE=159",
"RCPT TO:<" + kTo + ">",
"DATA"]);

Просмотреть файл

@ -18,6 +18,7 @@ load("../../../resources/passwordStorage.js");
var server;
var attempt = 0;
var kIdentityMail = "identity@foo.invalid";
var kSender = "from@foo.invalid";
var kTo = "to@foo.invalid";
var kUsername = "testsmtp";
@ -91,7 +92,7 @@ add_task(function *() {
// Start the fake SMTP server
server.start();
var smtpServer = getBasicSmtpServer(server.port);
var identity = getSmtpIdentity(kSender, smtpServer);
var identity = getSmtpIdentity(kIdentityMail, smtpServer);
// This time with auth
test = "Auth sendMailMessage";
@ -102,7 +103,7 @@ add_task(function *() {
do_test_pending();
MailServices.smtp.sendMailMessage(testFile, kTo, identity,
MailServices.smtp.sendMailMessage(testFile, kTo, identity, kSender,
null, URLListener, null, null,
false, {}, {});

Просмотреть файл

@ -25,6 +25,7 @@ add_task(function* sendMessage() {
var testFile = do_get_file("data/message1.eml");
var urlListener = new PromiseTestUtils.PromiseUrlListener();
MailServices.smtp.sendMailMessage(testFile, "somebody@example.org", identity,
"me@example.org",
null, urlListener, null, null,
false, {}, {});
yield urlListener.promise;