Closed Bug 1524751 Opened 6 years ago Closed 6 years ago

localAccountUtils.associate_servers() is horrible

Categories

(MailNews Core :: Testing Infrastructure, enhancement)

enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
Thunderbird 67.0

People

(Reporter: jorgk-bmo, Assigned: aceman)

Details

Attachments

(1 file)

Check this:

  associate_servers: function(aIncoming, aOutgoingServer, aSetAsDefault) {
    let identity = MailServices.accounts.createIdentity();
    identity.smtpServerKey = aOutgoingServer.key;

    if (aIncoming instanceof Ci.nsIMsgIncomingServer)
      aIncoming = MailServices.accounts.FindAccountForServer(aIncoming);
    aIncoming.addIdentity(identity);
    if (aSetAsDefault)
      aIncoming.defaultIdentity = identity;
  }

Hmm, we reuse/abuse the input parameter aIncoming and I have no idea what would happen if the instanceof returned false. Then we'd try to add an identity to a server :-(

If you don't read this thoroughly, you'd think that aIncoming.defaultIdentity is set by the funtion, but it's not. I wasted some time debugging that :-(

Aceman, can you please fix this.

Flags: needinfo?(acelists)

(In reply to Jorg K (GMT+1) from comment #0)

Hmm, we reuse/abuse the input parameter aIncoming and

I think we do that sometimes.

I have no idea what would happen if the instanceof returned false. Then we'd try to add an identity to a server :-(

No, if it isn't a server we assume it is an account and we can add identity to that.

If you don't read this thoroughly, you'd think that aIncoming.defaultIdentity is set by the funtion, but it's not. I wasted some time debugging that :-(

Hm, why not?

Flags: needinfo?(acelists)

Well, the documentation says:

   * @param aIncoming The incoming server (nsIMsgIncomingServer) or account
   *                  (nsIMsgAccount) to associate.

In case you pass in a server, the aIncoming.defaultIdentity is set in the account, but the caller doesn't see that. I had to do this to make it work for me:
https://hg.mozilla.org/try-comm-central/rev/353a7d02af0986b8b985555d3cd92af56963a37e#l4.43

+  // We also need to have a working identity, including an email address.
+  localAccountUtils.associate_servers(incoming, server, true);
+  let account = MailServices.accounts.FindAccountForServer(incoming);
+  let identity = account.defaultIdentity;
+  dump(identity.toString());
+  identity.email = "tinderbox@tinderbox.invalid";
+  MailServices.accounts.defaultAccount = account;

(In reply to Jorg K (GMT+1) from comment #2)

Well, the documentation says:

   * @param aIncoming The incoming server (nsIMsgIncomingServer) or account
   *                  (nsIMsgAccount) to associate.

In case you pass in a server, the aIncoming.defaultIdentity is set in the account, but the caller doesn't see that.

Doesn't see it on the passed server, but it does happen where it should happen :)

I had to do this to make it work for me:

What does 'work' mean. It seems to me it works.

  • // We also need to have a working identity, including an email address.
  • localAccountUtils.associate_servers(incoming, server, true);
  • let account = MailServices.accounts.FindAccountForServer(incoming);
  • let identity = account.defaultIdentity;
  • dump(identity.toString());
  • identity.email = "tinderbox@tinderbox.invalid";

This is also what https://searchfox.org/comm-central/source/mail/components/test/unit/test_about_support.js#100 does, and in the account the default identity is set.

So if you'd like to change it to take an account directly, we can do that, there are only these 2 callers.

  • MailServices.accounts.defaultAccount = account;

I assume this is not related to the discussed issue.

OK, forget it. Sorry about the noise.

Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → INVALID

We can still do some cleanup in the area.

Status: RESOLVED → REOPENED
Component: General → Testing Infrastructure
OS: Unspecified → All
Hardware: Unspecified → All
Resolution: INVALID → ---
Version: 17 → Trunk
Attached patch 1524751.patch (deleted) — Splinter Review
Assignee: nobody → acelists
Status: REOPENED → ASSIGNED
Attachment #9041005 - Flags: review?(jorgk)
Comment on attachment 9041005 [details] [diff] [review] 1524751.patch Review of attachment 9041005 [details] [diff] [review]: ----------------------------------------------------------------- Yes, this is a net gain. In fact, passing in the account eliminates the need to call `.FindAccountForServer()` twice, one inside and once outside the function. I assume the test still passes. ::: mailnews/test/resources/localAccountUtils.js @@ +149,5 @@ > * > + * @param {nsIMsgAccount} aIncoming The account to associate. > + * @param {nsISmtpServer} aOutgoingServer The outgoing server () to associate. > + * @param {bool} aSetAsDefault Whether to set the outgoing server as the default for > + * the incoming server's account. I think remove "server's" here.
Attachment #9041005 - Flags: review?(jorgk) → review+

Pushed by mozilla@jorgk.com:
https://hg.mozilla.org/comm-central/rev/a7097aec4a71
make associate_servers() take an incoming account instead of a server. r=jorgk

Status: ASSIGNED → RESOLVED
Closed: 6 years ago6 years ago
Resolution: --- → FIXED
Target Milestone: --- → Thunderbird 67.0
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: