Hi anyone,
just installed Thunderbird 3.0 final and I get undefined values with getURIsForSelection().
With TB 2.0 or 3.0 beta it worked fine. Any ideas?
This is a discussion on Exception by saving selected messages in Thunderbird as EML - Mozilla ; Hello! I am trying to develop a simple Thunderbird extension and I need your help. It should save the currently selected messages in Thunderbird as EML-files into the filesystem. I've got the following code-fragment: .... var uris = {}; var ...
Hello!
I am trying to develop a simple Thunderbird extension and I need your help.
It should save the currently selected messages in Thunderbird as EML-files
into the filesystem.
I've got the following code-fragment:
....
var uris = {};
var uriCount = {};
gDBView.getURIsForSelection(uris, uriCount); // get currently selected
eMail-messages
var selectedMails = uris.value;
if((selectedMails != null) && (selectedMails.length > 0))
{
var eMailFile = null;
for(var i = 0; i < selectedMails.length; i++)
{
// following code only works, if one item is selected!
eMailFile = this.createUniqueFile(".eml");
if((eMailFile != null) && (eMailFile.path.length > 0))
{
// do something with the eMailFile (nsIFile)
}
}
}
....
Code for the function "createUniqueFile()":
....
createUniqueFile:function(extension)
{
var messageCounter = 0;
var fileName = "";
var now = new Date();
var tickCount = 0;
// get temp-folder-path for file
var tempFile =
Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).g et("TmpD",
Components.interfaces.nsIFile);
// loop for generating unique filename
do
{
tickCount = now.getTime();
messageCounter++;
fileName = "_" + messageCounter + "_" + tickCount + extension;
tempFile.append(fileName);
} while((tempFile.exists()) && (messageCounter != Infinity));
if(messageCounter == Infinity)
{
tempFile = null;
}
else
{
try
{
// alert("file to create: " + tempFile.target.toString()); // with this
alert, the code works fine; without it throws an exception
(NS_ERROR_FILE_NOT_FOUND) up to the second call
tempFile.create(Components.interfaces.nsIFile.NORM AL_FILE_TYPE, 0666);
}
catch(exception)
{
alert("exception: \n" + exception);
tempFile = null;
}
}
return tempFile;
},
....
This code works fine, if only one message is selected. And if more than one
message is selected and the alert-box (// alert("file to create: " ...) is
active this code works also fine. But when in multi-selection-mode the
alert-box is inactive an exception occurs. The problem is, that the
exception NS_ERROR_FILE_NOT_FOUND in "tempFile.create(...)" is thrown. But
in the documentation on https://developer.mozilla.org/en/NsIFile/create the
function "create()" could only throw the following exceptions:
NS_ERROR_FILE_ALREADY_EXISTS and NS_ERROR_FILE_UNKNOWN_TYPE.
Could somebody help me in this case? I assume something like asynchronous
calls (threads) or timing problems in Thunderbird. Did you need more
information? Did I use the correct way to save messages as EMLs in
Thuunderbird?
Thank you for your help!
Hi anyone,
just installed Thunderbird 3.0 final and I get undefined values with getURIsForSelection().
With TB 2.0 or 3.0 beta it worked fine. Any ideas?