MozillaZine

How to get message body?

Talk about add-ons and extension development.
sumanraj
 
Posts: 1
Joined: February 7th, 2005, 6:31 am

Post Posted February 7th, 2005, 6:36 am

Hai,

I am in development of extension for thunderbird. my problem is how do i get the body of the messge with out attachment. i can able to get the full source of the message, i have used below code to get message full source, how can i parse and get only the body of the message or else any other way to get the body of the message.

var content;
var MessageURI = GetFirstSelectedMessage();
var MsgService = messenger.messageServiceFromURI(uri);
var MsgStream = Components.classes["@mozilla.org/network/sync-stream-listener;1"].createInstance();
var MsgStrem_Inputstream = 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) {
return;
}
ScriptInputStream .available();
while (ScriptInputStream .available()) {
content = content + ScriptInputStream .read(512);
}
alert(content);

Great Thanks in Advance!


-Suman Raj.V

Tamas
 
Posts: 2
Joined: January 4th, 2006, 3:25 am
Location: Karlsruhe, D

Post Posted January 4th, 2006, 5:19 am

Hi Sumanraj and Everybody,

I've got a related problem, so I have tried some alternatives. Now I list them, but actually I still do not know how to get the whole message from COMPOSER window.

a,
Because here is the problem:
var MessageURI = GetFirstSelectedMessage(); //no selection is case of composing new mail

b,
There is another thread on the forum:
"How to get the content of selected message?"
http://forums.mozillazine.org/viewtopic.php?t=274891

var dbv = GetDBView(); //does not work in compose window.. :(((
//anyway, i guess the msg is not stored yet in the DB

c,
In general, with the help of "gMsgCompose.compFields" it works reading fields (e.g. from, to, cc, bcc, etc.), BUT the ".body" field does NOT work (empty)!
Recipients2CompFields() //does not help..

d,
var uri = getCurrentIdentity(); //still answers, but is it realy URI??
var msgServ = messenger.messageServiceFromURI(uri); //finally not...

e, (identity interface):
var msgIdent = Components.classes["@mozilla.org/messenger/identity;1"].createInstance(Components.interfaces.nsIMsgIdentity);
var body = msgIdent.body; //no, no, no...

f,
var mailIF = Components.classes["@mozilla.org/messengercompose/mailtourl;1"].createInstance(Components.interfaces.nsIMailtoUrl );
mailIF.GetMessageContents ( toPart , ccPart , bccPart , fromPart , followUpToPart , organizationPart , replyToPart , subjectPart , bodyPart , htmlPart , referencePart , attachmentPart , priorityPart , newsgroupPart , newsHostPart , format );
alert( toPart ); //it does not work

g,
document.getElementById("body").value; //with "msgSubject" it works...

Is it impossible to extract the body (content) of an e-mail from msg composer window??
Thanks!!!
Thomas

Tamas
 
Posts: 2
Joined: January 4th, 2006, 3:25 am
Location: Karlsruhe, D

Post Posted January 20th, 2006, 1:27 am

Meanwhile I've found something related.. in the Autoarchive plugin (from Ausdilecce) the guy has made some magic..
During the send event (probably after) it can extract the whole message.
In case I more time had, i would decode the extension..
Ciao,
Thomas

onegawad
 
Posts: 2
Joined: April 22nd, 2009, 6:05 pm

Post Posted April 22nd, 2009, 11:34 pm

did you ever figure this situation out? I am having the same issue.

mursito
 
Posts: 5
Joined: April 21st, 2009, 11:06 pm

Post Posted April 24th, 2009, 5:32 am

Firstly save the mail as draft before send operation

---------------------------------------------------------------------------------
SaveAsDraft();

var draftUri = gMsgCompose.compFields.draftId;
var msgKey = draftUri.substr(draftUri.indexOf('#') + 1);
var folder = sRDF.GetResource
(gMsgCompose.savedFolderURI).QueryInterface
(Components.interfaces.nsIMsgFolder);

var offset = new Object();
var messageSize = new Object();

try{

var messageStream = folder.getOfflineFileStream
(msgKey,offset,messageSize);
var inputStream = Components.classes["@mozilla.org/
scriptableinputstream;1"].createInstance().QueryInterface
(Components.interfaces.nsIScriptableInputStream);
inputStream.init(messageStream);

var content = "";

while (inputStream.available()) {
content = content + inputStream.read(512);
}

}catch(e){

alert("message: "+e.message);
}

finally you can delete the draft message wiht draft ID

penguin_traveller
 
Posts: 98
Joined: May 25th, 2009, 2:31 am

Post Posted June 10th, 2009, 12:26 pm

sumanraj wrote:Hai,

I am in development of extension for thunderbird. my problem is how do i get the body of the messge with out attachment. i can able to get the full source of the message, i have used below code to get message full source, how can i parse and get only the body of the message or else any other way to get the body of the message.

var content;
var MessageURI = GetFirstSelectedMessage();
var MsgService = messenger.messageServiceFromURI(uri);
var MsgStream = Components.classes["@mozilla.org/network/sync-stream-listener;1"].createInstance();
var MsgStrem_Inputstream = 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) {
return;
}
ScriptInputStream .available();
while (ScriptInputStream .available()) {
content = content + ScriptInputStream .read(512);
}
alert(content);

Great Thanks in Advance!


-Suman Raj.V



There are a couple of errors in the previous post.
Here is the correct code to obtain the message body of the selected message:

var content;
var MessageURI = GetFirstSelectedMessage();
var MsgService = messenger.messageServiceFromURI(MessageURI);
var MsgStream = Components.classes["@mozilla.org/network/sync-stream-listener;1"].createInstance();
var MsgStrem_Inputstream = MsgStream.QueryInterface(Components.interfaces.nsIInputStream);
var ScriptInput = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance();
var ScriptInputStream = ScriptInput .QueryInterface(Components.interfaces.nsIScriptableInputStream);
ScriptInputStream .init(MsgStream);
try
{
MsgService .streamMessage(MessageURI,MsgStream, msgWindow, null, false, null);
}
catch (ex)
{
return;
}
ScriptInputStream .available();
while (ScriptInputStream .available())
{
content = content + ScriptInputStream .read(512);
}
alert(content);

by http://forums.mozillazine.org/memberlist.php?mode=viewprofile&u=226305

Return to Extension Development


Who is online

Users browsing this forum: No registered users and 1 guest