MozillaZine


Script to move message Thunderbird

User Help for Mozilla Thunderbird
gt.qualisa
 
Posts: 2
Joined: December 19th, 2011, 1:14 pm

Post Posted January 11th, 2012, 9:33 am

Hi,

I have 2 e-mail accounts in Thunderbird, with subfolders in Inbox:

Account A
Inbox
Sub-A1
Sub-A2
Sub-A3

Account B
Inbox
Sub-B1
Sub-B2
Sub-B3

I need a script to move all message (read and unread) from subfolders B to subfolders A:

Sub-B1 -> Sub-A1
Sub-B2 -> Sub-A2
Sub-B3 -> Sub-A3

I have a customize button to launch the script.

Thanks in advanced for your help/suggestions.

Patricio

LIMPET235
Moderator

User avatar
 
Posts: 39635
Joined: October 19th, 2007, 1:53 am
Location: The South Coast of N.S.W. Oz.

Post Posted January 11th, 2012, 9:36 am

Moving to Support...
Ancient Amateur Astronomer
Win-7-HP/Intel® DualCore-2.0GHz/500G HDD/4 Gig Ram/550Watt PSU/350WattUPS/Firefox-20.0-62.0-70.0-79.0/T-bird-2.0.0.24/SnagIt-v10.0.1/MWP-7.12.
W.M.Y.C.
(Always choose the "Custom" Install.)

tanstaafl
Moderator

User avatar
 
Posts: 47997
Joined: July 30th, 2003, 5:06 pm

Post Posted January 11th, 2012, 12:25 pm

Use a message filter to move messages. Since you're moving messages from something other than the inbox you need to manually invoke the message filters to do that. See http://kb.mozillazine.org/Message_Filters

gt.qualisa
 
Posts: 2
Joined: December 19th, 2011, 1:14 pm

Post Posted January 11th, 2012, 2:59 pm

Hi,

Thanks for your response. Let me expand my case.

I use "Account B" and manually arrange all new messages (Inbox) to subfolder B1 or subfolder B2 or subfolder B3. I don't use filters here because the criterias are really complex. But it isn't my problem.

I must to move (not copy) all messages from subfolder's "Account B" to subfolder's "Account A", so I need a script or small code to do something like this:

FROM -> TO
"Account B".Inbox.Sub-B1 -> "Account A".Inbox.Sub-A1
"Account B".Inbox.Sub-B2 -> "Account A".Inbox.Sub-A2
"Account B".Inbox.Sub-B3 -> "Account A".Inbox.Sub-A3

I could move messages manually, but the idea is avoid human errors.

Thanks in advance for any idea.

Patricio

DanRaisch
Moderator

User avatar
 
Posts: 125263
Joined: September 23rd, 2004, 8:57 pm
Location: Somewhere on the right coast

Post Posted January 11th, 2012, 3:36 pm

If you are moving ALL messages from one folder to another, why not simply select the source folder (Account B.Inbox.sub-B1) and then select all messages in that folder(Ctrl+A or menu path Edit->Select All), then use menu path Messages->Move to->select the target folder. Actually, to prevent loss due to errors you could Copy the messages rather than move them. Then if there is any problem you can repeat the process, eliminating the error, until all messages are in place. After all messages are "moved" as intended you can delete the contents of the original source folders.

morat
 
Posts: 4751
Joined: February 3rd, 2009, 6:29 pm

Post Posted January 11th, 2012, 4:00 pm

Try this:

Code: Select all
// move messages in source folder to destination folder
var sourceUri = "mailbox://foo%40gmail.com@pop.googlemail.com/Example";
var destinationUri = "mailbox://bar%40gmail.com@pop.googlemail.com/Example";
var sourceFolder = GetMsgFolderFromUri(sourceUri);
var destinationFolder = GetMsgFolderFromUri(destinationUri);
var enumerator = sourceFolder.messages;
var mutableArray = Components.classes["@mozilla.org/array;1"].
  createInstance(Components.interfaces.nsIMutableArray);
while (enumerator.hasMoreElements()) {
  var msgHdr = enumerator.getNext().
    QueryInterface(Components.interfaces.nsIMsgDBHdr);
  mutableArray.appendElement(msgHdr, false /*weak*/);
}
var cs = Components.classes["@mozilla.org/messenger/messagecopyservice;1"].
  getService(Components.interfaces.nsIMsgCopyService);
cs.CopyMessages(sourceFolder, mutableArray, destinationFolder,
  true /*isMove*/, null /*listener*/, msgWindow, true /*allowUndo*/); 

http://mxr.mozilla.org/comm-central/sou ... ervice.idl

tanstaafl
Moderator

User avatar
 
Posts: 47997
Joined: July 30th, 2003, 5:06 pm

Post Posted January 11th, 2012, 4:54 pm

Part of the confusion is your original post seemed to describe a much simpler problem ("move all message (read and unread) from subfolders B to subfolders A") when you press a button.

I assume you need to do this more than one time, and the complex criteria means you can't use a simple script. The FiltaQuilla add-on adds support for using regular expressions and javascript in the search criteria, using javascript as the "action" with filters and automatically running filters on folders other than the inbox (see Folder Name section).

https://addons.mozilla.org/en-US/thunde ... src=search
http://mesquilla.com/extensions/filtaquilla/ (more information on its features)

Your other alternative would be to write something like a Perl or Python script that knows how to manipulate the content of mbox folders, and where your profile is. All of the messages for each folder are stored in a plain text file named after the folder, with no file extension, called a mbox file. You can write scripts that you launch using a windows shortcut (rather than a button in Thunderbird) that find any move messages (its just text) between different mbox files. Perfectly doable, but harder to learn how to do.

Return to Thunderbird Support


Who is online

Users browsing this forum: No registered users and 4 guests