Bug 1897924 - Default to SMTP if we can't figure out the type of an outgoing server. r=mkmelin

Differential Revision: https://phabricator.services.mozilla.com/D214002

--HG--
extra : amend_source : ef6a83142f9b5fa7d78e9bb1b089901cc54ac9aa
This commit is contained in:
Brendan Abolivier 2024-06-19 11:49:23 +02:00
Родитель b347f77d09
Коммит fe548810a8
2 изменённых файлов: 28 добавлений и 4 удалений

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

@ -241,11 +241,15 @@ export class OutgoingServerService {
* @returns {nsIMsgOutgoingServer}
*/
_keyToServer(key) {
// We're intentionally not setting a default value, because if we're not
// sure of the type we want to fail early, rather than e.g. halfway through
// trying to configure the server with incorrect settings.
// Ideally we should be failing early if we can't figure out the type,
// because we might be trying to configure the server for the wrong
// protocol. However, We might be currently migrating an old profile that
// predates this pref being introduced, in which case we'll try to read this
// pref before the profile migration code has had a chance to set it. In
// which case, it's likely safe to assume the server's type is SMTP.
const serverType = Services.prefs.getCharPref(
`mail.smtpserver.${key}.type`
`mail.smtpserver.${key}.type`,
"smtp"
);
const server = Cc[OUTGOING_CONTRACT_ID_PREFIX + serverType].createInstance(

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

@ -5,6 +5,26 @@
* Tests for the SMTP implementation of nsIMsgOutgoingServer.
*/
/**
* Test that, if the outgoing server service does not have a type for the
* server, it defaults to instantiating the SMTP implementation.
*/
add_task(async function test_default_server_type() {
// Add a new server to the outgoing server service's list. Note that we don't
// set any property - including a type - on this new server.
Services.prefs.setCharPref("mail.smtpservers", "smtp1");
// Get the new server from the service (and make sure the operation doesn't
// throw, which would happen if we don't have a default value).
const server = MailServices.outgoingServer.getServerByKey("smtp1");
// Check that the service correctly defaulted to the SMTP implementation.
Assert.equal(server.type, "smtp");
// Remove the server from the service to avoid any side-effect.
MailServices.outgoingServer.deleteServer(server);
});
/**
* Test that cached server password is cleared when password storage changed.
*/