[gmime-devel] Help appreciated adding attachments to outgoing mails



I'm working on (yet another) console-based mail client and I've successfully
ported the majority of my code from using libmimetic to using GMime for
handling mail-parsing, attachment extraction, etc.

I have only one outstanding area which I'm struggling with.  I wish to allow
the user to add attachments to an outgoing messages.  Currently I have a
"simple" email stored as a file, and a vector of attachments which need to
be added.

The simple message looks something like this:

     To: "Bob" <bob example com>
     From: "Moi" <steve example org>
     Subject: This is the subject

     Body text
     Body text more

     Sig
     --

At the moment I'm struggling on where to go from here.  I guess my
code should be parsing this message, then adding the attachment
before serializing it to a (new) file, on-disk.  (From where it can
be piped to sendmail, and written to the sent-mail folder.)

Parsing the message is as simple as:

    GMimeParser *parser;
    GMimeStream *stream;
    int fd;

    if ((fd = open ( filename.c_str(), O_RDONLY, 0)) == -1)
        return;

    stream = g_mime_stream_fs_new (fd);

    parser = g_mime_parser_new_with_stream (stream);
    g_object_unref (stream);

    m_message = g_mime_parser_construct_message (parser);
    g_object_unref (parser);

But from there I'm struggling to understand which parts I need to add.
Clearly I'm going to be looking at an end-result which is multi-part,
rather than the input which is MIME-free.  I'm also looking at the
complex examples/imap-example.c and being a little overwhelmed by
the idea of serializing the final result to a (new) filename.

Any comments/suggestions would be useful.  Frustratingly all the
handling of attachments I could find via online searching were relating
to *extraction*/*decoding* and the test-suit/examples don't seem to
have any code I can be inspired by.

Steve
--

[0] - http://lumail.org/ - Console mail client with Lua scripting.

[1] - Migration to gmime:  https://github.com/skx/lumail/issues/101


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]