mozilla

Revision 300859 of nsIMsgMessageService

  • Revision slug: XPCOM_Interface_Reference/nsIMsgMessageService
  • Revision title: nsIMsgMessageService
  • Revision id: 300859
  • Created:
  • Creator: Oeekker
  • Is current revision? No
  • Comment Trying to fix internal links and note

Revision Content

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.

{{ Thunderbird-InterfaceStatus("nsIMsgMessageService", "/mailnews/base/public/nsIMsgMessageService.idl", "unfrozen", "Mozilla 1.9", "yes") }}

Inherits from: {{ Interface("nsISupports") }}

Method overview

void CopyMessage(in string aSrcURI, in {{ Interface("nsIStreamListener") }} aCopyListener, in boolean aMoveMessage, in {{ Interface("nsIUrlListener") }} aUrlListener, in {{ Interface("nsIMsgWindow") }} aMsgWindow, out {{ Interface("nsIURI") }} aURL);
{{ mediawiki.external('noscript') }} void CopyMessages(in {{ Interface("nsMsgKeyArrayPtr") }} keys, in {{ Interface("nsIMsgFolder") }} srcFolder, in {{ Interface("nsIStreamListener") }} aCopyListener, in boolean aMoveMessage, in {{ Interface("nsIUrlListener") }} aUrlListener, in {{ Interface("nsIMsgWindow") }} aMsgWindow, out nsIURI aURL);
void DisplayMessage(in string aMessageURI, in {{ Interface("nsISupports") }} aDisplayConsumer, in {{ Interface("nsIMsgWindow") }} aMsgWindow, in {{ Interface("nsIUrlListener") }} aUrlListener, in string aCharsetOverride, out {{ Interface("nsIURI") }} aURL);
void openAttachment(in string aContentType, in string aFileName, in string aUrl, in string aMessageUri, in {{ Interface("nsISupports") }} aDisplayConsumer, in {{ Interface("nsIMsgWindow") }} aMsgWindow, in {{ Interface("nsIUrlListener") }} aUrlListener);
void SaveMessageToDisk(in string aMessageURI, in {{ Interface("nsIFileSpec") }} aFile, in boolean aGenerateDummyEnvelope, in {{ Interface("nsIUrlListener") }} aUrlListener, out {{ Interface("nsIURI") }} aURL, in boolean canonicalLineEnding, in {{ Interface("nsIMsgWindow") }} aMsgWindow);
void GetUrlForUri(in string aMessageURI, out {{ Interface("nsIURI") }} aURL, in {{ Interface("nsIMsgWindow") }} aMsgWindow);
void DisplayMessageForPrinting(in string aMessageURI, in {{ Interface("nsISupports") }} aDisplayConsumer, in {{ Interface("nsIMsgWindow") }} aMsgWindow, in {{ Interface("nsIUrlListener") }} aUrlListener, out {{ Interface("nsIURI") }} aURL);
void Search(in {{ Interface("nsIMsgSearchSession") }} aSearchSession, in {{ Interface("nsIMsgWindow") }} aMsgWindow, in {{ Interface("nsIMsgFolder") }} aMsgFolder, in string aSearchUri);
{{ Interface("nsIURI") }} streamMessage(in string aMessageURI, in {{ Interface("nsISupports") }} aConsumer, in {{ Interface("nsIMsgWindow") }} aMsgWindow, in {{ Interface("nsIUrlListener") }} aUrlListener, in boolean aConvertData, in string aAdditionalHeader);
{{ Interface("nsIMsgDBHdr") }} messageURIToMsgHdr(in string uri);

Methods

CopyMessage()

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);
Parameters
aSrcURI
The string url of the message to copy.
aCopyListener
An {{ Interface("nsIStreamListener") }} to be notified of copy events.
aMoveMessage
Set to true if you want the message to be moved. false leaves it as just a copy.
aUrlListener
A {{ Interface("nsIUrlListener") }} to be notified of url events.
aMsgWindow
{{ Interface("nsIMsgWindow") }} for progress and status feedback
Return values
aURL
The new {{ Interface("nsIURI") }} of the message.

CopyMessages()

Copy multiple messages at a time. See CopyMessage

 [noscript] void CopyMessages(in nsMsgKeyArrayPtr keys,
                              in nsIMsgFolder srcFolder, 
                              in nsIStreamListener aCopyListener,
                              in boolean aMoveMessage, 
                              in nsIUrlListener aUrlListener,
                              in nsIMsgWindow aMsgWindow, 
                              out nsIURI aURL);
Parameters
keys
An array of message keys to be copied.
srcFolder
 
aCopyListener
An {{ Interface("nsIStreamListener") }} to be notified of copy events.
aMoveMessage
Set to true if you want the message to be moved. false leaves it as just a copy.
aUrlListener
An {{ Interface("nsIUrlListener") }}
aMsgWindow
{{ Interface("nsIMsgWindow") }} for progress and status feedback
Return values
aURL
The new {{ Interface("nsIURI") }} of the message. (?)

DisplayMessage()

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);
Parameters
aMessageURI
A uri representing the message to display.
aDisplayConsumer
Is (for now) an {{ Interface("nsIDocShell") }} which the message is loaded into.
aMsgWindow
{{ Interface("nsIMsgWindow") }} for progress and status feedback
aUrlListener
An {{ Interface("nsIUrlListener") }}
aCharsetOverride
(optional) character set over ride to force the message to use.
Return values
aURL
The new {{ Interface("nsIURI") }} of the message.

openAttachment()

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);
Parameters
aContentType
The content type of the attachment
aFileName
The name of the attachment.
aUrl
A string representation of the original url associated with the msg.
aMessageUri
RDF resource that describes the message
aDisplayConsumer
 
MsgWindow
{{ Interface("nsIMsgWindow") }} for progress and status feedback
aUrlListener
An {{ Interface("nsIUrlListener") }}.

SaveMessageToDisk()

When you want to spool a message out to a file on disk. This is an async operation of course.{{ Note("You must pass in a url listener in order to figure out when the operation is done.") }}

 void SaveMessageToDisk(in string aMessageURI,
                        in nsIFileSpec aFile, 
                        in boolean aGenerateDummyEnvelope,
                        in nsIUrlListener aUrlListener, 
                        out nsIURI aURL,
                        in boolean canonicalLineEnding, 
                        in nsIMsgWindow aMsgWindow);
Parameters
aMessageURI
Url representing the message to spool out to disk.
aFile
The file you want the message saved to.
aGenerateDummyEnvelope
Usually false. Set to true if you want the message appended at the end of the file.
aUrlListener
A {{ Interface("nsIUrlListener") }} for being notified when the copy is finished.
canonicalLineEnding
aMsgWindow
{{ Interface("nsIMsgWindow") }} for progress and status feedback
Return values
aURL
The new {{ Interface("nsIURI") }} of the saved message.

{{ Note("This operation may be obsolete. You always can use streamMessage to get the eml string representation of the message and then write it using File I/O Methods.") }}

GetUrlForUri()

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. {{ Note("The Uri MUST refer to a message and not a folder!") }}

 void GetUrlForUri(in string aMessageURI,
                   out nsIURI aURL,
                   in nsIMsgWindow aMsgWindow);
Parameters
aMessageURI
 
aMsgWindow
{{ Interface("nsIMsgWindow") }} for progress and status feedback
Return values
aURL
The {{ Interface("nsIURI") }} of the message.

DisplayMessageForPrinting()

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);
Parameters
aMessageURI
A uri representing the message to display.
aDisplayConsumer
For now, a {{ Interface("nsIDocShell") }} which the message is loaded into.
aMsgWindow
{{ Interface("nsIMsgWindow") }} for progress and status feedback
aUrlListener
 
Return values
aURL
The new {{ Interface("nsIURI") }} of the message.

Search()

 void Search(in nsIMsgSearchSession aSearchSession,
             in nsIMsgWindow aMsgWindow, 
             in nsIMsgFolder aMsgFolder,
             in string aSearchUri);
