Closed
Bug 970118
Opened 11 years ago
Closed 11 years ago
Improve nsIMsgCompose::checkAndPopulateRecipients
Categories
(MailNews Core :: Composition, defect)
MailNews Core
Composition
Tracking
(Not tracked)
RESOLVED
FIXED
Thunderbird 30.0
People
(Reporter: jcranmer, Assigned: jcranmer)
References
(Blocks 1 open bug)
Details
Attachments
(1 file, 1 obsolete file)
59.66 KB,
patch
|
neil
:
review+
|
Details | Diff | Splinter Review |
Whooo boy. This is a nasty little interface definition, and here's the history:
Originally, this method was getNonHtmlRecipients, apparently checking if any recipients preferred plain text. Ironically enough, the only use of the return value was to check if it was non-empty. This sole use has not been changed in the intervening 14 years, even in addons code. Along the way, the method was changed to support expanding mailing lists. It was also changed to return a more nuanced preference for mail (which was broken in Thunderbird by bug 872041, see bug 921836).
As part of the structured header revolution, I want to end the use of strings to represent addressing headers, and this is a perfect method that needs to be restructured. Addon impact is extremely minimal. Proposal:
Split the method into two methods, expandMailingLists and getHTMLAction. It's clear from MsgComposeCommands.js that there is a pretty strict definition of what needs to be done there, so that JS code (cloned between SM and TB, with TB's copy being broken) should be folded into the getHTMLAction instead of determining a preferred mail format.
Assignee | ||
Comment 1•11 years ago
|
||
Oh, I forgot. This method also increments the popularity index of sending messages. How could I neglect to mention this all-important feature which is neither implied by the API nor mentioned in the comments?
Updated•11 years ago
|
OS: Linux → All
Hardware: x86_64 → All
Assignee | ||
Comment 2•11 years ago
|
||
This patch may seem a bit complicated. Originally, I had it as three separate patches, but the division between them ended up being poorer than I wanted. I also feel like it may be worth moving the address collection from nsMsgSend to nsMsgCompose, but that's another patch for another day.
Attachment #8375308 -
Flags: review?(neil)
Comment 3•11 years ago
|
||
Eww, so every time I cancel the HTML mail question I've inadvertently bumped the popularity index of all of the recipients?
Comment 4•11 years ago
|
||
Comment on attachment 8375308 [details] [diff] [review]
Version 1
ExpandMailingLists wants to handle each field separately but DetermineHTMLAction ideally wants everything in one big array; I couldn't think of a nice way of handling that.
> rv = existingCard->GetPropertyAsUint32(kPreferMailFormatProperty,
>+ &preferFormat);
I take it you check all address books until you find a card with the format property? Why throw away the value?
>+ nsTArray<nsMsgRecipient> recipientsList[MAX_OF_RECIPIENT_ARRAY];
RecipientsArray?
>+ // Grab a ref to the directory--we're appending to the nsTArray, which
>+ // can invalidate the reference to recipient underneath us.
Nit: you don't append to the nsTArray until after you need the current entry.
>+nsMsgCompose::DetermineHTMLAction(int32_t aConvertible, int32_t *result)
Looks like if there are any newsgroups you should immediately return AskUser. Then after the loop you can write:
if (allHtml) return HTML;
if (allPlain || convertible == Plain) return PlainText;
if (pref != Unknown) return pref;
return AskUser;
>+ bool allHtml = true;
>+ bool allPlain = true;
>+
>+ for (int i = 0; i < MAX_OF_RECIPIENT_ARRAY; ++i)
Nit: would be more efficient if you stopped looping once both were false.
Assignee | ||
Comment 5•11 years ago
|
||
(In reply to neil@parkwaycc.co.uk from comment #4)
> > rv = existingCard->GetPropertyAsUint32(kPreferMailFormatProperty,
> >+ &preferFormat);
> I take it you check all address books until you find a card with the format
> property? Why throw away the value?
/me peers in more closely to the code.
Originally, I wanted to trash the get where it was when it started, but then I decided to avoid changing semantics too much. Considering that we're trying to get specifically two different properties that may in theory want different cards, it's probably better to ensure that PAB/CAB come first here and drop the checks, since it looks like known of our other ab backends support preferMailFormat (or popularity for that matter).
Thoughts?
> >+ // Grab a ref to the directory--we're appending to the nsTArray, which
> >+ // can invalidate the reference to recipient underneath us.
> Nit: you don't append to the nsTArray until after you need the current entry.
It's very confusing at first, but the append is in the middle of a loop. If we have a mailing list with two entries, the code crashes--that's why I added the copy.
> >+nsMsgCompose::DetermineHTMLAction(int32_t aConvertible, int32_t *result)
> Looks like if there are any newsgroups you should immediately return
> AskUser.
Heh, that was my original plan all along. I only stopped doing so on the basis that it might make adding intelligent send prefs for news harder.
Assignee | ||
Comment 6•11 years ago
|
||
(In reply to neil@parkwaycc.co.uk from comment #3)
> Eww, so every time I cancel the HTML mail question I've inadvertently bumped
> the popularity index of all of the recipients?
Another option is to move the popularity bump to the address collector (it already has to query the lookup anyways), but that was a yet more invasive patch I didn't want to do.
Comment 7•11 years ago
|
||
(In reply to Joshua Cranmer from comment #5)
> (In reply to comment #4)
> > > rv = existingCard->GetPropertyAsUint32(kPreferMailFormatProperty,
> > >+ &preferFormat);
> > I take it you check all address books until you find a card with the format
> > property? Why throw away the value?
>
> /me peers in more closely to the code.
>
> Originally, I wanted to trash the get where it was when it started, but then
> I decided to avoid changing semantics too much. Considering that we're
> trying to get specifically two different properties that may in theory want
> different cards, it's probably better to ensure that PAB/CAB come first here
> and drop the checks, since it looks like known of our other ab backends
> support preferMailFormat (or popularity for that matter).
My original question was really only about the detected prefer format value, although now that you draw my attention to it, your popularity appears to be broken if it doesn't find a preferred format but does find a card in a readonly address book (I don't know whether that occurs in practice).
Assignee | ||
Comment 8•11 years ago
|
||
Attachment #8375308 -
Attachment is obsolete: true
Attachment #8375308 -
Flags: review?(neil)
Attachment #8384204 -
Flags: review?(neil)
Comment 9•11 years ago
|
||
Comment on attachment 8384204 [details] [diff] [review]
Version 2
>- if (!recipient.mProcessed)
>+ if (!recipient.mDirectory && !recipient.mCard)
Nit: You never set the card without setting the directory, so you don't need to test for it.
>+ // Bump the popularity index for this card since we are about to send
>+ // e-mail to it.
>+ uint32_t popularityIndex = 0;
>+ if (!readOnly)
Nit: move the variable inside the if
Attachment #8384204 -
Flags: review?(neil) → review+
Assignee | ||
Comment 10•11 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → Thunderbird 30.0
Comment 11•11 years ago
|
||
Wohoo! This must have been one of the ugliest interfaces we had.
You need to log in
before you can comment on or make changes to this bug.
Description
•