Open Bug 819392 Opened 12 years ago Updated 1 year ago

Archive set for year-month fails, archives to year only for some messages (archive setting of non-primary identity is used with multi-identities or Delivered-to:(mismatch among Archive UI, "archiveMessages:+getIdentityForHeader" , and user's expectation)

Categories

(MailNews Core :: Backend, defect)

defect

Tracking

(Not tracked)

People

(Reporter: mozilla-bugs, Unassigned)

References

Details

(Keywords: reproducible, testcase, Whiteboard: [workaround: keep same archive setting among all identites])

Attachments

(1 file, 1 obsolete file)

User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:17.0) Gecko/20100101 Firefox/17.0
Build ID: 20121129165506

Steps to reproduce:

Have archiving set to do so by year/month on an IMAP account.


Actual results:

Some messages get archived to a year only folder, as if the parser failed to determine the month. Other messages archive as expected.

Example date from mail headers where archive missed month:
Date: Wed, 5 Dec 2012 17:28:40 +0000

This ended up in Archives/2012 instead of Archives/2012/2012-12. Attempting to re-archive leaves it in the same Archives/2012 folder.

Noted that the same format for other messages works correctly, can supply other header items as needed.
I can confirm this problem, happens here, too.

I'm using a POP3S account.

Might be important: I configured Account/Archive/year/year-month (no "s") as target folder for archives but the lost mails end up in Account/Archives/year (with "s").
(In reply to Bill Carlson from comment #0)
> This ended up in Archives/2012 instead of Archives/2012/2012-12. Attempting
> to re-archive leaves it in the same Archives/2012 folder.
(In reply to Daniel Höpfl from comment #1)
> I can confirm this problem, happens here, too.

Which is the "This ended up in Archives/2012 instead of Archives/2012/2012-12"?
(a) archived mails
(b) archived folder structure
What is path length of .msf file corresponds to Archives/2012/2012-mm and sub folders of it?

If Win, at Command Prompt, DIR "Mail_Directory" /S > C:\WORK\LIST.TXT, followed by notepad.exe C:\WORK\LIST.TXT, where Mail_Directory == directory path shown at Account Settings/Server Settings, Local Directory: field(== value in mail.server.serverN.directory in prefs.js where N is server number).
If Linux, use "ls" command or something with appropriate parameter, please.
Tb uses file set of mboxname and mboxname.msf for an Mbox, and uses dirctory of mboxname.sbd to hold the file set for subfolder.
> Example of file path for Archives=>yyyy=>yyyy-mm=>ArcivedFolder=>SubFolderOfArcivedFolder
>  /.../ImapMail/<server_name>/Archives.sbd/yyyy.sbd/yyyy-mm.sbd/ArcivedFolder.sbd/SubFolderOfArcivedFolder.msf   
>  C:\...\Mail\<server_name>\Archives.sbd\yyyy.sbd\yyyy-mm.sbd\ArcivedFolder.sbd\SubFolderOfArcivedFolder.msf   

(In reply to Daniel Höpfl from comment #1)
> Might be important: I configured Account/Archive/year/year-month (no "s") as
> target folder for archives but the lost mails end up in
> Account/Archives/year (with "s").

What is your actual archive setting in prefs.js?
=> find serverN for the POP3 account
> mail.server.serverN.type == pop3
> mail.server.serverN.hostname or mail.server.serverN.hostname == your server
> mail.server.serverN.userName or mail.server.serverN.realuserName == your ID
=> find accountP for serverN
mail.account.accountP.server == serverN
=> get main identity number for accountP 
mail.account.accountP.identities == idX,idy,idz,...
=> archive setting for the main identity of accountP
> mail.identity.idX.archive_enabled
> mail.identity.idX.archive_folder
> mail.identity.idX.archive_granularity
> mail.identity.idX.archive_keep_folder_structure
> mail.identity.idX.archives_folder_picker_mode
Sorry typo. Correct one. 
> mail.server.serverN.hostname or mail.server.serverN.realhostname == your server
(In reply to Daniel Höpfl from comment #1)
> but the lost mails end up in Account/Archives/year (with "s").

If IMAP, if user deletes archive folder requested at Copies&Folders while Tb is not running or Tb doesn't open the archive folder, IIRC, Tb doesn't try to create requested archive folder, instead tries to use default archive folder(archive folder in XLIST, or if no XLIST, top level 'Archives' of the account).
Similar "fall back" may be done on archive folder of POP3 and Local Folders.
If due to path length limitation, it may be "fall back to default archive folder(top level 'Archives' of the account) when Tb fails to archive mails to requested folder".
(In reply to Bill Carlson from comment #0)
> Have archiving set to do so by year/month on an IMAP account.
> Attempting to re-archive leaves it in the same Archives/2012 folder.

Is your archive setting changed to default by Tb after problem?
As you use same folder as default, top level "Archives" of the IMAP account, relevant setting in your case is following that is set via "Archive options...";
> mail.identity.idX.archive_granularity
> mail.identity.idX.archive_keep_folder_structure
(In reply to WADA from comment #5)
Problem is not config, when archiving messages some go to Archives/year/month and others go to Archives/year. Moving messages back to INBOX and re-archiving does the same thing again.
(In reply to Bill Carlson from comment #6)
> Problem is not config, when archiving messages some go to
> Archives/year/month and others go to Archives/year.

Preference setting related to archive doesn't look changed by Tb after something wrong happens, but, I think simply pasting relevant settings is better than words...
And, I can't understand why you don't do "ls" result check to rule out file path length relevant problem first, before adding comment...
(In reply to WADA from comment #7)
> Preference setting related to archive doesn't look changed by Tb after
> something wrong happens, but, I think simply pasting relevant settings is
> better than words...

user_pref("mail.identity.id1.archive_granularity", 2);
user_pref("mail.identity.id1.archive_keep_folder_structure", false);


> And, I can't understand why you don't do "ls" result check to rule out file
> path length relevant problem first, before adding comment...

Verified, file name length is not an issue on either server or client.
If you (In reply to Bill Carlson from comment #8)
> user_pref("mail.identity.id1.archive_granularity", 2);
> user_pref("mail.identity.id1.archive_keep_folder_structure", false);

No subfolder will be generated under Archives/yyyy/yyyy-mm in your case.

If your IMAP server's Mbox is one of next type only,
  a) can hold sub folder only, b) can hold mail only
following can occur.
- If 2012 is created as a), mail can't be copied to 2012.
  (if \Noselect is returned, this folder is shown in grayed-out/italic by Tb)
  This can occur when Archives/2012/2012-01 is created by
  single "create Archives/2012/2012-01", instead of "create Archives/2012" and
  "create Arcives/2012/2012-01", if such IMAP server.
- If 2012 is created as b), subfolder of 2012/2012-01 can't be created.
  This can occur when Archives/2012/2012-01 is created by "create Archives/2012"
  and "create Arcives/2012/2012-01",
  instead of single "create Archives/2012/2012-01", if such IMAP server.
This case?
Try following.
  Create Archives/A, Create Archives/A/B, Archives/A/B/C, ... in this order.
  Copy mail to Archives/A, Archives/A/B, Archives/A/B/C, ...
Correction. Sorry for spam.
- If 2012 is created as b), subfolder of 2012/2012-01 can't be created.
  This can occur when Archives/2012 is created by "create Archives/2012"
  when Archives already exists, if such IMAP server.
(In reply to WADA from comment #10)
> Correction. Sorry for spam.

Sorry, "Archives/yyyy/mm" is not an actual pathname, only using a a shorthand for:
Folder Archives, Subfolder yyyy, Subfolder mm

Again, issue is the following:
Two messages in INBOX, archive both. One message is archived to Folder mm in Folder yyyy in Folder Archives, other message is archived to Folder yyyy in Folder Archives. KEY ISSUE: archiving is happening to TWO different locations, same session, config, etc.

On actual IMAP server, in maildir format, the paths for the archives are:
/serverhome/username/.Archives.yyyy/
/serverhome/username/.Archives.yyyy/mm/
(In reply to Bill Carlson from comment #11)
> Again, issue is the following:
> Two messages in INBOX, archive both. One message is archived to Folder mm in
> Folder yyyy in Folder Archives, other message is archived to Folder yyyy in
> Folder Archives. KEY ISSUE: archiving is happening to TWO different
> locations, same session, config, etc.

Same yyyy for the yyyy and yyyy/mm? Or differnt yyyy for the yyyy and yyyy/mm?
If 2011 and 2012/01, "Mbox for subfolder only, Mbox mail only" may be relevant to your problem.
If mail is archived to both 2012 and 2012/01, 2012 can hold both sub folders and mails.
Can mails be manually copied to top level Archives, any of Archives/xxxx, any of Archives/yyyy/zz in your environment?
Can subfolder be created under existent Archives/yyyy/mm which already holds mail in it?
(In reply to WADA from comment #12)
> Same yyyy for the yyyy and yyyy/mm? Or differnt yyyy for the yyyy and
> yyyy/mm?

Same yyyy and mm for both messages. Both Folders work as expected.
(In reply to Bill Carlson from comment #13)
> (In reply to WADA from comment #12)
> > Same yyyy for the yyyy and yyyy/mm? Or differnt yyyy for the yyyy and
> > yyyy/mm?
> Same yyyy and mm for both messages. Both Folders work as expected.

I see.
Does "mail archived to yyyy instead of yyyy/mm even though mail.identity.id1.archive_granularity=2" have correct Date: header or timestamp related header in message source?
Date: in mail from bugzilla.
> Date: Tue, 26 Feb 2013 18:55:06 +0000
Date: you pasted to comment #0
> Date: Wed, 5 Dec 2012 17:28:40 +0000

day part is not two bytes. This may be relevant.
Is date correctly shown at thread pane?
What happen mail for following Date:
> Date: Wed,  5 Dec 2012 17:28:40 +0000
> Date: Wed, 05 Dec 2012 17:28:40 +0000
(In reply to WADA from comment #15)

It repeated today, this is not a one time occurrence item. I thought it might be a particular date combination also, but doesn't appear so. Have 17 such messages from the last week.

Here's Date header from messages in Archives->2013 (I'll use this to indicate folders):
Date: Wed, 20 Feb 2013 12:08:26 -0600
Date: Wed, 20 Feb 2013 23:37:57 +0000
Date: Thu, 21 Feb 2013 20:46:03 +0000
Date: Thu, 21 Feb 2013 20:47:15 +0000
Date: Thu, 21 Feb 2013 14:51:08 -0600
Date: Fri, 22 Feb 2013 16:57:55 +0000
Date: Fri, 22 Feb 2013 10:31:47 -0800
Date: Fri, 22 Feb 2013 11:18:02 -0800
Date: Sat, 23 Feb 2013 07:33:32 -0600
Date: Sun, 24 Feb 2013 11:04:46 +0100
Date: 24 Feb 2013 09:00:44 -0500
Date: Tue, 26 Feb 2013 00:52:10 +0000
Date: Tue, 26 Feb 2013 00:52:10 +0000
Date: Mon, 25 Feb 2013 18:41:09 -0500 (EST)
Date: Tue, 26 Feb 2013 10:36:27 -0500
Date: Tue, 26 Feb 2013 15:02:00 -0600
Date: Tue, 26 Feb 2013 17:40:27 -0500 (EST)

Some are a little strange, but most are okay.

I can get any raw headers needed, just let me know which header to check.
(In reply to Daniel Höpfl from comment #1)
> Might be important: I configured Account/Archive/year/year-month (no "s") as
> target folder for archives but the lost mails end up in
> Account/Archives/year (with "s").

This seems important, indicates somewhere the default configuration value is used instead of the actual configuration option.
(In reply to Bill Carlson from comment #16)
> Date: 24 Feb 2013 09:00:44 -0500

No "day of the week" case. Problem in Date; header parser in this case is already resolved. Archive feature does do different Date: header parsing?

> Date: Mon, 25 Feb 2013 18:41:09 -0500 (EST)
> Date: Tue, 26 Feb 2013 17:40:27 -0500 (EST)

Excess string after timezone case. Archive feature considers it as malformed? 

> Date: Wed, 20 Feb 2013 12:08:26 -0600
> Date: Wed, 20 Feb 2013 23:37:57 +0000
> Date: Thu, 21 Feb 2013 20:46:03 +0000
> Date: Thu, 21 Feb 2013 20:47:15 +0000
> Date: Thu, 21 Feb 2013 14:51:08 -0600
> Date: Fri, 22 Feb 2013 16:57:55 +0000
> Date: Fri, 22 Feb 2013 10:31:47 -0800
> Date: Fri, 22 Feb 2013 11:18:02 -0800
> Date: Sat, 23 Feb 2013 07:33:32 -0600
> Date: Sun, 24 Feb 2013 11:04:46 +0100
> Date: Tue, 26 Feb 2013 00:52:10 +0000
> Date: Tue, 26 Feb 2013 00:52:10 +0000
> Date: Tue, 26 Feb 2013 10:36:27 -0500
> Date: Tue, 26 Feb 2013 15:02:00 -0600

Funny. Archive feature looks other headers?

Do you enable Received column? If yes, do you set Received in mailnews.customHeaders(if Received is used by message filter, Received is set in this prefs entry) or mailnews.customDBHeaders(user manually set in this entry) for Received column?

Do you see your problem on local mail folder and local Archives folder?
   1. Add dummy POP3 account(Manual Config in accunt creation),
   2. Copy above mails to folder of the dummy account,  3. Archive

Tb currently uses "uid xxx fetch body[HEADER.FIELDS ( subject date to ... )]" for message header fetch. And, some IMAP servers don't return header in message source as-is to selective header fetch request, instead returns "re-constructed header data from parsing result by server". Gmail IMAP is an such IMAP server. See bug 402426 for example in Gmail IMAP.
If your IMAP server is such server, problem may be relevant to header data returned from server for body[HEADER.FIELDS ( ...)]".
For checking it, Tb's protocol logging is useful. See bug 402793 comment #28 for getting IMAP log.
Creation of subfoolder for archive looks done at following.
> http://mxr.mozilla.org/comm-central/source/mail/base/content/mailWindowOverlay.js#1714

Creation of Archive subfolder looks asynchronous. If something wrong occurs in subfolder creation phase, fallback(archive_granularity=2->1->0 like one) may occur.
Mails in comment #16 should go Archives/2012/02 in your case.
Was Archives/2012/02 already created when your problem occurred?
If problem occurs even when Archives/2012/02 already exists, problem in subfolder creation can not happen, so problem is in opening of Archives/2012/02, or in moving mail from source folder to Archives/2012/02, or in mail's date processing.
This is a tool I created for my testing of other bugs. Because still under construction and personal one, any bug such as infinite loop what causes Tb's crash or freeze, profile corruption, can occur. Install in test profile only, and remove after your test ASAP, please. 

How to check date value of mail.
(1) This test extension adds 3 toolbar buttons.
    Customize ToolBar, add button2(i icon) to Menu Bar, or ToolBar.
(2) Open Error Console
(3) Change IMAP delete model to "Just mark it as deleted", to see mail deleted
    by archive at source folder of archive(Account Settings/Server Settings)
    Deleted mail is shown with strike-thru line at thread pane.
(4) Show Order Received column(if IMAP, UID of mail == messagekey in msgDB),
    Select a mail folder, select a mail
(5) At menu of button 2, Selected Folder Info -> Selected Mail, or All Mail
    (don't use "All Mail" for big Mbox. memory hog may occur, because this tool)
    (holds all data in JavaScript object/array, dump data to single text var,  )
    (then put to Error Console.)
(6) Copy log data in Error Console, Paste to Text Editor.
Date vale is saved in Date or DateInSeconds property(perhaps delta of Date header from Epoc Time).

Is something wrong seen in Date or DateInSeconds property value of problematic mails?
Other concerns.

Year, Month was determined from Date value in msgDBHeader data of each mail. 
> http://mxr.mozilla.org/comm-central/source/mail/base/content/mailWindowOverlay.js#1601
So, as far as Date value is correct and Archives folder exists and is acceccible and year folder/month folder can be created or already exists, mail should be archived(moved==copied+deleted), according to the date value and  archive_granularity=2 in your case.

According to source code, month folder name looks yyyy-mm always.
How did you modify it to yyyy/mm?

Problem like following existed.
  When multiple mails are selected, archive target folder determintion is base
  only on date of first selected message.
IIRC, this was resolved, but it may be folder view=All case only, and similar problem may exist in Unified Folder or Search Folder.
What Folder View? Virtual folder? (Saved Search Folder, Unified Folder, ...) 
How did you select archive mails? Select All at thread pane? Non-continous selection? Selection via View(All, Unread, Custimized View, ...)? Or filtered result by Quick Filter Bar?
Sorry for the delayed feedback ... It took some time to experiment.

I found a way to reproduce it (it depends on having multiple identities):

- Create a new Thunderbird profile (e.g. by setting up a new user on your OS)
- Configure a dummy POP3 account for email@example.com
- Set up archive rules for the account. (Tools->Account Settings->Copies&Folders->Archive options->Monthly archived folders)
- Quit Thunderbird
- Copy a mailbox with some mails into your mail directory (.../Profiles/XXX.default/Mail/example.com/Testmails). These mails should have several different recipients (To: <email@example.com>, To: <other@example.com>, To: <mewasbcc@someone.else.com>, ...)
- Restart Thunderbird (you will now see the new mailbox "Testmails")
- Mark all mails, archive them. Everything is fine.
- Move all mails back into Testmails
- Set up a second identity, e-mail-address: other@example.com
- Mark all mails, archive them. Everything is fine.
- Move all mails back into Testmails
- Now change the archive rules for the account. (Tools->Account Settings->Copies&Folders->Archive options->Yearly archived folders)
- Mark all mails, archive them. Ups.

Changing the archive rules for the account does not change the rules for secondary identities. It works for mails that are associated with the primary identity or with no identity.

I think this should be changed: By default, identities should use the archive rules of the account. If you want to use different archive rules for one of the identities, there should be an option to explicitly behave differently from the account (default) settings.
(In reply to Daniel Höpfl from comment #22)
> I found a way to reproduce it (it depends on having multiple identities):
>(snip)
> - Set up a second identity, e-mail-address: other@example.com

As for Archive, iif i understand correctly, multiple identities can't have relation, except when "X-Identity-Keys: in mail header" case, because Archive setting is get from primary(first) identity of an account, although second or more identity can have archive setting in prefs.js.
  - Copies&Folders Setting panel is shared by all identities.
  - Archive setting is not removed from second or more identities yet.
Archive related setting is currently "per account" setting conceptually.

I guess "X-Accout-Key => primary identity selection" relevant phenomenon.

IIRC, if new account is created just after profile creation, Tb creates;
  - account1, server1, id1 for new account(POP3, IMAP, News, ...)
  - account2, server2 for Local Folders(no identity, type=none)
  - Hidden account for Unified Folder(typr=none, hidden)
    is not autiomatically created until UniFied Folder view is used.

Identity is determined from message header.
> http://mxr.mozilla.org/comm-central/source/mail/base/content/mailWindowOverlay.js#1623
> 
> 1622       else {
> 1623         let identity = getIdentityForHeader(msgHdr);

So, following is perhaps applied. (for Global Inbox support)
     (Call "N-th identity of accountM"         "id_M_N")
     (Call "N-th identity of default account"  "id_0_N")
  Mail in Mbox of account2 :                         used identity
  (Local Folders has no associated identity) :
   X-Account-Key: doesn't exist                   => id_0_1
   X-Account-Key: account1 (other account)        => id_1_1 
   X-Account-Key: account2 (myself==no identity)  => id_0_1
   X-Account-Key: accountX (other account)        => id_X_1
   X-Account-Key: accountY (hidden account)       => id_Y_1
   X-Account-Key: accountZ (non existent account) => id_0_1
   (in any case, if identity is not defined, id_0_1 or id_1_1 is used)
Above is aperhaps applied to other accounts, because any POP3 account can be defined as Global Inbox owner.
  Mail in Mbox of account1 :                          used identity
    X-Account-Key: doesn't exist                   => id_1_1 (myself)
    X-Account-Key: account1 (my self)              => id_1_1
    X-Account-Key: account2 (Local Folders,no idX) => id_1_1 or d_0_1 
    X-Account-Key: accountX (other account)        => id_X_1
    X-Account-Key: accountY (hidden account)       => id_Y_1
    X-Account-Key: accountZ (non existent account) => id_1_1 or d_0_1
   (in any case, if identity is not defined, id_0_1 or id_1_1 is used)

Did you see this kind of phenomenon?

If mail has "X-Identity-Key: idX" header, Tb may read archive setting of the identity. If so, second or more identities may be relivant.

Does "X-Identity-Key: idX" header exist in your mails?
Sorry, getIdentityForHeader looked Delivered-to: too, and searched all identities for mail-addr in Delivered-to:.
> http://mxr.mozilla.org/comm-central/source/mail/base/content/mailCommands.js#53
> 53 function getIdentityForHeader(hdr, type)
So, "use of second or more identity's archive setting" can occur if Delivered-To: is used even when no X-Identty-Key: header.

Is Delivered-To: header used by your server?
A possible change.
> http://mxr.mozilla.org/comm-central/source/mail/base/content/mailWindowOverlay.js#1622
> 1622       else {
> 1623         let identity = getIdentityForHeader(msgHdr);
>
>+1623+x       var GetPrimaryIdentity=function(identity)
>+             {
>+               Find accounN for identity via AccountManager.accounts;
>+               Find primary(first) identity of the accountN;
>+               return the primary(first) identity;
>+             }
>+             identity = GetPrimaryIdentity(identity);
>
> 1624         archiveFolderUri = identity.archiveFolder;
> 1625         archiveGranularity = identity.archiveGranularity;
> 1626         archiveKeepFolderStructure = identity.archiveKeepFolderStructure;
> 1627       }
Status: UNCONFIRMED → NEW
Component: Untriaged → Backend
Ever confirmed: true
Product: Thunderbird → MailNews Core
Summary: Archive set for year-month fails, archives to year only for some messages → Archive set for year-month fails, archives to year only for some messages (mismatch between "Archive setting UI" and "archiveMessages: + getIdentityForHeader")
Summary: Archive set for year-month fails, archives to year only for some messages (mismatch between "Archive setting UI" and "archiveMessages: + getIdentityForHeader") → Archive set for year-month fails, archives to year only for some messages, because archive setting of non-primary identity is used when Delivered-to: header exists (mismatch between "Archive setting UI" and "archiveMessages: + getIdentityForHeader")
OS: Linux → All
Hardware: x86_64 → All
Whiteboard: [workaround: keep same archive setting among all identites]
Following is observed.
(0) idX: Archives=FolderX, idY: Archives=FolderY, idZ : Archives=FolderZ
(1) Mails in Mbox of dummy POP3 account.
      no X-Account-Key:, no X-Identity-Key:,
      From: Unknown mail addr, To: Unknown mail addr, no CC:
    mail-1 : Delivered-To: idX, yyyy=2011, Offset=1000(MsgKey=1000)
    mail-2 : Delivered-To: idY, yyyy=2012, Offset=2000(MsgKey=2000)
    mail-3 : Delivered-To: idZ, yyyy=2013, Offset=3000(MsgKey=3000)
(2) Archive each mail
    mail-1 => FolderX, mail-2 => FolderY, mail-3 => FolderXZ
    Granuality : setting of each identity of Delivered-To: is used
    Year       : each mail's Date: header is used
(3) Select All mails, Archive => All goes to FolderZ
    mail-1 => FolderZ, mail-2 => FolderZ, mail-3 => FolderX
    Granuality : setting of mail-3/idZ is used
    Year       : each mail's Date: header is used
(4) Copy mails to Mbox in descending order
    mail-3 : Delivered-To: idZ, yyyy=2013, Offset=1000(MsgKey=1000)
    mail-2 : Delivered-To: idY, yyyy=2012, Offset=2000(MsgKey=2000)
    mail-1 : Delivered-To: idX, yyyy=2011, Offset=3000(MsgKey=3000)
(5) Select All mails, Archive => All goes to FolderX
    mail-1 => FolderX, mail-2 => FolderX mail-3 => FolderX
    Granuality : setting of mail-1/idX is used
    Year       : each mail's Date: header is used

(3) and (5) is;
When multiple mails are selected(may be "Select All"), identity is selected from mail of highest MsgKey and archive option is obtained, and it's applied to all mails.
This is similar to bug 531829 on Date:, but that bug is apparently already reoslved and doesn't occur.

> http://mxr.mozilla.org/comm-central/source/mail/base/content/mailCommands.js#53
> 53 function getIdentityForHeader(hdr, type)
Defines local function of findDeliveredToIdentityEmail()
> 55   function findDeliveredToIdentityEmail() {
At 90, getIdentityForHeader calls local findDeliveredToIdentityEmail().
> 88   else
> 89     hintForIdentity = hdr.recipients + "," + hdr.ccList + "," +
> 90                       findDeliveredToIdentityEmail();
Local findDeliveredToIdentityEmail() refers to currentHeaderData[key] (key=="delivered-to").
Because no parameter is passed to the local findDeliveredToIdentityEmail(), currentHeaderData object is variable of outer environment.

Is this currentHeaderData object holds header data of each message upon each call of the Local findDeliveredToIdentityEmail() for each selected message?
Correction of comment #26.
(1) Mails in "Mbox" folder of dummy POP3 account.
      no X-Account-Key:, no X-Identity-Key:,
      From: Unknown mail addr, To: Unknown mail addr, no CC:
    mail-1 : Delivered-To: idX, yyyy/mm of Date: = 2001/01
    mail-2 : Delivered-To: idY, yyyy/mm of Date: = 2002/02
    mail-3 : Delivered-To: idZ, yyyy/mm of Date: = 2003/03
    Granuarity :
      idX = yyyy,         No folder structure keeping
      idY = yyyy/yyyy-mm, No folder structure keeping
      idX = yyyy/yyyy-mm, Keep folder structure
(2) Archive each mail
    mail-1 => FolderX, mail-2 => FolderY, mail-3 => FolderXZ
    Granuality : setting of each identity of Delivered-To: is used
(3) When multiple mails are selected
(3-1) Select mail-1, then Select All, Archive of context menu
      => All goes to FolderX, Granuality of idX is used.
    mail-1 => FolderX/2001
    mail-2 => FolderX/2002
    mail-3 => FolderX/2003
(3-2) Select mail-2, then Select All, Archive of context menu
      => All goes to FolderY, Granuality of idY is used.
    mail-1 => FolderY/2001/2001-01
    mail-2 => FolderY/2002/2002-02
    mail-3 => FolderY/2003/2003-03
(3-3) Select mail-3, then Select All, Archive of context menu
      => All goes to FolderZ, Granuality of idZ is used.
    mail-1 => FolderZ/2001/2001-01/Mbox
    mail-2 => FolderZ/2002/2002-02/Mbox
    mail-3 => FolderZ/2003/2003-03/Mbox

i.e.
Phenomenon was;
(A) Identity from Delivered-To: is always get from currently selected
    mail, even when multiple mail selection at thread pane.
(B) So, if identity for Archive is based on Delivered-To:
    (To:/CC: is not defined as identity in Tb = usually sent as BCC:),
    Archives setting for Delivered-To: of the currently selected mail
    is wrongly used.

(Problem-I)
"Gettting identity from Delivered-To: of currently selected mail" is perhaps needed for Reply/Reply All etc., but as for "Archive with multiple mails selected" case, it should be "Gttting identity from Delivered-To: of currently processed mail".

(Problem-II)
Even though "Archive setting" is "per identity setting" in UI currently(not removed yet from panel for non-primary identity's Copies&Folders Tab), and even though "per identity Archive option" is possible, and even if "per identity Archive option" may be convenient for some users, initial concept of "Archive" was "per account" feature.
I believe one of next is neded.
(1) Change "Archive" to "per Account feature" at any place of back end, by always using primary identity.
(2) If "Archive is per identity feature" will be kept in some places, provide easy/non-hidden way to apply "primary identity's Archive options(and other Copies&Folders settings)" to all other identities.
Summary: Archive set for year-month fails, archives to year only for some messages, because archive setting of non-primary identity is used when Delivered-to: header exists (mismatch between "Archive setting UI" and "archiveMessages: + getIdentityForHeader") → Archive set for year-month fails, archives to year only for some messages, because archive setting of non-primary identity is used when Delivered-to: header exists (mismatch between "Archive setting UI/prefs" and "archiveMessages: + getIdentityForHeader")
Correction of archive setting of each identity.
    Archive folder, Granuarity :
      idX : Archive=FolderX, yyyy,         No folder structure keeping
      idY : Archive=FolderY, yyyy/yyyy-mm, No folder structure keeping
      idZ : Archive=FolderZ, yyyy/yyyy-mm, Keep folder structure
3 test mails has Delivered-To: = a1@a.a.a, a2@a.a.a, or a3@a.a.a.
Before test with the mails, add 3 dummy identities with above mail address, and change Archive setting appropriately for ease of your test.
Attachment #718770 - Attachment is obsolete: true
(In reply to Daniel Höpfl from comment #22)
> I found a way to reproduce it (it depends on having multiple identities):
>(snip)
> - Set up a second identity, e-mail-address: other@example.com

"Delivered-To:" was not always relevant to phenomenon.

As you saw, current "Archive" was "per identity feature" istead of "per account feature", then Archive is affected by multiple identities.
  3 mails, with no X-Account-Key:, no CC:/BCC:(and no X-Identity-Key:)
  mail-11 = To: idX, idY, idZ => Archive setting of idX is used
  mail-12 = To: idY, idZ, idX => Archive setting of idY is used
  mail-13 = To: idZ, idX, idY => Archive setting of idZ is used
  (In this case, "currently selected or not" doesn't affect on it)
i.e.
"Which identity's Archive setting is used" depends on "order of identity's mail address in message header of a mail".

If Archive settings is diffferent among identities, as you saw, phenomenon of "different archive action on different mails in same account" occurs.
This can occur even when X-Account-Key: exists, because identity check is done with "identity list of account" instead of with "primary identity of the account".
Summary: Archive set for year-month fails, archives to year only for some messages, because archive setting of non-primary identity is used when Delivered-to: header exists (mismatch between "Archive setting UI/prefs" and "archiveMessages: + getIdentityForHeader") → Archive set for year-month fails, archives to year only for some messages (archive setting of non-primary identity is used with multi-identities or Delivered-to:(mismatch among Archive UI, "archiveMessages: + getIdentityForHeader" , and use's expectation)
Summary: Archive set for year-month fails, archives to year only for some messages (archive setting of non-primary identity is used with multi-identities or Delivered-to:(mismatch among Archive UI, "archiveMessages: + getIdentityForHeader" , and use's expectation) → Archive set for year-month fails, archives to year only for some messages (archive setting of non-primary identity is used with multi-identities or Delivered-to:(mismatch among Archive UI, "archiveMessages:+getIdentityForHeader" , and user's expectation)
(In reply to WADA from comment #24)

> Is Delivered-To: header used by your server?

Yes. It contains an mail address that is different from all identities. (user@fqdn.of.mailserver)

There is also a X-Original-To:, same address as Delivered-To:.
(In reply to Daniel Höpfl from comment #31)
> > Is Delivered-To: header used by your server?
> Yes. It contains an mail address that is different from all identities.
> (user@fqdn.of.mailserver)
> There is also a X-Original-To:, same address as Delivered-To:.

As seen in source of function getIdentityForHeader, X-Account-Key: is relevant to problem. And, as seen in next code, mail address in To:, CC: is looked before Delivered-To:.
> 89     hintForIdentity = hdr.recipients + "," + hdr.ccList + "," +
> 90                       findDeliveredToIdentityEmail();
And, because X-Account-Key: is used for identity selection, "by which account identity is owned" is relevant. And, if Mbox of Local Folders, identity of "Default account" is used, because "Local Folders" doesn't have associated identity.

Can you show us relevant message headers, identity definitions, and mail box owner account info(owns which identity)?
(If consistency among mail addresses is kept, actual mail address is not required. Replace mail address please, because private data.)
(In reply to WADA from comment #32)

> Can you show us relevant message headers, identity definitions, and mail box
> owner account info(owns which identity)?

From the notification about your comment:

X-Account-Key: account1
X-UIDL: 0002076449550972
X-Mozilla-Status: 0001
X-Mozilla-Status2: 00000000
X-Mozilla-Keys:                                                                                 
Return-Path: <bugzilla-daemon@mozilla.org>
X-Original-To: user@fqdn.mailserver.org
Delivered-To: user@fqdn.mailserver.org
Received: by fqdn.mailserver.org (Postfix, from userid 1234)
	id 9971375C001; Mon, 11 Mar 2013 11:15:31 +0100 (CET)
Received: from smtp.mozilla.org (mx2.corp.phx1.mozilla.com [63.245.216.70])
	by fqdn.mailserver.org (Postfix) with ESMTP id CDBC41E48082
	for <bugzilla@hoepfl.de>; Mon, 11 Mar 2013 11:15:30 +0100 (CET)
To: bugzilla@hoepfl.de



Settings:

user_pref("CorrectIdentity.selectedAccount", "server1");
user_pref("CorrectIdentity.selectedIdentity", "id1");
user_pref("mail.account.account1.identities", "id1,id2,id3,id4,id7,id6,id8,id9,id5,id10,id11");
user_pref("mail.account.account1.server", "server1");
user_pref("mail.accountmanager.accounts", "account1,account2,account4,account3");
user_pref("mail.accountmanager.defaultaccount", "account1");
user_pref("mail.identity.id1.archive_folder", "mailbox://xxxxxxxxx/Archive");
user_pref("mail.identity.id1.archive_granularity", 2);
user_pref("mail.identity.id1.archive_keep_folder_structure", false);
user_pref("mail.identity.id1.archives_folder_picker_mode", "0");
user_pref("mail.identity.id2.archive_folder", "mailbox://hoepfl@pop.hoepfl.de/Archives");
user_pref("mail.identity.id2.archive_granularity", 2);
user_pref("mail.identity.id2.archive_keep_folder_structure", false);
user_pref("mail.identity.id2.archives_folder_picker_mode", "0");
user_pref("mail.identity.id2.useremail", "not.bugzilla@fqdn");
user_pref("mail.identity.id2.valid", true);

(To work around, all other identities use the same archive settings, none of them is bugzilla@hoepfl.de)

Would it help if I mailed you my complete prefs.js? (What would I have to replace other than any occurrence of my username/mailserver/enigmail-settings? Are there any passwords in prefs.js?)
What is mail.identity.id1.useremail?
bugzilla@hoepfl.de? (To:)  user@fqdn.mailserver.org? (Delivered-To:)

No other mail address in To:?
No CC: in the mail?
Only one Delivered-To:? (multiple Delivered-To: is possible) 
id3 to id11 is absolutely irrelevant to your problem?

Where was the mail moved by Archive?
(a) mailbox://xxxxxxxxx/Archive for id1?
(b) mailbox://hoepfl@pop.hoepfl.de/Archives for id2?
I guess (a) with single identity only(only id1 is defined), (b) with multiple identities defined, but I can't know it by your comment.

Does phenomenon of "one mail goes to Archives for id1 and another mail goes to Archives for id2" occur by archive operaion(s) on mails in a folder with current setting?
If yes, what is difference of the two mails?

archives_folder_picker_mode=0 is "Archives folder of the account or other account". No confusion in your test due to multiple mails which should go to Archives for id1 or Archives for id2 or Archives for id3 to id11?
(I usually select via Others:, and use different/unique folder name to reduce my confusion in my test...)
 
Because account1 has identities, account1 is never Local Folders.
Is "Archive at Mbox of Local Folders" involved in your case?

> user_pref("CorrectIdentity.selectedAccount", "server1");
> user_pref("CorrectIdentity.selectedIdentity", "id1");

CorrectIdentity may affect on identity selection by Tb's archive, because the addon may touch identity selecion code.
Is influence by CorrectIdentity surely ruled out in your case?
See bug #872291
FYI.
If Global Inbox is used or if mails downloaded via POP3 account are moved to other account of Tb, multiple X-Accunt-Key: can exist in a mail folder.
If you do Archive with selecting multiple mails at Thread pane of such mail folder, following phenomenon can be observed.
  All mail is moved to archive folder for an identity of X-Account-Key:
  (usually first identity) of a selected mail(perhaps currently selected
   mail).
  i.e. X-Account-Key: of other mails is ignored by Archive.
Quick check result with X-Accoint-Key: and To:.
(mails)
  type-A : X-Accout-Key: accountX, To: id-1 of account-X(first identity)
  type-B : X-Accout-Key: accountX, To: id-N of account-X
  type-C : X-Accout-Key: accountX, To: id-P(any) of account-Y(!=X)
(Archive folder setting)
  id-1 of account-X (first identity) : Archive folder = Arc_X_1 
  id-N of account-X                  : Archive folder = Arc_X_N
  id-P(any) of account-Y(!=X)        : Archive folder = Arc_Y_P
(select only one mail at thread pane, and do Archive)
  type-A : moved to Arc_X_1
  type-B : moved to Arc_X_N
  type-C : moved to Arc_X_1

i.e.
If only one mail is archived,
  - if To: address is an identity of account set in in X-Account-Key:,
    archive folder for the identity is used as expected.
  - if To: address is NOT identity of account set in in X-Account-Key:,
    archive folder for primary(first) identity of account set in
    X-Account-Key: is used as expected.
If X-Account-Key: header exists and accountX set in X-Account-Key: is defined in Tb, identity selection looks only identities defined for the accountX, regardless of owner of mail folder(same as known symptom in From: address selection in Reply).

Cause of inconsistent behavior in Archive of Tb is perhaps:
  When multiple mails are selected at thread pane upon Archive,
  accountN and associated identity of a selected mail
  (perhaps currently selected mail in the view)
  is used for all other selected mails.
If so, solution of "inconsistent behaviou" is perhaps;
   Select "account and associated identities" for each message.
Blocks: 1162932
Severity: normal → S3

My Thunderbird keeps creating a yearly folder even though I set it to use a single archive folder. This started happening a few months ago, I did not change anything about my IMAP setting which is the weirdest part.

I saw some people reported this on the support forum as well: https://support.cdn.mozilla.net/gl/questions/1384240#answer-1533683

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: