Can't delete a folder if Trash already contains a folder of the same name

Bug #214366 reported by Douglas Royds
24
This bug affects 4 people
Affects Status Importance Assigned to Milestone
Mozilla Thunderbird
Fix Released
Medium
thunderbird (Ubuntu)
Triaged
Low
Unassigned

Bug Description

Binary package hint: mozilla-thunderbird

1. Create a new folder, eg. "Temp"
2. Delete it, OK
3. Create the same folder again
4. Delete it, OK

I expect it to be moved to my Trash folder, perhaps with a suffix appended (it being the second instance of that folder in the trash).

Thunderbird popped up an error message. On an imap host:
   The current command did not succeed. The mail server responded: Mailbox already exists.
In the local folders:
   A folder with that name already exists. Please enter a different name (!)

Workarounds:
1. Empty the trash
2. Rename the folder before deletion
3. Rename the folder already in the trash
4. Delete (permanently) the folder that is already in the trash

Ubuntu 7.10 Gutsy
thunderbird 2.0.0.12+nobinonly-0ubuntu0.7.10.0

Revision history for this message
In , Sspitzer (sspitzer) wrote :

over to naving

Revision history for this message
In , Sheelar (sheelar) wrote :

using build2001-01-29-04 I see the following for pop
delete drafts folder
exit app
log into the account.
You will see that drafts is created again
delete this folder again
In trash you still see the first drafts folder deleted and not the second one.
The second one just goes away. Which is the opposite of what the reporter is
seeing.

confirming the bug.

Revision history for this message
In , Naving (naving) wrote :

We can throw an alert and inform the user that the folder will be created with
a new name. For example if there is a folder "A" under Trash and if the user
tries to delete "A" somewhere else. Then this folder will be created with a new
name "A0". This is what 4x does.

Revision history for this message
In , Sheelar (sheelar) wrote :

I agree. the warning message should also let the user know that the folder will
be renamed if he okays the alert.

Revision history for this message
In , Naving (naving) wrote :

Created an attachment (id=26204)
proposed fix

Revision history for this message
In , Naving (naving) wrote :

Just made it like 4x. cc bienvenu, sspitzer for review.

Revision history for this message
In , Naving (naving) wrote :

Sorry for marking it fixed !

Revision history for this message
In , Sspitzer (sspitzer) wrote :

a couple comments:

1) is your while loop correct?

It looks like it will generate foldernames like this:

foo1,foo12,foo123,foo1234

seems like you'd want:

foo-1,foo-2,foo-3

2) I'm not sure, but should you be using strcasecmp() instead of strcmp()?

3) ToNewCString() to get oldName and newName are wrong. what if the folder
names are in japanese? you should not be using the nsTextFormatter, you should
be using nsIStringBundle's FormatStringFromName() (or FormatStringFromID()?)

I think you can write this code without using Free() by using nsXPIDLString and
FormatStringFrom*()

Revision history for this message
In , Naving (naving) wrote :

>>foo1,foo12,foo123,foo1234

I would leave it this way because it is going to Trash, anyway and 4x also
does this way

>>I think you can write this code without using Free() by using nsXPIDLString
>>and
>>FormatStringFrom*()
FormatStringFromID() finally uses nsTextFormatter::smprintf

If I don't use const char *oldName *newName only the 1st character is
displayed. Any ideas?

Revision history for this message
In , Naving (naving) wrote :

I think UTF8String() will take care of Japanese characters.

Revision history for this message
In , Naving (naving) wrote :

cc nhotta. nhotta do you know whether UTF8String() will take care of
japanense characters.

Revision history for this message
In , Naving (naving) wrote :

I have this fix in my tree for a long time now. Can somebody tell me
what should I do for the Japenese characters ?

Revision history for this message
In , Naving (naving) wrote :

Seth, I was talking to you about this bug, regarding japenese characters.

Revision history for this message
In , Naving (naving) wrote :

*** Bug 91711 has been marked as a duplicate of this bug. ***

Revision history for this message
In , Spam-minneboken (spam-minneboken) wrote :

similar: bug 46365

Revision history for this message
In , Meehansqa (meehansqa) wrote :

changing QA contact from Sheela to Gregg

Revision history for this message
In , Bugzilla-mozilla-vitters (bugzilla-mozilla-vitters) wrote :

*** Bug 161876 has been marked as a duplicate of this bug. ***

Revision history for this message
In , Cohntm (cohntm) wrote :

*** Bug 125891 has been marked as a duplicate of this bug. ***

Revision history for this message
In , Meehansqa (meehansqa) wrote :

Reporter, I'm unable to reproduce in current build - I'm unable to delete ANY
system folders. Are you still seeing this problem?

Revision history for this message
In , AleksanderAdamowski (aadamowski) wrote :

Currently, when we delete a folder while another with the same name exists in
trash, the opertion fails and there's a confusing error messagebox: "A folder
with that name already exists. Please enter a different name".

This is so confusing - the user isn't naming anything at the moment, how can he
enter a different name?

My friend had this problem (and problem described in bug 73404) just recently in
1.2 branch nightly build when trying to manage some imported Outlook folders
(changing the mail reader from Outlook to Mozilla). Can we please check this
patch in?

Revision history for this message
In , Bienvenu (bienvenu) wrote :

this patch needs work before it can get checked in, as Seth pointed out. Since
it was written, the string classes have changed quite a bit, so I think a lot of
the copying is unneeded, and you can use the Equals method to compare
nsXPIDLStrings, so there's no need for the auto strings. To format messages with
unicode strings, you just use %S instead of %s in the format string like so:
+4023=The Trash already contained a folder named %S. The folder which you just
deleted can be found in the Trash under the new name %S.

Also,
               newFolderNameUnderTrash.AppendInt(i,10);
should just be newFolderNameUnderTrash.AppendInt(i); since 10 is the default.

Revision history for this message
In , Sspitzer (sspitzer) wrote :

mass re-assign.

Revision history for this message
In , Mcow (mcow) wrote :

*** Bug 268435 has been marked as a duplicate of this bug. ***

Revision history for this message
In , Mcow (mcow) wrote :

*** Bug 268436 has been marked as a duplicate of this bug. ***

Revision history for this message
In , Mcow (mcow) wrote :

*** Bug 268946 has been marked as a duplicate of this bug. ***

Revision history for this message
In , M-wada (m-wada) wrote :

*** Bug 208114 has been marked as a duplicate of this bug. ***

Revision history for this message
In , M-wada (m-wada) wrote :

Bug 71348 is for same symptom on IMAP.

Revision history for this message
In , Mcow (mcow) wrote :

*** Bug 250390 has been marked as a duplicate of this bug. ***

Revision history for this message
In , M-wada (m-wada) wrote :

*** Bug 71348 has been marked as a duplicate of this bug. ***

Revision history for this message
In , M-wada (m-wada) wrote :

*** Bug 274829 has been marked as a duplicate of this bug. ***

Revision history for this message
In , Peter-qaya (peter-qaya) wrote :

I am confused by this bug. It seems that the original problem has been fixed,
but in an unsatisfactory way which leads to the undesirable side-effect noted in
Comment 20 and in each of the bugs recently marked as duplicates of this one. It
seems that the current bug is not the original one, but a bug in the first bug
fix. If this doesn't count as a new bug, at least the situation should be
clarified - and the reporters of the bugs duplicated to this one should be
encouraged to vote for this one.

Revision history for this message
In , Elmar-ludwig (elmar-ludwig) wrote :

*** Bug 277959 has been marked as a duplicate of this bug. ***

Revision history for this message
In , Elmar-ludwig (elmar-ludwig) wrote :

*** Bug 314406 has been marked as a duplicate of this bug. ***

Revision history for this message
In , Elmar-ludwig (elmar-ludwig) wrote :

As noted in comment 31, this bug has morphed over time from deleting system
folders to normal folders, though I don't doubt that system folders would show
the same behaviour today if it were possible to delete them.

Since a lot of other bugs have already been duped against this bug, we might as
well morph this bug completely...

-> no longer dataloss, updating summary + whiteboard, etc.

Revision history for this message
In , Mkmelin+mozilla (mkmelin+mozilla) wrote :

*** Bug 281236 has been marked as a duplicate of this bug. ***

Revision history for this message
In , Mcow (mcow) wrote :

*** Bug 357702 has been marked as a duplicate of this bug. ***

Revision history for this message
In , Mkmelin+mozilla (mkmelin+mozilla) wrote :

*** Bug 397991 has been marked as a duplicate of this bug. ***

Revision history for this message
In , Erich (eiseli) wrote :

*** Bug 46365 has been marked as a duplicate of this bug. ***

Revision history for this message
In , Philringnalda (philringnalda) wrote :

*** Bug 405493 has been marked as a duplicate of this bug. ***

Revision history for this message
In , Mozilla-bugs-2010-04 (mozilla-bugs-2010-04) wrote :

As comment #34 points out, this bug is no longer the same bug as the description states. This bug should be closed and a new bug opened that described the current problem (cannot delete folder and misleading error message). One of the many dupes will do.

Revision history for this message
Douglas Royds (douglas-royds) wrote :

Binary package hint: mozilla-thunderbird

1. Create a new folder, eg. "Temp"
2. Delete it, OK
3. Create the same folder again
4. Delete it, OK

I expect it to be moved to my Trash folder, perhaps with a suffix appended (it being the second instance of that folder in the trash).

Thunderbird popped up an error message. On an imap host:
   The current command did not succeed. The mail server responded: Mailbox already exists.
In the local folders:
   A folder with that name already exists. Please enter a different name (!)

Workarounds:
1. Empty the trash
2. Rename the folder before deletion
3. Rename the folder already in the trash
4. Delete (permanently) the folder that is already in the trash

Ubuntu 7.10 Gutsy
thunderbird 2.0.0.12+nobinonly-0ubuntu0.7.10.0

Revision history for this message
In , Mkmelin+mozilla (mkmelin+mozilla) wrote :

*** Bug 431314 has been marked as a duplicate of this bug. ***

Revision history for this message
In , Mkmelin+mozilla (mkmelin+mozilla) wrote :

*** Bug 448101 has been marked as a duplicate of this bug. ***

Revision history for this message
In , Philringnalda (philringnalda) wrote :

*** Bug 458123 has been marked as a duplicate of this bug. ***

Revision history for this message
Daniel T Chen (crimsun) wrote :

Is this symptom still reproducible in 8.10 or 9.04?

Changed in mozilla-thunderbird:
status: New → Incomplete
Revision history for this message
Pedro Villavicencio (pedro) wrote :

We are closing this bug report because it lacks the information we need to investigate the problem, as described in the previous comments. Please reopen it if you can give us the missing information, and don't hesitate to submit bug reports in the future. To reopen the bug report you can click on the current status, under the Status column, and change the Status back to New. Thanks again!.

Changed in mozilla-thunderbird:
status: Incomplete → Invalid
Revision history for this message
Michael Rooney (mrooney) wrote :

I can confirm this in Intrepid with thunderbird 2.0.0.19+nobinonly-0ubuntu0.8.10.1

Changed in mozilla-thunderbird:
importance: Undecided → Low
status: Invalid → Confirmed
Revision history for this message
John Vivirito (gnomefreak) wrote :

Is this only for IMAP or for any server type? I will test with tb3 sometime this weekend to see if i get same results. I'm un,arking as confirmed since first reporter has no more info for us, if im able to reproduce in tb2 or 3 i will change it as needed.
Michael can you please start with new profile and test it also without any addons if you can.

Changed in mozilla-thunderbird:
status: Confirmed → Incomplete
Revision history for this message
Michael Rooney (mrooney) wrote : Re: [Bug 214366] Re: Can't delete a folder if Trash already contains a folder of the same name

Hi John, this was tested with a new IMAP profile with no add-ons.

Revision history for this message
John Vivirito (gnomefreak) wrote : Re: [Bug 214366] Re: Can't delete a folder if Trash already contains a folder of the same name

On 01/31/2009 03:24 PM, Michael Rooney wrote:
> Hi John, this was tested with a new IMAP profile with no add-ons.
>

I was able to reproduce this with POP3 on tb2 and tb3. Can someone
please look upstream for this bug. There should be one already. I will
look when i get time, work is keeping me busy.

 status confirmed

--
Sincerely Yours,
    John Vivirito

https://launchpad.net/~gnomefreak
https://wiki.ubuntu.com/JohnVivirito
Linux User# 414246

"How can i get lost, if i have no where to go"
    -- Metallica from Unforgiven III

Changed in mozilla-thunderbird:
status: Incomplete → Confirmed
Revision history for this message
In , John Vivirito (gnomefreak) wrote :

This is still an issue in thunderbird 2.0.0.19 and 3.0~b2. here is the bug from Ubuntu for any info that might be needed.
https://bugs.launchpad.net/ubuntu/+source/mozilla-thunderbird/+bug/214366

This happens on seamonkey as well as Tunderbird

Revision history for this message
Alexander Sack (asac) wrote :

as its still an issue on thunderbird-3.0 we should triage it upstream

Changed in mozilla-thunderbird:
status: Confirmed → Triaged
Changed in thunderbird:
status: New → Invalid
Revision history for this message
Alexander Sack (asac) wrote :

forwarded upstream: https://bugzilla.mozilla.org/show_bug.cgi?id=477602

subscribe and continue discussion there. Thanks!

Changed in thunderbird:
importance: Undecided → Unknown
status: Invalid → Unknown
Revision history for this message
John Vivirito (gnomefreak) wrote :

i found https://bugzilla.mozilla.org/show_bug.cgi?id=66763 already and marked as remote bug.
I am unable to mark dups in Mozilla tracker

Changed in thunderbird:
status: Unknown → Confirmed
Revision history for this message
In , Sgautherie-bz (sgautherie-bz) wrote :

*** Bug 477602 has been marked as a duplicate of this bug. ***

Revision history for this message
In , Philringnalda (philringnalda) wrote :

*** Bug 520145 has been marked as a duplicate of this bug. ***

Revision history for this message
In , Meridianox (meridianox) wrote :

Thunderbird 3.0
Can't move folder to "Deleted" if a folder with the same name already exists.

 Move "test" to "Deleted"
 Create new folder "test"
 Move second "test" to "Deleted"
 Error: Folder already exists

Ideally, the second "test" folder should be moved to "deleted" as "test(2)" or something.

Revision history for this message
In , Philringnalda (philringnalda) wrote :

*** Bug 537561 has been marked as a duplicate of this bug. ***

Revision history for this message
In , Ulysse (ulysse) wrote :

*** Bug 550836 has been marked as a duplicate of this bug. ***

Revision history for this message
In , Inscription (inscription) wrote :