Parameters
aSearchSession
The {{ Interface("nsIMsgSearchSession") }} to use.
aMsgWindow
{{ Interface("nsIMsgWindow") }} for progress and status feedback
aMsgFolder
{{ Interface("nsIMsgFolder") }}
aSearchUri
url of the search.

streamMessage()

This 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);
Parameters
aMessageURI
uri of message to stream
aConsumer
Generally, a stream listener listening to the message. 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.
aMsgWindow
{{ Interface("nsIMsgWindow") }} for progress and status feedback.
aUrlListener
An {{ Interface("nsIUrlListener") }} that is notified when url starts and stops.
aConvertData
If aConvertData is true, it will create a stream converter from message rfc2822 to */*.
aAdditionalHeader
Header added to the URI. e.g., header=filter
Return

The {{ Interface("nsIURI") }} that gets run

Example

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);

messageURIToMsgHdr()

Go from message uri to {{ Interface("nsIMsgDBHdr") }}:

 nsIMsgDBHdr messageURIToMsgHdr(in string uri);
Parameters
uri
url of the message
Return

The message's {{ Interface("nsIMsgDBHdr") }}

Revision Source

<p>Objects that implements <code>nsIMsgMessageService</code> give the user top level routines related to messages like copying, displaying, attachment's manipulation, printing, streaming the message content to <code><a href="/en/Eml" title="en/Eml">eml</a></code> format string, etc.</p>
<p>{{ Thunderbird-InterfaceStatus("nsIMsgMessageService", "/mailnews/base/public/nsIMsgMessageService.idl", "unfrozen", "Mozilla 1.9", "yes") }}</p>
<p>Inherits from: {{ Interface("nsISupports") }}</p>
<h2 id="Method_overview" name="Method_overview">Method overview</h2>
<table class="standard-table">
  <tbody>
    <tr>
      <td><code>void <a href="#CopyMessage()">CopyMessage</a>(in string aSrcURI, in {{ Interface("nsIStreamListener") }} aCopyListener, in boolean aMoveMessage, in {{ Interface("nsIUrlListener") }} aUrlListener, in {{ Interface("nsIMsgWindow") }} aMsgWindow, out {{ Interface("nsIURI") }} aURL);</code></td>
    </tr>
    <tr>
      <td><code>{{ mediawiki.external('noscript') }} void <a href="#CopyMessages()">CopyMessages</a>(in {{ Interface("nsMsgKeyArrayPtr") }} keys, in {{ Interface("nsIMsgFolder") }} srcFolder, in {{ Interface("nsIStreamListener") }} aCopyListener, in boolean aMoveMessage, in {{ Interface("nsIUrlListener") }} aUrlListener, in {{ Interface("nsIMsgWindow") }} aMsgWindow, out nsIURI aURL);</code></td>
    </tr>
    <tr>
      <td><code>void <a href="#DisplayMessage()">DisplayMessage</a>(in string aMessageURI, in {{ Interface("nsISupports") }} aDisplayConsumer, in {{ Interface("nsIMsgWindow") }} aMsgWindow, in {{ Interface("nsIUrlListener") }} aUrlListener, in string aCharsetOverride, out {{ Interface("nsIURI") }} aURL);</code></td>
    </tr>
    <tr>
      <td><code>void <a href="#openAttachment()">openAttachment</a>(in string aContentType, in string aFileName, in string aUrl, in string aMessageUri, in {{ Interface("nsISupports") }} aDisplayConsumer, in {{ Interface("nsIMsgWindow") }} aMsgWindow, in {{ Interface("nsIUrlListener") }} aUrlListener);</code></td>
    </tr>
    <tr>
      <td><code>void <a href="#SaveMessageToDisk()">SaveMessageToDisk</a>(in string aMessageURI, in {{ Interface("nsIFileSpec") }} aFile, in boolean aGenerateDummyEnvelope, in {{ Interface("nsIUrlListener") }} aUrlListener, out {{ Interface("nsIURI") }} aURL, in boolean canonicalLineEnding, in {{ Interface("nsIMsgWindow") }} aMsgWindow);</code></td>
    </tr>
    <tr>
      <td><code>void <a href="#GetUrlForUri()">GetUrlForUri</a>(in string aMessageURI, out {{ Interface("nsIURI") }} aURL, in {{ Interface("nsIMsgWindow") }} aMsgWindow);</code></td>
    </tr>
    <tr>
      <td><code>void <a href="#DisplayMessageForPrinting()">DisplayMessageForPrinting</a>(in string aMessageURI, in {{ Interface("nsISupports") }} aDisplayConsumer, in {{ Interface("nsIMsgWindow") }} aMsgWindow, in {{ Interface("nsIUrlListener") }} aUrlListener, out {{ Interface("nsIURI") }} aURL);</code></td>
    </tr>
    <tr>
      <td><code>void <a href="#Search()">Search</a>(in {{ Interface("nsIMsgSearchSession") }} aSearchSession, in {{ Interface("nsIMsgWindow") }} aMsgWindow, in {{ Interface("nsIMsgFolder") }} aMsgFolder, in string aSearchUri);</code></td>
    </tr>
    <tr>
      <td><code>{{ Interface("nsIURI") }} <a href="#streamMessage()">streamMessage</a>(in string aMessageURI, in {{ Interface("nsISupports") }} aConsumer, in {{ Interface("nsIMsgWindow") }} aMsgWindow, in {{ Interface("nsIUrlListener") }} aUrlListener, in boolean aConvertData, in string aAdditionalHeader);</code></td>
    </tr>
    <tr>
      <td><code>{{ Interface("nsIMsgDBHdr") }} <a href="#messageURIToMsgHdr()">messageURIToMsgHdr</a>(in string uri);</code></td>
    </tr>
  </tbody>
</table>
<h2 id="Methods">Methods</h2>
<h3 id="CopyMessage()">CopyMessage()</h3>
<p>Pass in the URI for the message you want to have copied. <code>aCopyListener</code> already knows about the destination folder.</p>
<pre class="eval">
 void CopyMessage(in string aSrcURI,
                  in nsIStreamListener aCopyListener, 
                  in boolean aMoveMessage,
                  in nsIUrlListener aUrlListener, 
                  in nsIMsgWindow aMsgWindow,
                  out nsIURI aURL);
</pre>
<h6 id="Parameters" name="Parameters">Parameters</h6>
<dl>
  <dt>
    <code>aSrcURI</code></dt>
  <dd>
    The string <code>url</code> of the message to copy.</dd>
  <dt>
    <code>aCopyListener</code></dt>
  <dd>
    An {{ Interface("nsIStreamListener") }} to be notified of copy events.</dd>
  <dt>
    <code>aMoveMessage</code></dt>
  <dd>
    Set to <code>true</code> if you want the message to be moved. <code>false</code> leaves it as just a copy.</dd>
  <dt>
    <code>aUrlListener</code></dt>
  <dd>
    A {{ Interface("nsIUrlListener") }} to be notified of url events.</dd>
  <dt>
    <code>aMsgWindow</code></dt>
  <dd>
    {{ Interface("nsIMsgWindow") }} for progress and status feedback</dd>
</dl>
<h6 id="Return_values" name="Return_values">Return values</h6>
<dl>
  <dt>
    <code>aURL</code></dt>
  <dd>
    The new {{ Interface("nsIURI") }} of the message.</dd>
</dl>
<h3 id="CopyMessages()">CopyMessages()</h3>
<p>Copy multiple messages at a time. See <a href="#CopyMessage()">CopyMessage</a></p>
<pre class="eval">
 [noscript] void CopyMessages(in nsMsgKeyArrayPtr keys,
                              in nsIMsgFolder srcFolder, 
                              in nsIStreamListener aCopyListener,
                              in boolean aMoveMessage, 
                              in nsIUrlListener aUrlListener,
                              in nsIMsgWindow aMsgWindow, 
                              out nsIURI aURL);
</pre>
<h6 id="Parameters_2" name="Parameters_2">Parameters</h6>
<dl>
  <dt>
    <code>keys</code></dt>
  <dd>
    An array of message keys to be copied.</dd>
  <dt>
    <code>srcFolder</code></dt>
  <dd>
    &nbsp;</dd>
  <dt>
    <code>aCopyListener</code></dt>
  <dd>
    An {{ Interface("nsIStreamListener") }} to be notified of copy events.</dd>
  <dt>
    <code>aMoveMessage</code></dt>
  <dd>
    Set to <code>true</code> if you want the message to be moved. <code>false</code> leaves it as just a copy.</dd>
  <dt>
    <code>aUrlListener</code></dt>
  <dd>
    An {{ Interface("nsIUrlListener") }}</dd>
  <dt>
    <code>aMsgWindow</code></dt>
  <dd>
    {{ Interface("nsIMsgWindow") }} for progress and status feedback</dd>
</dl>
<h6 id="Return_values_2" name="Return_values_2">Return values</h6>
<dl>
  <dt>
    <code>aURL</code></dt>
  <dd>
    The new {{ Interface("nsIURI") }} of the message. (?)</dd>
</dl>
<h3 id="DisplayMessage()">DisplayMessage()</h3>
<p>When you want a message displayed....</p>
<pre class="eval">
 void DisplayMessage(in string aMessageURI,
                     in nsISupports aDisplayConsumer, 
                     in nsIMsgWindow aMsgWindow,
                     in nsIUrlListener aUrlListener, 
                     in string aCharsetOverride,
                     out nsIURI aURL);
</pre>
<h6 id="Parameters_3" name="Parameters_3">Parameters</h6>
<dl>
  <dt>
    <code>aMessageURI</code></dt>
  <dd>
    A uri representing the message to display.</dd>
  <dt>
    <code>aDisplayConsumer</code></dt>
  <dd>
    Is (for now) an {{ Interface("nsIDocShell") }} which the message is loaded into.</dd>
  <dt>
    <code>aMsgWindow</code></dt>
  <dd>
    {{ Interface("nsIMsgWindow") }} for progress and status feedback</dd>
  <dt>
    <code>aUrlListener</code></dt>
  <dd>
    An {{ Interface("nsIUrlListener") }}</dd>
  <dt>
    <code>aCharsetOverride</code></dt>
  <dd>
    (optional) character set over ride to force the message to use.</dd>
</dl>
<h6 id="Return_values_3" name="Return_values_3">Return values</h6>
<dl>
  <dt>
    <code>aURL</code></dt>
  <dd>
    The new {{ Interface("nsIURI") }} of the message.</dd>
</dl>
<h3 id="openAttachment()">openAttachment()</h3>
<p>Downloads and opens an attachment.</p>
<pre class="eval">
 void openAttachment(in string aContentType,
                     in string aFileName,
                     in string aUrl, 
                     in string aMessageUri,
                     in nsISupports aDisplayConsumer, 
                     in nsIMsgWindow aMsgWindow,
                     in nsIUrlListener aUrlListener);
</pre>
<h6 id="Parameters_4" name="Parameters_4">Parameters</h6>
<dl>
  <dt>
    <code>aContentType</code></dt>
  <dd>
    The content type of the attachment</dd>
  <dt>
    <code>aFileName</code></dt>
  <dd>
    The name of the attachment.</dd>
  <dt>
    <code>aUrl</code></dt>
  <dd>
    A string representation of the original url associated with the msg.</dd>
  <dt>
    <code>aMessageUri</code></dt>
  <dd>
    <a href="/en/RDF" title="en/RDF">RDF</a> resource that describes the message</dd>
  <dt>
    <code>aDisplayConsumer</code></dt>
  <dd>
    &nbsp;</dd>
  <dt>
    <code>MsgWindow</code></dt>
  <dd>
    {{ Interface("nsIMsgWindow") }} for progress and status feedback</dd>
  <dt>
    <code>aUrlListener</code></dt>
  <dd>
    An {{ Interface("nsIUrlListener") }}.</dd>
</dl>
<h3 id="SaveMessageToDisk()">SaveMessageToDisk()</h3>
<p>When you want to spool a message out to a file on disk. This is an async operation of course.{{ Note("You must pass in a url listener in order to figure out when the operation is done.") }}</p>
<pre class="eval">
 void SaveMessageToDisk(in string aMessageURI,
                        in nsIFileSpec aFile, 
                        in boolean aGenerateDummyEnvelope,
                        in nsIUrlListener aUrlListener, 
                        out nsIURI aURL,
                        in boolean canonicalLineEnding, 
                        in nsIMsgWindow aMsgWindow);
</pre>
<h6 id="Parameters_5" name="Parameters_5">Parameters</h6>
<dl>
  <dt>
    <code>aMessageURI</code></dt>
  <dd>
    Url representing the message to spool out to disk.</dd>
  <dt>
    <code>aFile</code></dt>
  <dd>
    The file you want the message saved to.</dd>
  <dt>
    <code>aGenerateDummyEnvelope</code></dt>
  <dd>
    Usually <code>false</code>. Set to <code>true</code> if you want the message appended at the end of the file.</dd>
  <dt>
    <code>aUrlListener</code></dt>
  <dd>
    A {{ Interface("nsIUrlListener") }} for being notified when the copy is finished.</dd>
  <dt>
    <code>canonicalLineEnding</code></dt>
  <dt>
    <code>aMsgWindow</code></dt>
  <dd>
    {{ Interface("nsIMsgWindow") }} for progress and status feedback</dd>
</dl>
<h6 id="Return_values_4" name="Return_values_4">Return values</h6>
<dl>
  <dt>
    <code>aURL</code></dt>
  <dd>
    The new {{ Interface("nsIURI") }} of the saved message.</dd>
</dl>
<p>{{ Note("This operation may be obsolete. You always can use <a href=#streamMessage()>streamMessage</a> to get the <a href=/en/Eml>eml</a> string representation of the message and then write it using <a href=/en/Code_snippets/File_I_O>File I/O Methods</a>.") }}</p>
<h3 id="GetUrlForUri()">GetUrlForUri()</h3>
<p>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. {{ Note("The Uri MUST refer to a message and not a folder!") }}</p>
<pre class="eval">
 void GetUrlForUri(in string aMessageURI,
                   out nsIURI aURL,
                   in nsIMsgWindow aMsgWindow);
</pre>
<h6 id="Parameters_6" name="Parameters_6">Parameters</h6>
<dl>
  <dt>
    <code>aMessageURI</code></dt>
  <dd>
    &nbsp;</dd>
  <dt>
    <code>aMsgWindow</code></dt>
  <dd>
    {{ Interface("nsIMsgWindow") }} for progress and status feedback</dd>
</dl>
<h6 id="Return_values_5" name="Return_values_5">Return values</h6>
<dl>
  <dt>
    <code>aURL</code></dt>
  <dd>
    The {{ Interface("nsIURI") }} of the message.</dd>
</dl>
<h3 id="DisplayMessageForPrinting()">DisplayMessageForPrinting()</h3>
<p>When you want a message displayed in a format that is suitable for printing.</p>
<pre class="eval">
 void DisplayMessageForPrinting(in string aMessageURI,
                                in nsISupports aDisplayConsumer, 
                                in nsIMsgWindow aMsgWindow,
                                in nsIUrlListener aUrlListener, 
                                out nsIURI aURL);
</pre>
<h6 id="Parameters_7" name="Parameters_7">Parameters</h6>
<dl>
  <dt>
    <code>aMessageURI</code></dt>
  <dd>
    A uri representing the message to display.</dd>
  <dt>
    <code>aDisplayConsumer</code></dt>
  <dd>
    For now, a {{ Interface("nsIDocShell") }} which the message is loaded into.</dd>
  <dt>
    <code>aMsgWindow</code></dt>
  <dd>
    {{ Interface("nsIMsgWindow") }} for progress and status feedback</dd>
  <dt>
    <code>aUrlListener</code></dt>
  <dd>
    &nbsp;</dd>
</dl>
<h6 id="Return_values_6" name="Return_values_6">Return values</h6>
<dl>
  <dt>
    <code>aURL</code></dt>
  <dd>
    The new {{ Interface("nsIURI") }} of the message.</dd>
</dl>
<h3 id="Search()">Search()</h3>
<pre class="eval">
 void Search(in nsIMsgSearchSession aSearchSession,
             in nsIMsgWindow aMsgWindow, 
             in nsIMsgFolder aMsgFolder,
             in string aSearchUri);
</pre>
<h6 id="Parameters_8" name="Parameters_8">Parameters</h6>
<dl>
  <dt>
    <code>aSearchSession</code></dt>
  <dd>
    The {{ Interface("nsIMsgSearchSession") }} to use.</dd>
  <dt>
    <code>aMsgWindow</code></dt>
  <dd>
    {{ Interface("nsIMsgWindow") }} for progress and status feedback</dd>
  <dt>
    <code>aMsgFolder</code></dt>
  <dd>
    {{ Interface("nsIMsgFolder") }}</dd>
  <dt>
    <code>aSearchUri</code></dt>
  <dd>
    url of the search.</dd>
</dl>
<h3 id="streamMessage()">streamMessage()</h3>
<p>This method streams a message to the passed in consumer. It will also tack <code>aAdditionalHeader</code> onto the url (e.g., <code>header=filter</code>). The good thing about this method is that you can extract a standard representation of any message, no matter if they are emails, <a href="/en/RSS" title="en/RSS">RSS</a>, news, blogs, etc.</p>
<pre class="eval">
 nsIURI streamMessage(in string aMessageURI,
                      in nsISupports aConsumer, 
                      in nsIMsgWindow aMsgWindow,
                      in nsIUrlListener aUrlListener,  
                      in boolean aConvertData,
                      in string aAdditionalHeader);
</pre>
<h6 id="Parameters_9" name="Parameters_9">Parameters</h6>
<dl>
  <dt>
    <code>aMessageURI</code></dt>
  <dd>
    uri of message to stream</dd>
  <dt>
    <code>aConsumer</code></dt>
  <dd>
    Generally, a stream listener listening to the message. The consumer has to be a stream listener and in your listener's <code>onDataAvailable</code> method, you can write out the stream data to a local file or concatenate it to a string.</dd>
  <dt>
    <code>aMsgWindow</code></dt>
  <dd>
    {{ Interface("nsIMsgWindow") }} for progress and status feedback.</dd>
  <dt>
    <code>aUrlListener</code></dt>
  <dd>
    An {{ Interface("nsIUrlListener") }} that is notified when url starts and stops.</dd>
  <dt>
    <code>aConvertData</code></dt>
  <dd>
    If <code>aConvertData</code> is true, it will create a stream converter from message <a class="external" href="http://tools.ietf.org/html/rfc2822">rfc2822</a> to */*.</dd>
  <dt>
    <code>aAdditionalHeader</code></dt>
  <dd>
    Header added to the URI. e.g., <code>header=filter</code></dd>
</dl>
<h6 id="Return" name="Return">Return</h6>
<p>The {{ Interface("nsIURI") }} that gets run</p>
<h6 id="Example" name="Example">Example</h6>
<p>For example, the next piece of code shows the selected message code on a dialog: (taken from <a class="external" href="http://forums.mozillazine.org/viewtopic.php?t=214824">Mozillazine</a>)</p>
<pre>
  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);
</pre>
<h3 id="messageURIToMsgHdr()">messageURIToMsgHdr()</h3>
<p>Go from message uri to {{ Interface("nsIMsgDBHdr") }}:</p>
<pre class="eval">
 nsIMsgDBHdr messageURIToMsgHdr(in string uri);
</pre>
<h6 id="Parameters_10" name="Parameters_10">Parameters</h6>
<dl>
  <dt>
    <code>uri</code></dt>
  <dd>
    url of the message</dd>
</dl>
<h6 id="Return_2" name="Return_2">Return</h6>
<p>The message's {{ Interface("nsIMsgDBHdr") }}</p>
Revert to this revision