GObject type assertion in GMime when parsing spam: Refs #7034

Won't close this quite yet because this workaround shouldn't be
necessary, and introduces a memory copy when dealing with message
headers and bodies, which we'd like to avoid.
This commit is contained in:
Jim Nelson 2013-06-07 14:36:31 -07:00
parent c9a138ada3
commit 870094e9ee

View file

@ -47,11 +47,19 @@ public class Geary.RFC822.Message : BaseObject {
}
public Message.from_parts(Header header, Text body) throws RFC822Error {
GMime.StreamCat stream_cat = new GMime.StreamCat();
stream_cat.add_source(new GMime.StreamMem.with_buffer(header.buffer.get_array()));
stream_cat.add_source(new GMime.StreamMem.with_buffer(body.buffer.get_array()));
// Had some problems with GMime not parsing a message when using a StreamCat, so
// manually copy them into a single buffer and decode that way; see
// http://redmine.yorba.org/issues/7034
// and
// https://bugzilla.gnome.org/show_bug.cgi?id=701572
//
// TODO: When fixed in GMime, return to original behavior of streaming each buffer in
uint8[] buffer = new uint8[header.buffer.get_size() + body.buffer.get_size()];
uint8* ptr = buffer;
GLib.Memory.copy(ptr, header.buffer.get_array(), header.buffer.get_size());
GLib.Memory.copy(ptr + header.buffer.get_size(), body.buffer.get_array(), body.buffer.get_size());
GMime.Parser parser = new GMime.Parser.with_stream(stream_cat);
GMime.Parser parser = new GMime.Parser.with_stream(new GMime.StreamMem.with_buffer(buffer));
message = parser.construct_message();
if (message == null)
throw new RFC822Error.INVALID("Unable to parse RFC 822 message");