Objects that implements nsIMsgMessageService give the user top level routines related to messages like copying, displaying, attachment's manipulation, printing, streaming the message content to eml format string, etc.
Inherits from: nsISupports
void CopyMessage(in string aSrcURI, in |
[noscript] void CopyMessages(in |
void DisplayMessage(in string aMessageURI, in |
void openAttachment(in string aContentType, in string aFileName, in string aUrl, in string aMessageUri, in |
void SaveMessageToDisk(in string aMessageURI, in |
void GetUrlForUri(in string aMessageURI, out |
void DisplayMessageForPrinting(in string aMessageURI, in |
void Search(in |
|
in string aMessageURI, in in |
boolean isMsgInMemCache(in , in |
|
Pass in the URI for the message you want to have copied. aCopyListener already knows about the destination folder.
void CopyMessage(in string aSrcURI,
in nsIStreamListener aCopyListener,
in boolean aMoveMessage,
in nsIUrlListener aUrlListener,
in nsIMsgWindow aMsgWindow,
out nsIURI aURL);
aSrcURIurl of the message to copy.aCopyListenernsIStreamListener to be notified of copy events.aMoveMessagetrue if you want the message to be moved. false leaves it as just a copy.aUrlListenernsIUrlListener to be notified of url events.aMsgWindownsIMsgWindow for progress and status feedbackaURLnsIURI of the message.Copy multiple messages at a time. See CopyMessage
[noscript] void CopyMessages(innsMsgKeyArrayPtrkeys, innsIMsgFoldersrcFolder, innsIStreamListeneraCopyListener, in boolean aMoveMessage, innsIUrlListeneraUrlListener, innsIMsgWindowaMsgWindow, out nsIURI aURL);
keyssrcFolderaCopyListenernsIStreamListener to be notified of copy events.aMoveMessagetrue if you want the message to be moved. false leaves it as just a copy.aUrlListenernsIUrlListeneraMsgWindownsIMsgWindow for progress and status feedbackaURLnsIURI of the message. (?)When you want a message displayed....
void DisplayMessage(in string aMessageURI,
in nsISupports aDisplayConsumer,
in nsIMsgWindow aMsgWindow,
in nsIUrlListener aUrlListener,
in string aCharsetOverride,
out nsIURI aURL);
aMessageURIaDisplayConsumernsIDocShell which the message is loaded into.aMsgWindownsIMsgWindow for progress and status feedbackaUrlListenernsIUrlListeneraCharsetOverrideaURLnsIURI of the message.Downloads and opens an attachment.
void openAttachment(in string aContentType,
in string aFileName,
in string aUrl,
in string aMessageUri,
in nsISupports aDisplayConsumer,
in nsIMsgWindow aMsgWindow,
in nsIUrlListener aUrlListener);
aContentTypeaFileNameaUrlaMessageUriaDisplayConsumerMsgWindownsIMsgWindow for progress and status feedbackaUrlListenernsIUrlListener.When you want to spool a message out to a file on disk. This is an async operation of course.
void SaveMessageToDisk(in string aMessageURI,
in nsIFileSpec aFile,
in boolean aGenerateDummyEnvelope,
in nsIUrlListener aUrlListener,
out nsIURI aURL,
in boolean canonicalLineEnding,
in nsIMsgWindow aMsgWindow);
aMessageURIaFileaGenerateDummyEnvelopefalse. Set to true if you want the message appended at the end of the file.aUrlListenernsIUrlListener for being notified when the copy is finished.canonicalLineEndingaMsgWindownsIMsgWindow for progress and status feedbackaURLnsIURI of the saved message.When you have a uri and you would like to convert that to a url which can be run through necko, you can use this method.
void GetUrlForUri(in string aMessageURI,
out nsIURI aURL,
in nsIMsgWindow aMsgWindow);
aMessageURIaMsgWindownsIMsgWindow for progress and status feedbackaURLnsIURI of the message.When you want a message displayed in a format that is suitable for printing.
void DisplayMessageForPrinting(in string aMessageURI,
in nsISupports aDisplayConsumer,
in nsIMsgWindow aMsgWindow,
in nsIUrlListener aUrlListener,
out nsIURI aURL);
aMessageURIaDisplayConsumernsIDocShell which the message is loaded into.aMsgWindownsIMsgWindow for progress and status feedbackaUrlListeneraURLnsIURI of the message.void Search(innsIMsgSearchSessionaSearchSession, innsIMsgWindowaMsgWindow, innsIMsgFolderaMsgFolder, in string aSearchUri);
aSearchSessionnsIMsgSearchSession to use.aMsgWindownsIMsgWindow for progress and status feedbackaMsgFoldernsIMsgFolderaSearchUriThis method streams a message to the passed in consumer. It will also tack aAdditionalHeader onto the url (e.g., header=filter). The good thing about this method is that you can extract a standard representation of any message, no matter if they are emails, RSS, news, blogs, etc.
nsIURI streamMessage(in string aMessageURI,
in nsISupports aConsumer,
in nsIMsgWindow aMsgWindow,
in nsIUrlListener aUrlListener,
in boolean aConvertData,
in string aAdditionalHeader);
aMessageURIaConsumeronDataAvailable method, you can write out the stream data to a local file or concatenate it to a string.aMsgWindownsIMsgWindow for progress and status feedback.aUrlListenernsIUrlListener that is notified when url starts and stops.aConvertDataaConvertData is true, it will create a stream converter from message rfc2822 to */*.aAdditionalHeaderheader=filterThe nsIURI that gets run
For example, the next piece of code shows the selected message code on a dialog: (taken from Mozillazine)
var content = "";
var MessageURI = GetFirstSelectedMessage();
var MsgService = messenger.messageServiceFromURI(MessageURI);
var MsgStream = Components.classes["@mozilla.org/network/sync-stream-listener;1"].createInstance();
var consumer = MsgStream.QueryInterface(Components.interfaces.nsIInputStream);
var ScriptInput = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance();
var ScriptInputStream = ScriptInput.QueryInterface(Components.interfaces.nsIScriptableInputStream);
ScriptInputStream.init(consumer);
try {
MsgService.streamMessage(MessageURI, MsgStream, msgWindow, null, false, null);
} catch (ex) {
alert("error: "+ex)
}
ScriptInputStream .available();
while (ScriptInputStream .available()) {
content = content + ScriptInputStream .read(512);
}
alert(content
This method streams a message's headers to the passed in consumer. This is for consumers who want a particular header but don't want to stream the whole message.
nsIURI streamMessage(in string aMessageURI,
in nsIStreamListener aConsumer,
in nsIUrlListener aUrlListener,
in boolean aLocalOnly);
aMessageURIaConsumernsIStreamListener Generally, a stream listener listening to the message headers. The consumer has to be a stream listener and in your listener's onDataAvailable method, you can write out the stream data to a local file or concatenate it to a string.aUrlListenernsIUrlListener that is notified when url starts and stops, if we run a url.aLocalOnlyIf we're offline, then even if aLocalOnly is false, we won't stream over the network
The URL that gets run, if any
Determines whether a message is in the memory cache. Local folders don't implement this.
boolean isMsgInMemCache(innsIURIaUrl, innsIMsgFolderaFolder, outnsICacheEntryDescriptoraCacheEntry);
aUrlaFolderaCacheEntryTRUE if the message is in mem cache; FALSE if it is not.
Go from message uri to nsIMsgDBHdr:
nsIMsgDBHdr messageURIToMsgHdr(in string uri);
uriThe URL that gets run, if any.