Get Mime Content of outgoing message

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Get Mime Content of outgoing message

karel.gudera
Hello I wonder if there is a way to get mime content of outgoing message.

I can only intercept 'compose-send-message' event and modify subject, body etc.

The only way that comes to my mind is to save message in draft/outbox, then get its MsgDBHdr and use MsgHdrToMimeMessage.
_______________________________________________
dev-apps-thunderbird mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-apps-thunderbird
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Get Mime Content of outgoing message

Patrick Brunschwig-3
On 07.01.17 03:55, [hidden email] wrote:
> Hello I wonder if there is a way to get mime content of outgoing message.
>
> I can only intercept 'compose-send-message' event and modify subject, body etc.
>
> The only way that comes to my mind is to save message in draft/outbox, then get its MsgDBHdr and use MsgHdrToMimeMessage.

You can get the MIME body the way Enigmail and S/MIME do it. See
<https://sourceforge.net/p/enigmail/source/ci/master/tree/package/mimeEncrypt.js>

Plus the chrome registration for
@mozilla.org/messengercompose/composesecure;1 in
<https://sourceforge.net/p/enigmail/source/ci/master/tree/package/chrome.manifest>

-Patrick

_______________________________________________
dev-apps-thunderbird mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-apps-thunderbird
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Get Mime Content of outgoing message

karel.gudera
In reply to this post by karel.gudera
Dne sobota 7. ledna 2017 10:46:50 UTC+1 Patrick Brunschwig napsal(a):

> On 07.01.17 03:55, [hidden email] wrote:
> > Hello I wonder if there is a way to get mime content of outgoing message.
> >
> > I can only intercept 'compose-send-message' event and modify subject, body etc.
> >
> > The only way that comes to my mind is to save message in draft/outbox, then get its MsgDBHdr and use MsgHdrToMimeMessage.
>
> You can get the MIME body the way Enigmail and S/MIME do it. See
> <https://sourceforge.net/p/enigmail/source/ci/master/tree/package/mimeEncrypt.js>
>
> Plus the chrome registration for
> @mozilla.org/messengercompose/composesecure;1 in
> <https://sourceforge.net/p/enigmail/source/ci/master/tree/package/chrome.manifest>
>
> -Patrick

Hi thanks for reply,

I've been browsing the code, but I wasn't able to find what I need.
Although I discovered createRFC822Message method which partially does the job.

let msgSend = Components.classes["@mozilla.org/messengercompose/send;1"]
              .createInstance(Components.interfaces.nsIMsgSend);

var objectArray = GetCurrentEditor().getEmbeddedObjects();
var attachArray = [];
while ( attachEnum.hasMoreElements() )
{
    var attach = attachEnum.getNext().QueryInterface(Components.interfaces.nsIMsgAttachment);
attachArray.push(attach)
}

msgSend.createRFC822Message(getCurrentIdentity(),
                            gMsgCompose.compFields,
                            "text/html",
                            gMsgCompose.editor.outputToString("text/html", 0),
                            false,
                            attachArray,
                            objectArray,
                            gSendListener);

But there are some problems. Sometimes thunderbird fires error GetCurrentEditor().getEmbeddedObjects() is not a function. Another problem is bad encoding of the message.
_______________________________________________
dev-apps-thunderbird mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-apps-thunderbird
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Get Mime Content of outgoing message

Joshua Cranmer 🐧
In reply to this post by karel.gudera
On 1/6/2017 8:55 PM, [hidden email] wrote:
> Hello I wonder if there is a way to get mime content of outgoing message.
>
> I can only intercept 'compose-send-message' event and modify subject, body etc.
>
> The only way that comes to my mind is to save message in draft/outbox, then get its MsgDBHdr and use MsgHdrToMimeMessage.

