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
How to get message body?
-
- Posts: 2
- Joined: January 4th, 2006, 3:25 am
- Location: Karlsruhe, D
How to get the content from composer window?
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
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
-
- Posts: 2
- Joined: January 4th, 2006, 3:25 am
- Location: Karlsruhe, D
-
- Posts: 2
- Joined: April 22nd, 2009, 6:05 pm
Re: How to get message body?
did you ever figure this situation out? I am having the same issue.
-
- Posts: 5
- Joined: April 21st, 2009, 11:06 pm
Re: How to get message body?
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
---------------------------------------------------------------------------------
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
-
- Posts: 98
- Joined: May 25th, 2009, 2:31 am
Re: How to get message body?
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