Re: [gmime-devel] Accessing attachments including inline-parts.



On Sun May 25, 2014 at 18:51:22 -0400, Jeffrey Stedfast wrote:

Right - your current code will only work with GMimeParts and won't
work with GMimeMessageParts because GMimeMessageParts do not subclass
GMimePart and so g_mime_part_*() functions will fail.

  Your explanations always make these things seem so easy.  I'm
 enormously in your debt, once again.

        if (GMIME_IS_MESSAGE_PART (part))
        {
            GMimeMessage *msg = g_mime_message_part_get_message (GMIME_MESSAGE_PART (part));

            g_mime_object_write_to_stream (GMIME_OBJECT (msg), mem);
        }
        else
        {
            GMimeDataWrapper *content = g_mime_part_get_content_object (GMIME_PART (part));

            g_mime_data_wrapper_write_to_stream (content, mem);
        }

  This is the key that I was missing, and now I've got something that
 is working well, so far as I can see, for random mails and the
 problematic one that was reported to me.

  (Subject to bugs porting this 'demo' code into the real application,
  of course.)

        // by setting the owner to FALSE, it means unreffing the memory stream won't
        // free the GByteArray data.
        g_mime_stream_mem_set_owner (GMIME_STREAM_MEM (mem), FALSE);


  That's a good thing to see too, thanks.

        // get the GByteArray data
        adata = g_mime_stream_mem_get_byte_array (GMIME_STREAM_MEM (mem));

  Here we need a "->data" added, rather than just the start of the
  GByteArray, but yeah I've got that now.

I'd recommend replacing the malloc & memcpy logic in CAttachment with
just using the GByteArray to avoid unnecessary overhead of
duplicating the content in memory, but that's up to you.

  That'll have to happen, yes.  For the moment I tend to use malloc
 sparingly and new/delete a few places.  But mostly I just reparse
 things on the heap, so I haven't had to choose a definitive
 memory-strategy.

  (This will change though, if I'm having to reparse multi-Mb PPT
 files, or similar.)

Hopefully my code snippet above helps get you closer.

  Definitely.

There's one last thing you'll need to be aware of with the code
snippet I pasted above, though, which is that the iterator will
descend into attached messages, so you'll be extracting both the
attached messages *and* each of the attachments they contain with the
logic in my snippet above.

  I think that I'll document that and call it a feature...

  My advice to anybody writing a mail client is to stick with mutt .. ;)

Been down that road and scarily enough, I'm half considering going
down that road again. Lord help me.

  Well you obviously understand the MIME parts pretty well.  The other
 half of the job is deciding what user-interface to have, and people
 get very attached to those.  Me?  I always liked mutt-patched with the
 sidebar, and when that broke my client was born.  (Although it looks
 different the feeling is still the same:  Folders -> Indexes ->
 Messages.)



Steve
-- 
http://www.steve.org.uk/


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