What are you really trying to do? By design, the compose system hides
the actual building of the MIME text as an implementation detail in a
latter step of the compose process and doesn't really expose it to
add-ons (there is a partial exposure for handling S/MIME that Enigmail
hooks into, but that's not really the solution).

If you're just trying to build a MIME representation for a certain body
+ attachments pair, that's basically what
nsIMsgSend::CreateRFC822Message does (it also adds a whole host of
requisite outgoing headers too). The main compose pipeline instead uses
nsIMsgSend::createAndSendMessage instead, which does conceptually a
not-exposed get-body-from-editor followed by a createRFC822Message and
sendMessageFile [1].

[1] These methods basically form the totality of the interface. The rest
of the interface is a giant mess of leaky abstractions, to the point
that asking to expose any more of the internals would be rejected since
you *really* don't want to have to deal with how annoying it is.

--
Joshua Cranmer
Thunderbird and DXR developer
Source code archæologist

_______________________________________________
dev-apps-thunderbird mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-apps-thunderbird
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Get Mime Content of outgoing message

karel.gudera
Dne neděle 8. ledna 2017 3:10:12 UTC+1 Joshua Cranmer 🐧 napsal(a):

> On 1/6/2017 8:55 PM, [hidden email] wrote:
> > Hello I wonder if there is a way to get mime content of outgoing message.
> >
> > I can only intercept 'compose-send-message' event and modify subject, body etc.
> >
> > The only way that comes to my mind is to save message in draft/outbox, then get its MsgDBHdr and use MsgHdrToMimeMessage.
>
> What are you really trying to do? By design, the compose system hides
> the actual building of the MIME text as an implementation detail in a
> latter step of the compose process and doesn't really expose it to
> add-ons (there is a partial exposure for handling S/MIME that Enigmail
> hooks into, but that's not really the solution).
>
> If you're just trying to build a MIME representation for a certain body
> + attachments pair, that's basically what
> nsIMsgSend::CreateRFC822Message does (it also adds a whole host of
> requisite outgoing headers too). The main compose pipeline instead uses
> nsIMsgSend::createAndSendMessage instead, which does conceptually a
> not-exposed get-body-from-editor followed by a createRFC822Message and
> sendMessageFile [1].
>
> [1] These methods basically form the totality of the interface. The rest
> of the interface is a giant mess of leaky abstractions, to the point
> that asking to expose any more of the internals would be rejected since
> you *really* don't want to have to deal with how annoying it is.
>
> --
> Joshua Cranmer
> Thunderbird and DXR developer
> Source code archæologist

Hi,

Yes I'm trying to build MIME content from body, compFields, attachments etc.
So far it looks good, but I don't know why GetCurrentEditor().getEmbeddedObjects() is randomly causing error.
_______________________________________________
dev-apps-thunderbird mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-apps-thunderbird
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Get Mime Content of outgoing message

karel.gudera
In reply to this post by Joshua Cranmer 🐧
Hello,

I would like to ask one more question about createRFC822Message. When I try to create message with embedded images as I described above, the generated message contains <img alt="" src="file:///home/...">, but I would like to get <img alt="" src="cid:part1.3C8F0CC4...">. What is the reason of this behaviour, is it intended?
_______________________________________________
dev-apps-thunderbird mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-apps-thunderbird
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Get Mime Content of outgoing message

karel.gudera
Well I managed to fix the message with folowing code:

messageSource // MIME message source

// fix embedded images
var inlineAttachments = messageSource.match(/Content-ID:[\s\S]*?Content-Disposition: inline;[\s\S]*?filename=".*?"/gm);
var inlineAttachmentsInfo = [];

    if ( inlineAttachments )
    {
        for ( var i = 0; i < inlineAttachments.length; i++ )
        {
            inlineAttachmentsInfo.push({
              CID : inlineAttachments[i].replace(/Content-ID: <(.*?)>[\s\S]*?Content-Disposition: inline;[\s\S]*?filename="(.*?)"/gm, "$1"),
              name : inlineAttachments[i].replace(/Content-ID: <(.*?)>[\s\S]*?Content-Disposition: inline;[\s\S]*?filename="(.*?)"/gm, "$2")
            });
        }

        for ( var i = 0; i < inlineAttachmentsInfo.length; i++ )
        {
            var re = new RegExp('src=".*' + inlineAttachmentsInfo[i].name + '"', 'gm');
            messageSource = messageSource.replace(re, 'src="cid:' + inlineAttachmentsInfo[i].CID + '"');
        }
    }

But I think it's a sloppy solution and if anyone knows how to generate it right away please let me know.
_______________________________________________
dev-apps-thunderbird mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-apps-thunderbird
Loading...