(In reply to comment #48)
> Thunderbird 3.0
> Can't move folder to "Deleted" if a folder with the same name already exists.
>
> Move "test" to "Deleted"
> Create new folder "test"
> Move second "test" to "Deleted"
> Error: Folder already exists
>
> Ideally, the second "test" folder should be moved to "deleted" as "test(2)" or
> something.

This is not an issue. It should not have to change the name to be able to delete it.

Revision history for this message
In , Denis Barmenkov (denis-barmenkov) wrote :

> This is not an issue. It should not have to change the name to be able to
> delete it.

Strange requirement: make additional processing on item which user want to trash.

This is an issue: user dont want to worry about what already placed in Trash - user want to delete this folder. Delete this folder. Just now.

I mean this TB's behaviour is a sample of stupidity: program don't let user make their work because of 'violation' some sort of 'logical structure'.
As user mark this as trash do something with folder name for moving it to trash -- add unique postfix, add random number etc.

Revision history for this message
In , Duncan-clee (duncan-clee) wrote :

I have noticed this too, just the other day, in fact. Renaming the folder (a subfolder of "Local Folders\Personal Folders" before deleting it is a workaround.

Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.1.9) Gecko/20100317 Thunderbird/3.0.4

Revision history for this message
In , Ulysse (ulysse) wrote :

*** Bug 581780 has been marked as a duplicate of this bug. ***

Changed in thunderbird:
importance: Unknown → Medium
Revision history for this message
In , Ulysse (ulysse) wrote :

*** Bug 598053 has been marked as a duplicate of this bug. ***

Revision history for this message
In , Ditiseennamaakadres (ditiseennamaakadres) wrote :

Fout: uncaught exception: [Exception... "Component returned failure code: 0x80550013 [nsIMsgFolder.deleteSubFolders]" nsresult: "0x80550013 (<unknown>)" location: "JS frame :: chrome://messenger/content/folderPane.js :: ftc_delete :: line 2201" data: no]

Revision history for this message
In , Ulysse (ulysse) wrote :

*** Bug 653696 has been marked as a duplicate of this bug. ***

Revision history for this message
In , Acelists (acelists) wrote :

*** Bug 708625 has been marked as a duplicate of this bug. ***

Revision history for this message
In , Acelists (acelists) wrote :

Would comment 52 be an acceptable solution for everyone?
It seems the old patch is attempting to do that.
I could try to pick it up.

Revision history for this message
In , Dbienvenu (dbienvenu) wrote :

(In reply to :aceman from comment #59)
> Would comment 52 be an acceptable solution for everyone?
> It seems the old patch is attempting to do that.
> I could try to pick it up.

Yes, that's fine, similar to what windows file system explorer does. That would be great if you could fix this!

Revision history for this message
In , Acelists (acelists) wrote :

It seems the file has changed too much. I have no idea where to put this code. The flow is too different now.

Revision history for this message
In , M-wada (m-wada) wrote :

*** Bug 712912 has been marked as a duplicate of this bug. ***

Revision history for this message
In , Acelists (acelists) wrote :

Created attachment 609152
proof of concept patch

I managed to strip the patch down and update it for the current architecture.
I need feedback from David Bienvenu if this is a good direction and reaction to the points below.

What it does:
- it does work to fix the problem as reported.
- if the folder 'Folder' is already existing in Trash, this will try to move it as 'Folder2', 'Folder3' (to fix comment 8).

What it is missing for now:
- if CopyFolderLocal is used not only for moving to trash then this renaming functionality must be done only if isChildOfTrash is true.
- it doesn't have the alert dialog informing the user the folder was renamed.

Problems:
- for some reason when a folder is deleted and then a new folder with the same name is created in its place, then it can't be deleted, without any error. It that is some other known bug or a bug in this code? After TB restart that same folder can be deleted fine.

Revision history for this message
In , Mkmelin+mozilla (mkmelin+mozilla) wrote :

> - it doesn't have the alert dialog informing the user the folder was renamed.

That doesn't sound to me like something we'd want.

I'd too (like comment 8) prefer a folder-N, not folderN naming scheme.

Revision history for this message
In , Acelists (acelists) wrote :

(In reply to Magnus Melin from comment #64)
> > - it doesn't have the alert dialog informing the user the folder was renamed.
> That doesn't sound to me like something we'd want.
It would be easier without it, but let's ask bwinton too.

> I'd too (like comment 8) prefer a folder-N, not folderN naming scheme.

The dash in comment 8 can be probably added trivially if we decide on it. The main point from comment 8 is that the original patch tried folder names like this: Folder0, Folder01, Folder012, etc... My patch tries Folder2, Folder3, Folder4, etc...

Revision history for this message
In , UlfZibis (ulf-zibis) wrote :

(In reply to :aceman from comment #65)
> (In reply to Magnus Melin from comment #64)
> > I'd too (like comment 8) prefer a folder-N, not folderN naming scheme.
>
> The dash in comment 8 can be probably added trivially if we decide on it.
> The main point from comment 8 is that the original patch tried folder names
> like this: Folder0, Folder01, Folder012, etc... My patch tries Folder2,
> Folder3, Folder4, etc...

I would prefer a space before the number:
My Folder 1
Or better (like in Windows Explorer):
My Folder (1)
Copy(1) of My Folder
Duplicate(1) of My Folder

Revision history for this message
In , Acelists (acelists) wrote :

For those interested, Outlook 2007 renames the folder to 'Folder1' (no space) if 'Folder' is already existing. At least in the SK language version.

Revision history for this message
In , UlfZibis (ulf-zibis) wrote :

(In reply to :aceman from comment #67)
> For those interested, Outlook 2007 renames the folder to 'Folder1' (no
> space) if 'Folder' is already existing. At least in the SK language version.

I would say: "Bug" in MS's corporate Identity ;-)
Imagine, someone just has Folder1. It would result in Folder11. Do you want this?

Revision history for this message
In , Acelists (acelists) wrote :

Yes, that does really happen :) Delete 'Folder', 'Folder', and 'Folder1'.

I do not want that but I do not care much. I implement whatever the UI guys decide. I just provide options :)

Changed in thunderbird:
status: Confirmed → In Progress
Revision history for this message
In , Dbienvenu (dbienvenu) wrote :

Comment on attachment 609152
proof of concept patch

thx for the patch - I think we really want to do this, but there are issues with the patch.

I don't like the rename of the src folder before the move - that might fail as well, if the name exists in the source folder's directory. I'd prefer to move to the right name initially. And I don't think CopyFolderLocal is the right place for this either - I suspect it wants to be at a higher level, though I'd need to poke around to find the right place.

I'd also like to fix this for imap, which has the same issue.

Revision history for this message
In , Acelists (acelists) wrote :

Thanks David. If you find the right place I can look at it again. Otherwise it is again beyond me.

Revision history for this message
In , Bwinton-a (bwinton-a) wrote :

Comment on attachment 609152
proof of concept patch

This seems like reasonable behaviour to me. I agree with Magnus that I'ld prefer it to end in "-1", "-2", etc… (Sorry, Ulf. :)

(As a side note, OS X, when you delete the same thing twice, names the second "filename.txt" as "filename 14:59:27 .txt" (if you deleted it at 2:59pm ;).)

Later,
Blake.

Revision history for this message
In , UlfZibis (ulf-zibis) wrote :

Maybe you could rename Folder-1 back to Folder, if Folder would be deleted from trash.

Revision history for this message
In , L-bernh5rd-s (l-bernh5rd-s) wrote :

can You please fix it with Your favorite solution !

this issue is already very very old without any progress.
reported Jan-2001

and if there is time it can be udated later ?

: if already exists in trash it could also be moved to
- trash/1/foldername
- trash/2/foldername
so name must not be touch for move.

but no matter how,
please help with Your favorite solution/fix

thanks, Bernhard

Revision history for this message
In , I-vitaly-s (i-vitaly-s) wrote :

It might be better use aliases for folders (and files) in the trash I think.
And add a file with pair of data: alias:real_name.

I meen like this:
In the TB window:
Trash
  Folder
  Folder
  File1
  Folder
  File2
  File1

On the FS:
Trash
  UfatVuHy
  tynkEejRyp
  3jofmamOo
  HajbymFo
  faydfehacs
  RureegojDa

In the additional file:
UfatVuHy:Folder
tynkEejRyp:Folder
3jofmamOo:File1
HajbymFo:Folder
faydfehacs:File2
RureegojDa:File1

Something like this.

Revision history for this message
In , Acelists (acelists) wrote :

The folder name is not a problem. There are technical issues with the implementation so we are waiting on David Bienvenu.

Revision history for this message
In , Vseerror (vseerror) wrote :

(In reply to :aceman from comment #71)
> Thanks David. If you find the right place I can look at it again. Otherwise
> it is again beyond me.

ref comment 70

Revision history for this message
In , Irving (irving) wrote :

I agree with David's remark in comment 70, that we should not rename the folder before copying - we should just copy it directly into the new name. I don't think we need to do anything complicated to deal with duplicate names; appending a number is probably enough.

I don't have any insight into where would be the best place to implement this; if David doesn't know off the top of his head, somebody's going to have to do the hard work of reverse engineering what's already there.

Revision history for this message
In , Archaeopteryx (archaeopteryx) wrote :

*** Bug 967521 has been marked as a duplicate of this bug. ***

Revision history for this message
In , mmxbass (mmxbass) wrote :

The fact that this still hasn't been resolved in the public release after almost 15 years is, quite frankly, disgusting.

These kind of amateurish bugs and the utter inability of anyone to fix them years, or in this case, DECADES later is exactly why nobody takes open-source software seriously.

Rename either folder in some way and be done with it. This does not need to be debated until our eyes and ears bleed. Make a command decision and fix it one way or the other. Delete should just work.

Revision history for this message
In , Acelists (acelists) wrote :

Created attachment 8370331
WIP patch 2

This is an updated version that implements the atomic move of the folder to the final destination, as requested.

The search for a new free folder name is not inside the block where we check if this move is to the Trash folder. That means this automatic renaming works also when copying/moving/dragging to any other folder. That could be a nice feature. Do we want it? Or do we only want this when moving a folder to Trash?

Neil is this still a wrong place to do it and can you propose a better one that David Bienvenu was talking about?

Revision history for this message
In , Josiah-l (josiah-l) wrote :

Comment on attachment 8370331
WIP patch 2

Review of attachment 8370331:
-----------------------------------------------------------------

So this seems like a fine approach to me. I think that we should call each folder "folder(x)" instead of "folder-x", as it more clearly indicates duplicates though. People may already have folders called Name-Subname or the like, so another reason to use parenthesis.

I also definitely think we should expand this to other folders, not just trash.

Revision history for this message
In , UlfZibis (ulf-zibis) wrote :

To avoid future bug reports I would suggest changing the existing Dialogue to:
A folder with name "Child" is already existing in folder "Parent". Do you want to rename it to "Child(2)" or fill it's content into existing folder "Child"?
[Yes] [No] [Cancel]

Revision history for this message
In , Acelists (acelists) wrote :

I wouldn't try to implement merging in this bug (it is much harder). But I think I could make that dialog with Yes/Cancel options meaning Rename/Cancel. For Trash, the rename would happen without question. If UI guys like that :)

Revision history for this message
In , Josiah-l (josiah-l) wrote :

Yeah, for trash moving automatically is fine.

Revision history for this message
In , UlfZibis (ulf-zibis) wrote :

(In reply to :aceman from comment #84)
> I wouldn't try to implement merging in this bug (it is much harder).

What's the problem, moving a (bunch of) message(s) to another folder is already implemented and the suggested dialogue is well known from file managers. I just mean adding, not merging with existing messages.

Revision history for this message
In , Schierlm (schierlm) wrote :

(In reply to Ulf Zibis from comment #86)
> (In reply to :aceman from comment #84)
> > I wouldn't try to implement merging in this bug (it is much harder).
>
> What's the problem, moving a (bunch of) message(s) to another folder is
> already implemented and the suggested dialogue is well known from file
> managers. I just mean adding, not merging with existing messages.

You seem to ignore that folders can (and will) not only contain messages, but subfolders as well (where we will run into the same problem again if the subfolder has the same name as an existing folder in the destination folder). Certainly doable, but way out of scope of this bug in my opinion.

My opinion: Can we please fix this bug quickly (I regularly rename folders just to be able to delete them...) instead of building the ideal bike shed for everybody? Auto-renaming folders when moved elsewhere is fine for me, asking the user about it is fine too, but if we try to add merging functionality (with its own problems) this bug will not be fixed within the next 10 years, I suppose.

Revision history for this message
In , Irving (irving) wrote :

Comment on attachment 8370331
WIP patch 2

Review of attachment 8370331:
-----------------------------------------------------------------

I'm OK with this approach. I'd like to see test cases for both a single folder and a nested folder - for example:

make folder A
move A to trash
make new A
move A to trash
make new A
make new A/B
move A to trash
make sure trash has A and A-1 and A-2 and A-2/B

We don't need to test all those combinations for every message store type, but we should at least test the copyFolder(...aNewName) parameter works once on each store type.

::: mailnews/local/src/nsLocalMailFolder.cpp
@@ +1732,5 @@
> + while (1) {
> + rv = CheckIfFolderExists(newFolderNameUnderTrash, this, NULL);
> + if (rv == NS_MSG_FOLDER_EXISTS) {
> + newFolderNameUnderTrash.Assign(folderName);
> + newFolderNameUnderTrash.AppendLiteral("-"); // do we want this localizable? "<folder>-<SeqNo>"

I don't think this needs to be localizable.

Revision history for this message
In , Acelists (acelists) wrote :

(In reply to :Irving Reid from comment #88)
> I'm OK with this approach. I'd like to see test cases for both a single
> folder and a nested folder - for example:
>
I'll try.

> We don't need to test all those combinations for every message store type,
> but we should at least test the copyFolder(...aNewName) parameter works once
> on each store type.
Store type as in mbox and maildir? Do we actually have tests differentiating the stores?
Can't bug 765926 cover maildir by itself?

> ::: mailnews/local/src/nsLocalMailFolder.cpp
> @@ +1732,5 @@
> > + while (1) {
> > + rv = CheckIfFolderExists(newFolderNameUnderTrash, this, NULL);
> > + if (rv == NS_MSG_FOLDER_EXISTS) {
> > + newFolderNameUnderTrash.Assign(folderName);
> > + newFolderNameUnderTrash.AppendLiteral("-"); // do we want this localizable? "<folder>-<SeqNo>"
>
> I don't think this needs to be localizable.
I think it should be localizable if it is not complicated.

And I agree with comment 87.

Revision history for this message
In , Irving (irving) wrote :

(In reply to :aceman from comment #89)

> > We don't need to test all those combinations for every message store type,
> > but we should at least test the copyFolder(...aNewName) parameter works once
> > on each store type.
> Store type as in mbox and maildir? Do we actually have tests differentiating
> the stores?
> Can't bug 765926 cover maildir by itself?

As far as I know, maildir is mostly untested aside from what's discussed in bug 765926. I don't know whether the long term plan is to run the entire suite twice, once for mbox and once for maildir - if so then yes, we'd be covered. That's a huge waste of testing run time, but might be easier than refactoring our test suite into separate tests for the higher level and the store.

Revision history for this message
In , Neil-httl (neil-httl) wrote :

(In reply to aceman from comment #89)
> (In reply to Irving Reid from comment #88)
> > I don't think this needs to be localizable.
> I think it should be localizable if it is not complicated.
It doesn't need to be localisable (compare uniqueFile from contentAreaUtils.js).

Revision history for this message
In , Neil-httl (neil-httl) wrote :

(In reply to aceman from comment #81)
> Neil is this still a wrong place to do it and can you propose a better one
> that David Bienvenu was talking about?
Well, as I see it there are two options:
1. Make moving a folder automatically rename if the destination already exists, but allow copies to continue to merge the folders. (This was a lifesaver for me when I was moving mail between two accounts and hadn't provided sufficient quota on the destination account first.) Also make this work for IMAP.
2. Propagate the optional destination folder name throughout the mailnews codebase, including the copy service and the imap service. Then you would update the two implementations of DeleteSubFolders to handle the duplicate folder name case.

Revision history for this message
In , Acelists (acelists) wrote :

(In reply to <email address hidden> from comment #92)
> Well, as I see it there are two options:
> 1. Make moving a folder automatically rename if the destination already
> exists, but allow copies to continue to merge the folders. (This was a
> lifesaver for me when I was moving mail between two accounts and hadn't
> provided sufficient quota on the destination account first.) Also make this
> work for IMAP.
In which case does copy merge folders already?

> 2. Propagate the optional destination folder name throughout the mailnews
> codebase, including the copy service and the imap service. Then you would
> update the two implementations of DeleteSubFolders to handle the duplicate
> folder name case.
If I did it in DeleteSubFolders we would probably loose the automatic renaming when a normal copy occurs outside of Trash, which was of interest to users in the previous comments.

Revision history for this message
In , Neil-httl (neil-httl) wrote :

Comment on attachment 8370331
WIP patch 2

>+ PRUint32 i = 2;
>+ nsAutoString newFolderNameUnderTrash(folderName);
>+ while (1) {
>+ rv = CheckIfFolderExists(newFolderNameUnderTrash, this, NULL);
>+ if (rv == NS_MSG_FOLDER_EXISTS) {
>+ newFolderNameUnderTrash.Assign(folderName);
>+ newFolderNameUnderTrash.AppendLiteral("-"); // do we want this localizable? "<folder>-<SeqNo>"
>+ newFolderNameUnderTrash.AppendInt(i);
>+ i++;
>+ } else if (NS_SUCCEEDED(rv)) {
>+ // NS_OK so the tried folder name doesn't exist
>+ break;
>+ } else {
>+ return rv;
>+ }
>+ }
CheckIfFolderExists is overkill if you don't want to alert, use ContainsChildNamed instead. Also, the loop is horribly written, though maybe you might think my version is going too far the other way:
bool containsChild;
for (int32_t i = 2; ContainsChildNamed(destFolderName, &containsChild), containsChild; i++) {
  // compute new folder name
}

Revision history for this message
In , Acelists (acelists) wrote :

(In reply to :aceman from comment #93)
> (In reply to <email address hidden> from comment #92)
> > Well, as I see it there are two options:
> > 1. Make moving a folder automatically rename if the destination already
> > exists, but allow copies to continue to merge the folders. (This was a
> > lifesaver for me when I was moving mail between two accounts and hadn't
> > provided sufficient quota on the destination account first.) Also make this
> > work for IMAP.
> In which case does copy merge folders already?
>
In nsMsgLocalMailFolder::CopyFolder it seems when we are moving folder then it calls CopyFolderLocal (which I am touching). If we are copying then it calls CopyFolderAcrossServer (which I do not touch). So if CopyFolderAcrossServer merges, then all is fine. Is that what you meant?

Revision history for this message
In , Neil-httl (neil-httl) wrote :

(In reply to aceman from comment #95)
> In nsMsgLocalMailFolder::CopyFolder it seems when we are moving folder then
> it calls CopyFolderLocal (which I am touching). If we are copying then it
> calls CopyFolderAcrossServer (which I do not touch). So if
> CopyFolderAcrossServer merges, then all is fine. Is that what you meant?

Technically yes, but that's more by luck than design.

Revision history for this message
In , UlfZibis (ulf-zibis) wrote :

(In reply to Josiah Bruner [:JosiahOne] from comment #82)
> So this seems like a fine approach to me. I think that we should call each
> folder "folder(x)" instead of "folder-x", as it more clearly indicates
> duplicates though. People may already have folders called Name-Subname or
> the like, so another reason to use parenthesis.
+1
The "(x)" pattern is well known from file managers, so why differ here?
There is already another mechanism using the "-x" pattern e.g. in case of lost synchronisation via IMAP where panacea.dat resolves the redirection. Using the same pattern for different reasons could raise ambiguity problems.

> I also definitely think we should expand this to other folders, not just trash.
(In reply to :aceman from comment #84)
> But I think I could make that dialog with Yes/Cancel options meaning
> Rename/Cancel. For Trash, the rename would happen without question.
(In reply to Josiah Bruner [:JosiahOne] from comment #85)
> Yeah, for trash moving automatically is fine.
I think, the decision if a dialogue is shown should not be upon destination folder Trash, but upon the involved action:
Delete action -> automatically rename to Folder(x)
Move/Copy action -> ask user for renaming or cancel
Reasons:
- If user uses Move/Copy instead of the easier Delete he may have some special reason e.g. using the Trash as temporary location, so user should be warned as for any other Move/Copy.
- If we later extend with merge functionality, user is guaranteed to have the merge functionality even for Trash when using the Move/Copy actions.

Revision history for this message
In , Acelists (acelists) wrote :

Created attachment 8371072
WIP patch 3

This adds the requested test (as xpcshell so Seamonkey gets it too).
Also covers all the feedback from Neil, Irving, Josiah and Ulf.
When moving a folder outside Trash, it asks about the rename. It does not ask when moving to Trash = deleting. I can't distinguish between clicking Delete and manually dragging to Trash. That would need sending the distinguishing flag through all the layers of functions from UI to backend and I'd not want to do that in this bug.

Josiah, decide if we want to note the proposed final folder name in the renaming question as Ulf proposes.

I'll look at IMAP after we settle on what layer this needs to be. Seems the patch here does option 1. from Neil's comment.

Revision history for this message
In , Acelists (acelists) wrote :

(In reply to Ulf Zibis from comment #97)
> (In reply to Josiah Bruner [:JosiahOne] from comment #82)
> > So this seems like a fine approach to me. I think that we should call each
> > folder "folder(x)" instead of "folder-x", as it more clearly indicates
> > duplicates though. People may already have folders called Name-Subname or
> > the like, so another reason to use parenthesis.
> +1
> The "(x)" pattern is well known from file managers, so why differ here?
Josiah does not propose to differ. The last patch does rename to (x).

> > I also definitely think we should expand this to other folders, not just trash.
> (In reply to :aceman from comment #84)
> > But I think I could make that dialog with Yes/Cancel options meaning
> > Rename/Cancel. For Trash, the rename would happen without question.
> (In reply to Josiah Bruner [:JosiahOne] from comment #85)
> > Yeah, for trash moving automatically is fine.
> I think, the decision if a dialogue is shown should not be upon destination
> folder Trash, but upon the involved action:
> Delete action -> automatically rename to Folder(x)
> Move/Copy action -> ask user for renaming or cancel
> Reasons:
> - If user uses Move/Copy instead of the easier Delete he may have some
> special reason e.g. using the Trash as temporary location, so user should be
> warned as for any other Move/Copy.
I think user should never move to Trash as temporary measure. Notice may have the automatic mechanisms enabled that remove messages from trash (retention settings e.g. old messages, only x last messages, etc.) so he may easily loose those temporarily moved messages. He gets the warning about "Really delete" in both of the cases you describe. That should be a clue for him.

Revision history for this message
In , Acelists (acelists) wrote :

(In reply to :Irving Reid from comment #90)
> (In reply to :aceman from comment #89)
> > Can't bug 765926 cover maildir by itself?
> As far as I know, maildir is mostly untested aside from what's discussed in
> bug 765926. I don't know whether the long term plan is to run the entire
> suite twice, once for mbox and once for maildir - if so then yes, we'd be
> covered. That's a huge waste of testing run time, but might be easier than
> refactoring our test suite into separate tests for the higher level and the
> store.
I am sure we or somebody else will run the whole testsuite under maildir in the future. I understood bug 765926 as a metabug to fix found issues. If we do not have any other individual tests running both store versions NOW, I do not see a reason implementing it in this test (it would be an anomaly). But it would probably not be hard to add, so please decide :)

Revision history for this message
In , UlfZibis (ulf-zibis) wrote :

(In reply to :aceman from comment #99)
> Josiah does not propose to differ. The last patch does rename to (x).
Great!

> I think user should never move to Trash as temporary measure.
Well, You'll never know, what user does, ...and there is the other reason mentioned above. Additionally it looks more clean to me, if the user is warned upon normal Move/Copy action.

Revision history for this message
In , Standard8 (mbanner) wrote :

Comment on attachment 8371072
WIP patch 3

Quick Q: Has someone tested what happens in the undo case? Does the folder get named to what it was previously.

Revision history for this message
In , Acelists (acelists) wrote :

(In reply to Mark Banner (:standard8) from comment #102)
> Quick Q: Has someone tested what happens in the undo case? Does the folder
> get named to what it was previously.

I'll check that :)

We'd like to know from you if you have any idea about comment 88, 90 and 100.

Revision history for this message
In , UlfZibis (ulf-zibis) wrote :

(In reply to Mark Banner (:standard8) from comment #102)
> Quick Q: Has someone tested what happens in the undo case? Does the folder
> get named to what it was previously.

Great Q !
I too had this Q in my synapses last night before falling into dreams.

Revision history for this message
In , Acelists (acelists) wrote :

(In reply to Mark Banner (:standard8) from comment #102)
> Quick Q: Has someone tested what happens in the undo case? Does the folder
> get named to what it was previously.
Not sure what I am doing wrong but I get no option to Undo after drag-and-dropping a folder. Undo is disabled in Edit menu. If I copy a message (using the context menu and Copy to, I get Undo possibility).

Revision history for this message
In , Neil-httl (neil-httl) wrote :

Comment on attachment 8371072
WIP patch 3

>+ nsAutoString newFolderName(EmptyString());
[Strings default to empty...]

>+ while (containsChild) {
>+ rv = ContainsChildNamed(newFolderName, &containsChild);
>+ NS_ENSURE_SUCCESS(rv, rv);
>+ if (!containsChild)
>+ break;
[Weird use of loop condition.]

>+ newFolderName.AppendLiteral("(");
[Could use Append('(');]

>+confirmDuplicateFolderRename=A folder with that name already exists. Would you like to copy the folder under a different name?
You should include the suggested new folder name in the message, otherwise the user will expect to choose the new name.

Revision history for this message
In , Neil-httl (neil-httl) wrote :

Comment on attachment 8371072
WIP patch 3

>+ newFolderName.Assign(folderName);
>+ bool containsChild = true;
>+ uint32_t i = 1;
>+ while (containsChild) {
>+ rv = ContainsChildNamed(newFolderName, &containsChild);
>+ NS_ENSURE_SUCCESS(rv, rv);
>+ if (!containsChild)
>+ break;
>+ // This could be localizable but Toolkit is fine without it, see
>+ // mozilla/toolkit/content/contentAreaUtils.js::uniqueFile()
>+ i++;
>+ newFolderName.Assign(folderName);
>+ newFolderName.AppendLiteral("(");
>+ newFolderName.AppendInt(i);
>+ newFolderName.AppendLiteral(")");
>+ }
bool containsChild;
rv = ContainsChildNamed(folderName, &containsChild);
NS_ENSURE_SUCCESS(rv, rv);
while (containsChild) {
  i++;
  newFolderName.Assign(folderName);
  newFolderName.AppendLiteral("(");
  newFolderName.AppendInt(i);
  newFolderName.AppendLiteral(")");
  rv = ContainsChildNamed(newFolderName, &containsChild);
  NS_ENSURE_SUCCESS(rv, rv);
}

Revision history for this message
In , UlfZibis (ulf-zibis) wrote :

(In reply to <email address hidden> from comment #107)

Hi, why not using for statements:

> >+ newFolderName.Assign(folderName);
> >+ bool containsChild = true;
> >+ for (uint32_t i=2; ; i++) {
> >+ rv = ContainsChildNamed(newFolderName, &containsChild);
> >+ NS_ENSURE_SUCCESS(rv, rv);
> >+ if (!containsChild)
> >+ break;
> >+ // This could be localizable but Toolkit is fine without it, see
> >+ // mozilla/toolkit/content/contentAreaUtils.js::uniqueFile()
> >+ newFolderName.Assign(folderName);
> >+ newFolderName.AppendLiteral("(");
> >+ newFolderName.AppendInt(i);
> >+ newFolderName.AppendLiteral(")");
> >+ }

Revision history for this message
In , Josiah-l (josiah-l) wrote :

(In reply to Ulf Zibis from comment #108)
> (In reply to <email address hidden> from comment #107)
>
> Hi, why not using for statements:
>
> > >+ newFolderName.Assign(folderName);
> > >+ bool containsChild = true;
> > >+ for (uint32_t i=2; ; i++) {
> > >+ rv = ContainsChildNamed(newFolderName, &containsChild);
> > >+ NS_ENSURE_SUCCESS(rv, rv);
> > >+ if (!containsChild)
> > >+ break;
> > >+ // This could be localizable but Toolkit is fine without it, see
> > >+ // mozilla/toolkit/content/contentAreaUtils.js::uniqueFile()
> > >+ newFolderName.Assign(folderName);
> > >+ newFolderName.AppendLiteral("(");
> > >+ newFolderName.AppendInt(i);
> > >+ newFolderName.AppendLiteral(")");
> > >+ }

For is never used for such a purpose. That's the point of a while(condition).

Revision history for this message
In , UlfZibis (ulf-zibis) wrote :

IMHO:
1. while(condition) is only appropriate, if the condition is determined outside the loop.
2. define variables only in the scope, where they are used.
3. for(...) is appropriate if there is a counting variable, which is only used inside the loop
4. If you look closer, in your code snippet you could fairly use while(true) and define containsChild inside the loop.

Revision history for this message
In , Josiah-l (josiah-l) wrote :

No. The idea here is very similar to the common "priming read" concept taught in introductory CS courses. Following such a pattern the code here should be:

newFolderName.Assign(folderName);
bool containsChild = true;
int counter = 2;

//Priming Read
rv = ContainsChildNamed(newFolderName, &containsChild);
NS_ENSURE_SUCCESS(rv, rv);

while (containsChild) {
  // This could be localizable but Toolkit is fine without it, see
  // mozilla/toolkit/content/contentAreaUtils.js::uniqueFile()
  newFolderName.Assign(folderName);
  newFolderName.AppendLiteral("(");
  newFolderName.AppendInt(i);
  newFolderName.AppendLiteral(")");

  //Read new data
  rv = ContainsChildNamed(newFolderName, &containsChild);
  NS_ENSURE_SUCCESS(rv, rv);
}

Revision history for this message
In , Josiah-l (josiah-l) wrote :

Err. Except in that while statement there should be a:
  "counter++"
line right before we read new data.

Revision history for this message
In , UlfZibis (ulf-zibis) wrote :

Little sophisticated:

>+ newFolderName.Assign(folderName);
>+ for (uint32_t i=2, containsChild; ; i++) {
>+ rv = ContainsChildNamed(newFolderName, &containsChild);
>+ NS_ENSURE_SUCCESS(rv, rv);
>+ if (!containsChild)
>+ break;
>+ // This could be localizable but Toolkit is fine without it, see
>+ // mozilla/toolkit/content/contentAreaUtils.js::uniqueFile()
>+ newFolderName.Assign(folderName);
>+ newFolderName.AppendLiteral("(");
>+ newFolderName.AppendInt(i);
>+ newFolderName.AppendLiteral(")");
>+ }

Or really type clean:
>+ for (uint32_t i=2; ; i++) {
>+ bool containsChild;
>+ rv = ContainsChildNamed(newFolderName, &containsChild);
...

I'm not sure, if newFolderName and rv also could be drawn into the loop, are they used outside?

Revision history for this message
In , UlfZibis (ulf-zibis) wrote :

(In reply to Josiah Bruner [:JosiahOne] from comment #111)
> No. The idea here is very similar to the common "priming read" concept
> taught in introductory CS courses.
In advanced CS practice I learned: No code duplicates, because if there comes a change along, one of the duplicates could be overseen.

> Following such a pattern the code here should be:
If there is no other pattern with higher priority ;-)

> newFolderName.Assign(folderName);
> bool containsChild = true; // no need to preset it to true
> int counter = 2; // yes, better than starting with 1 as before

Revision history for this message
In , Acelists (acelists) wrote :

(In reply to <email address hidden> from comment #107)
> Comment on attachment 8371072
> WIP patch 3
>
> >+ newFolderName.Assign(folderName);
> >+ bool containsChild = true;
> >+ uint32_t i = 1;
> >+ while (containsChild) {
> >+ rv = ContainsChildNamed(newFolderName, &containsChild);
> >+ NS_ENSURE_SUCCESS(rv, rv);
> >+ if (!containsChild)
> >+ break;
> >+ // This could be localizable but Toolkit is fine without it, see
> >+ // mozilla/toolkit/content/contentAreaUtils.js::uniqueFile()
> >+ i++;
> >+ newFolderName.Assign(folderName);
> >+ newFolderName.AppendLiteral("(");
> >+ newFolderName.AppendInt(i);
> >+ newFolderName.AppendLiteral(")");
> >+ }
> bool containsChild;
> rv = ContainsChildNamed(folderName, &containsChild);
> NS_ENSURE_SUCCESS(rv, rv);
> while (containsChild) {
> i++;
> newFolderName.Assign(folderName);
> newFolderName.AppendLiteral("(");
> newFolderName.AppendInt(i);
> newFolderName.AppendLiteral(")");
> rv = ContainsChildNamed(newFolderName, &containsChild);
> NS_ENSURE_SUCCESS(rv, rv);
> }

Well, I always try to avoid the duplication of the main logic (rv = ContainsChildNamed(folderName, &containsChild);) that is why I did not write it this way :)

Revision history for this message
In , Acelists (acelists) wrote :

(In reply to Ulf Zibis from comment #114)
> (In reply to Josiah Bruner [:JosiahOne] from comment #111)
> > No. The idea here is very similar to the common "priming read" concept
> > taught in introductory CS courses.
> In advanced CS practice I learned: No code duplicates, because if there
> comes a change along, one of the duplicates could be overseen.
Exactly.

>
> > newFolderName.Assign(folderName);
> > bool containsChild = true; // no need to preset it to true
> > int counter = 2; // yes, better than starting with 1 as before

But later below the loop I check whether i (counter) > 1 so the variable exists outside the loop and value of 1 is also significant to the code.

So what about this:
    uint32_t i;
    for (i=1;;i++)) {
      newFolderName.Assign(folderName);
      if (i>1) {
        newFolderName.AppendLiteral("(");
        newFolderName.AppendInt(i);
        newFolderName.AppendLiteral(")");
      }
      rv = ContainsChildNamed(newFolderName, &containsChild);
      NS_ENSURE_SUCCESS(rv, rv);
      if (!containsChild)
        break;
    }

Of course, instead of (i>1) test later on we could do !newFolderName.Equals(folderName) but that is probably much more expensive.

Revision history for this message
In , M-wada-7 (m-wada-7) wrote :

*** Bug 305728 has been marked as a duplicate of this bug. ***

Revision history for this message
In , Irving (irving) wrote :

Comment on attachment 8371072
WIP patch 3

Review of attachment 8371072:
-----------------------------------------------------------------

Nice test.

::: mailnews/local/src/nsLocalMailFolder.cpp
@@ +1723,5 @@
> return NS_MSG_ERROR_COPY_FOLDER_ABORTED;
> }
> }
> +
> + nsAutoString newFolderName(EmptyString());

Shouldn't need the EmptyString() initializer; the constructor makes an empty string by default.

@@ +1726,5 @@
> +
> + nsAutoString newFolderName(EmptyString());
> + nsAutoString folderName;
> + rv = srcFolder->GetName(folderName);
> + NS_ENSURE_SUCCESS(rv, rv);

Mozilla core code is deprecating NS_ENSURE_SUCCESS, because the macro hides control flow - see https://groups.google.com/d/topic/mozilla.dev.platform/1clMLuuhtWQ/discussion . Use

if (NS_WARN_IF(NS_FAILED(rv))) {
  return rv;
}

if the condition deserves a warning message (as this one does)

::: mailnews/local/test/unit/test_nsIMsgLocalMailFolder.js
@@ +50,5 @@
> + do_check_eq(trash.numSubFolders, 3);
> + // The folder should be automatically renamed as the same name already is in Trash
> + // but the subfolder should be untouched.
> + let folderDeleted3 = trash.getChildNamed("folder(3)");
> + let subfolderDeleted = folderDeleted3.getChildNamed("subfolder");

do_check_true(trash.containsChildNamed("folder(3)");
do_check_true(trash.getChildNamed("folder(3)").containsChildNamed("subfolder"));

Revision history for this message
In , Acelists (acelists) wrote :

Created attachment 8374439
WIP patch 4

Thanks, addressed all comments and added a new test segment to check for the prompt when moving duplicate folder outside Trash.

Revision history for this message
In , Irving (irving) wrote :

Comment on attachment 8374439
WIP patch 4

Review of attachment 8374439:
-----------------------------------------------------------------

::: mail/locales/en-US/chrome/messenger/messenger.properties
@@ +58,5 @@
> sendingUnsent=Sending Unsent Messages
>
> folderExists=A folder with that name already exists. Please enter a different name.
> +# LOCALIZATION NOTE(confirmDuplicateFolderRename): %1$S is parent folder name, %2$S is proposed child folder name
> +confirmDuplicateFolderRename=A folder with that name already exists under folder '%1$S'. Would you like to copy the folder under a new name of '%2$S'?

Does this message come up with folder copies and moves, or only with moves? If it's only move, I suggest changing the wording to:

A folder named %1%S already exists in %2$S. Do you wish to move the folder to %2$S / %3$S?

Revision history for this message
In , Acelists (acelists) wrote :

(In reply to :Irving Reid from comment #120)
> Does this message come up with folder copies and moves, or only with moves?
> If it's only move, I suggest changing the wording to:
>
> A folder named %1%S already exists in %2$S. Do you wish to move the folder
> to %2$S / %3$S?

In the change to nsLocalMailFolder.cpp it can be seen I try to do rename only on move (we should not do a copy in CopyFolderLocal() as said earlier, but I put an if there to be sure).

Revision history for this message
In , Neil-httl (neil-httl) wrote :

Comment on attachment 8374439
WIP patch 4

>+ bool containsChild = true;
>+ uint32_t i;
>+ for (i = 1; ; i++) {
>+ newFolderName.Assign(folderName);
>+ if (i > 1) {
>+ // This could be localizable but Toolkit is fine without it, see
>+ // mozilla/toolkit/content/contentAreaUtils.js::uniqueFile()
>+ newFolderName.Append('(');
>+ newFolderName.AppendInt(i);
>+ newFolderName.Append(')');
>+ }
>+ rv = ContainsChildNamed(newFolderName, &containsChild);
>+ if (NS_WARN_IF(NS_FAILED(rv))) {
>+ return rv;
>+ }
>+ if (!containsChild)
>+ break;
>+ }
Did you mean for (i = 1; containsChild; i++) ? Note that if you do this then i ends the loop being at least 2, so you'd need to change the subsequent check. Alternatively, you would have to rewrite the loop something like this (sorry if this is what the code did in one of the earlier patches):

uint32_t i = 1;
newFolderName.Assign(folderName);
for (;;) {
  bool containsChild;
  rv = ContainsChildNamed(newFolderName, &containsChild);
  NS_ENSURE_SUCCESS(rv, rv);
  if (!containsChild)
    break;

  i++;
  newFolderName.Assign(folderName);
  newFolderName.Append('(');
  newFolderName.AppendInt(i);
  newFolderName.Append(')');
}

>+ try {
>+ root.copyFolderLocal(folderDeleted3, true, null, null);
>+ do_throw("copyFolderLocal() should have failed here due to user prompt!");
I'm not sure why you're trying to throw from inside this try block, but I don't know enough about writing tests to know whether there's a better way.

>+ } catch (e) {
>+ do_check_eq(e.result, parseInt("0x8055001a", 16));
Why not just write 0x8055001a?

>+confirmDuplicateFolderRename=A folder with that name already exists under folder '%1$S'. Would you like to copy the folder under a new name of '%2$S'?
A subfolder with that name already exists in the folder '%1$S'. Would you like to move the folder using the new name of '%2$S'?

Revision history for this message
In , Acelists (acelists) wrote :

(In reply to <email address hidden> from comment #122)
> Comment on attachment 8374439
> WIP patch 4
>
> >+ bool containsChild = true;
> >+ uint32_t i;
> >+ for (i = 1; ; i++) {
> >+ newFolderName.Assign(folderName);
> >+ if (i > 1) {
> >+ // This could be localizable but Toolkit is fine without it, see
> >+ // mozilla/toolkit/content/contentAreaUtils.js::uniqueFile()
> >+ newFolderName.Append('(');
> >+ newFolderName.AppendInt(i);
> >+ newFolderName.Append(')');
> >+ }
> >+ rv = ContainsChildNamed(newFolderName, &containsChild);
> >+ if (NS_WARN_IF(NS_FAILED(rv))) {
> >+ return rv;
> >+ }
> >+ if (!containsChild)
> >+ break;
> >+ }
> Did you mean for (i = 1; containsChild; i++) ? Note that if you do this then
> i ends the loop being at least 2, so you'd need to change the subsequent
> check. Alternatively, you would have to rewrite the loop something like this
> (sorry if this is what the code did in one of the earlier patches):
>
> uint32_t i = 1;
> newFolderName.Assign(folderName);
> for (;;) {
> bool containsChild;
> rv = ContainsChildNamed(newFolderName, &containsChild);
> NS_ENSURE_SUCCESS(rv, rv);
> if (!containsChild)
> break;
>
> i++;
> newFolderName.Assign(folderName);
> newFolderName.Append('(');
> newFolderName.AppendInt(i);
> newFolderName.Append(')');
> }
Yes, this is what the previous version did, just with a 'while'.
Is this issue really that important that we make tens of comments in such a long thread? It is not a perf critical path.

> >+ try {
> >+ root.copyFolderLocal(folderDeleted3, true, null, null);
> >+ do_throw("copyFolderLocal() should have failed here due to user prompt!");
> I'm not sure why you're trying to throw from inside this try block, but I
> don't know enough about writing tests to know whether there's a better way.
I expect .copyFolderLocal to throw and be catched by my catch. But if it does not throw (wrong behaviour), the next throw is not catched and fails the test.

>
> >+ } catch (e) {
> >+ do_check_eq(e.result, parseInt("0x8055001a", 16));
> Why not just write 0x8055001a?
Because e.result returns the code in decimal. Is there other method of 'e' I can use?

> >+confirmDuplicateFolderRename=A folder with that name already exists under folder '%1$S'. Would you like to copy the folder under a new name of '%2$S'?
> A subfolder with that name already exists in the folder '%1$S'. Would you
> like to move the folder using the new name of '%2$S'?

Irving proposed some other wording with more arguments. So what should I do now?

Revision history for this message
In , Neil-httl (neil-httl) wrote :

(In reply to aceman from comment #123)
> (In reply to comment #122)
> > (From update of attachment 8374439)
> Is this issue really that important that we make tens of comments in such a
> long thread? It is not a perf critical path.

I'm after readability here, not perf, in particular I don't like breaking at the end of a for loop, because it's easy to miss that this skips the increment.

> > >+ try {
> > >+ root.copyFolderLocal(folderDeleted3, true, null, null);
> > >+ do_throw("copyFolderLocal() should have failed here due to user prompt!");
> > I'm not sure why you're trying to throw from inside this try block, but I
> > don't know enough about writing tests to know whether there's a better way.
> I expect .copyFolderLocal to throw and be catched by my catch. But if it
> does not throw (wrong behaviour), the next throw is not catched and fails
> the test.
Sure, but my question is is it safe to put do_throw in a try block?

> > >+ } catch (e) {
> > >+ do_check_eq(e.result, parseInt("0x8055001a", 16));
> > Why not just write 0x8055001a?
> Because e.result returns the code in decimal. Is there other method of 'e' I
> can use?

nsIException.idl (if that's the right one) says that result is an unsigned long, not a decimal. So I don't see why you can't compare it to any other integer.

> > >+confirmDuplicateFolderRename=A folder with that name already exists under folder '%1$S'. Would you like to copy the folder under a new name of '%2$S'?
> > A subfolder with that name already exists in the folder '%1$S'. Would you
> > like to move the folder using the new name of '%2$S'?
>
> Irving proposed some other wording with more arguments. So what should I do
> now?

Sorry, I hadn't seen his wording. How about:
A subfolder with the name '%$1S' already exists in the folder '%2$S'. Would you like to move this folder using the new name of '%3$S'?
(I don't really want to use a / because that's an implementation detail.)

Revision history for this message
In , Acelists (acelists) wrote :

Created attachment 8377817
patch v5

> > > >+ try {
> > > >+ root.copyFolderLocal(folderDeleted3, true, null, null);
> > > >+ do_throw("copyFolderLocal() should have failed here due to user prompt!");
> > > I'm not sure why you're trying to throw from inside this try block, but I
> > > don't know enough about writing tests to know whether there's a better way.
> > I expect .copyFolderLocal to throw and be catched by my catch. But if it
> > does not throw (wrong behaviour), the next throw is not catched and fails
> > the test.
> Sure, but my question is is it safe to put do_throw in a try block?
I use the same pattern in test_fileName.js. I don't know if it is safe enough. I now changed the catch a bit to only catch the specific exception. Is is safer now?

> > > >+ } catch (e) {
> > > >+ do_check_eq(e.result, parseInt("0x8055001a", 16));
> > > Why not just write 0x8055001a?
> > Because e.result returns the code in decimal. Is there other method of 'e' I
> > can use?
> nsIException.idl (if that's the right one) says that result is an unsigned
> long, not a decimal. So I don't see why you can't compare it to any other
> integer.
I knew octal literals are deprecated so somehow I extended that to hex too. Thanks.

Revision history for this message
In , Irving (irving) wrote :

Comment on attachment 8377817
patch v5

Review of attachment 8377817:
-----------------------------------------------------------------

(In reply to <email address hidden> from comment #124)
> (In reply to aceman from comment #123)
> > (In reply to comment #122)
> > > (From update of attachment 8374439)
> > Is this issue really that important that we make tens of comments in such a
> > long thread? It is not a perf critical path.
>
> I'm after readability here, not perf, in particular I don't like breaking at
> the end of a for loop, because it's easy to miss that this skips the
> increment.
>
> > > >+ try {
> > > >+ root.copyFolderLocal(folderDeleted3, true, null, null);
> > > >+ do_throw("copyFolderLocal() should have failed here due to user prompt!");
> > > I'm not sure why you're trying to throw from inside this try block, but I
> > > don't know enough about writing tests to know whether there's a better way.
> > I expect .copyFolderLocal to throw and be catched by my catch. But if it
> > does not throw (wrong behaviour), the next throw is not catched and fails
> > the test.
> Sure, but my question is is it safe to put do_throw in a try block?

You can call do_throw() inside a try; whether you catch it or not it still registers as a test failure (see https://developer.mozilla.org/en-US/docs/Mozilla/QA/Writing_xpcshell-based_unit_tests#XPCShell_test_utility_functions)

> Sorry, I hadn't seen his wording. How about:
> A subfolder with the name '%$1S' already exists in the folder '%2$S'. Would
> you like to move this folder using the new name of '%3$S'?
> (I don't really want to use a / because that's an implementation detail.)

This is OK with me; whoever has ui-r? gets final say. r+ aside from that wording change.

Revision history for this message
In , Acelists (acelists) wrote :

Comment on attachment 8377817
patch v5

Review of attachment 8377817:
-----------------------------------------------------------------

Josiah, please see the discussion about the wording of the message and decide on ui-r :)

Revision history for this message
In , Neil-httl (neil-httl) wrote :

(In reply to aceman from comment #125)
> I knew octal literals are deprecated so somehow I extended that to hex too.
> Thanks.

The only reason old-style octal literals are deprecated is because it's too easy to confuse them with decimal literals e.g. 160 - 060 != 100. Hex literals and new-style octal literals (0o60) are fine, of course.

Revision history for this message
In , Neil-httl (neil-httl) wrote :

Comment on attachment 8377817
patch v5

>+ rv = bundle->FormatStringFromName(MOZ_UTF16("confirmDuplicateFolderRename"),
>+ formatStrings, 3, getter_Copies(confirmString));
If you'd used MOZ_ARRAY_LENGTH(formatStrings) it would have saved you the trouble of changing it each time ;-)

>+ } catch (e if e.result == 0x8055001a) {
>+ // catch only the expected error, otherwise fail the test.
Nice!

Revision history for this message
In , Standard8 (standard8) wrote :

(In reply to :aceman from comment #100)
> (In reply to :Irving Reid from comment #90)
> > (In reply to :aceman from comment #89)
> > > Can't bug 765926 cover maildir by itself?
> > As far as I know, maildir is mostly untested aside from what's discussed in
> > bug 765926. I don't know whether the long term plan is to run the entire
> > suite twice, once for mbox and once for maildir - if so then yes, we'd be
> > covered. That's a huge waste of testing run time, but might be easier than
> > refactoring our test suite into separate tests for the higher level and the
> > store.
> I am sure we or somebody else will run the whole testsuite under maildir in
> the future. I understood bug 765926 as a metabug to fix found issues. If we
> do not have any other individual tests running both store versions NOW, I do
> not see a reason implementing it in this test (it would be an anomaly). But
> it would probably not be hard to add, so please decide :)

I know David implemented some maildir tests. I can't remember if they ran both twice or not, or if it was just some additional tests in places.

I believe the intent was to do a complete switch over at some stage, and hence this wouldn't have been running the suites twice (although there would likely be something vague in the middle where both existed, and we probably would need the tests).

I would suggest having a quick look around. For now, mbox should be enough I think.

Revision history for this message
In , Josiah-l (josiah-l) wrote :

Comment on attachment 8377817
patch v5

Review of attachment 8377817:
-----------------------------------------------------------------

I'm good with:

A subfolder with the name '%$1S' already exists in the folder '%2$S'. Would you like to move this folder using the new name '%3$S'?

(So sans the 'of' part of Neil's suggestion)

Revision history for this message
In , Acelists (acelists) wrote :

Created attachment 8390075
patch v6 - local folders

Oh, looks like this got all the reviews. Marking for superreview if one is needed for the changed idl.

Revision history for this message
In , Standard8 (standard8) wrote :

Comment on attachment 8390075
patch v6 - local folders

Review of attachment 8390075:
-----------------------------------------------------------------

::: mailnews/base/util/nsMsgDBFolder.cpp
@@ +3843,5 @@
>
> +nsresult
> +nsMsgDBFolder::ConfirmAutoFolderRename(nsIMsgWindow *msgWindow,
> + const nsString aOldName,
> + const nsString aNewName,

These should be const nsString &... to avoid unnecessary string copies.

@@ +3846,5 @@
> + const nsString aOldName,
> + const nsString aNewName,
> + bool *confirmed)
> +{
> + NS_ENSURE_ARG_POINTER(confirmed);

It is possible that confirmed never gets set, so you might then end up with a bad value.

Additionally I don't really see the point of returning nsresult here, when you're already warning for errors, and you treat a failure as not confirmed anyway.

So I think it would be simpler just to change this function to return the bool.

Revision history for this message
In , Acelists (acelists) wrote :

Created attachment 8390810
patch v7 - local folders

Thanks, converted the function to bool.

Revision history for this message
In , L-bernh5rd-s (l-bernh5rd-s) wrote :

Why don't You allow double/multiple entries, may be
- add the delete timestamp
- add the different parent folders

Revision history for this message
In , Alexandrevicenzi (alexandrevicenzi) wrote :

*** Bug 987608 has been marked as a duplicate of this bug. ***

Revision history for this message
In , Ryanvm (ryanvm) wrote :
Revision history for this message
In , Euryalus-0 (euryalus-0) wrote :

*** Bug 998862 has been marked as a duplicate of this bug. ***

Revision history for this message
In , Vseerror (vseerror) wrote :

should we not do the rest in a followup bug? ref: [leave open after checkin]

Revision history for this message
In , Acelists (acelists) wrote :

Yes, I am currently not working on the remaining parts. You can close this for ease of tracking in which TB version this went.

Revision history for this message
In , Vseerror (vseerror) wrote :

Bug 125864 is open, Trash does not maintain deleted folder's hierarchy location

Is anything else left that needs a new bug report?

Revision history for this message
In , Acelists (acelists) wrote :

Other types of accounts (other than "local" ones), e.g. IMAP need testing and if they don't work then they need a bug.

Changed in thunderbird:
status: In Progress → Fix Released
Revision history for this message
In , Tero-t-nieminen (tero-t-nieminen) wrote :

I Don't know if this is the same old bug again (or something completely new), but today I noticed that my TB 31.2.0 under RHEL6.6 (64-bit) didn't delete an IMAP folder (In Exchange) if a folder with the same name already existed in the Trash. It just silently didn't delete it, until I renamed the same name folder in Trash to something else. In this case the folder to be deleted was in "IMAP:/.../Archive/", as if that should make any difference.

Revision history for this message
In , Acelists (acelists) wrote :

See comment 142. If you see the problem on IMAP, please open a new bug. We knowingly fixed it only for POP3/Local accounts in this bug.

Revision history for this message
In , Tero-t-nieminen (tero-t-nieminen) wrote :

(In reply to :aceman from comment #144)
> See comment 142. If you see the problem on IMAP, please open a new bug. We
> knowingly fixed it only for POP3/Local accounts in this bug.

Ok, will do...

Revision history for this message
Douglas Royds (douglas-royds) wrote :

@Acelists
This Launchpad defect was raised on IMAP in the first place. Bugzilla 66763 is a different thing.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.