const gchar* mu_msg_part_get_content_id (MuMsgPart *mpart) { g_return_val_if_fail (mpart, NULL); g_return_val_if_fail (GMIME_IS_OBJECT(mpart->data), NULL); return g_mime_object_get_content_id((GMimeObject*)mpart->data); }
/** * g_mime_multipart_index_of: * @multipart: a #GMimeMultipart object * @part: a #GMimeObject * * Gets the 0-based index of @part within @multipart. * * Returns: the 0-based index of @part within @multipart or %-1 if not found. **/ int g_mime_multipart_index_of (GMimeMultipart *multipart, GMimeObject *part) { g_return_val_if_fail (GMIME_IS_MULTIPART (multipart), -1); g_return_val_if_fail (GMIME_IS_OBJECT (part), -1); return GMIME_MULTIPART_GET_CLASS (multipart)->index_of (multipart, part); }
/** * g_mime_multipart_contains: * @multipart: a #GMimeMultipart object * @part: a #GMimeObject * * Checks if @part is contained within @multipart. * * Returns: %TRUE if @part is a subpart of @multipart or %FALSE * otherwise. **/ gboolean g_mime_multipart_contains (GMimeMultipart *multipart, GMimeObject *part) { g_return_val_if_fail (GMIME_IS_MULTIPART (multipart), FALSE); g_return_val_if_fail (GMIME_IS_OBJECT (part), FALSE); return GMIME_MULTIPART_GET_CLASS (multipart)->contains (multipart, part); }
/** * g_mime_multipart_add: * @multipart: a #GMimeMultipart object * @part: a #GMimeObject * * Appends a mime part to @multipart. **/ void g_mime_multipart_add (GMimeMultipart *multipart, GMimeObject *part) { g_return_if_fail (GMIME_IS_MULTIPART (multipart)); g_return_if_fail (GMIME_IS_OBJECT (part)); GMIME_MULTIPART_GET_CLASS (multipart)->add (multipart, part); }
char* mu_msg_part_get_filename (MuMsgPart *mpart, gboolean construct_if_needed) { g_return_val_if_fail (mpart, NULL); g_return_val_if_fail (GMIME_IS_OBJECT(mpart->data), NULL); return mime_part_get_filename ((GMimeObject*)mpart->data, mpart->index, construct_if_needed); }
/** * g_mime_multipart_insert: * @multipart: a #GMimeMultipart object * @part: a #GMimeObject * @index: the 0-based index to insert the part * * Inserts @part into @multipart at the specified @index. **/ void g_mime_multipart_insert (GMimeMultipart *multipart, int index, GMimeObject *part) { g_return_if_fail (GMIME_IS_MULTIPART (multipart)); g_return_if_fail (GMIME_IS_OBJECT (part)); g_return_if_fail (index >= 0); GMIME_MULTIPART_GET_CLASS (multipart)->insert (multipart, index, part); }
/** * g_mime_multipart_replace: * @multipart: a #GMimeMultipart object * @index: the 0-based index of the part to replace * @replacement: a #GMimeObject to use as the replacement * * Replaces the part at the specified @index within @multipart with * @replacement. * * Returns: (transfer full): the part that was replaced or %NULL * if the part was not contained within the multipart. **/ GMimeObject * g_mime_multipart_replace (GMimeMultipart *multipart, int index, GMimeObject *replacement) { GMimeObject *replaced; g_return_val_if_fail (GMIME_IS_MULTIPART (multipart), NULL); g_return_val_if_fail (GMIME_IS_OBJECT (replacement), NULL); g_return_val_if_fail (index >= 0, NULL); if ((guint) index >= multipart->children->len) return NULL; replaced = multipart->children->pdata[index]; multipart->children->pdata[index] = replacement; g_object_ref (replacement); return replaced; }
MuxMessagePart* mux_message_part_new (const char *path, GMimeObject *mobj) { MuxMessagePart *self; g_return_val_if_fail (path, NULL); g_return_val_if_fail (GMIME_IS_OBJECT(mobj), NULL); self = MUX_MESSAGE_PART(g_object_new(MUX_TYPE_MESSAGE_PART, NULL)); self->path = ext_path (path); self->content_type = g_mime_object_get_content_type (mobj); self->content_id = g_mime_object_get_content_id (mobj); self->content_disposition = g_mime_object_get_content_disposition (mobj); if (GMIME_IS_PART (mobj)) self->file_name = g_mime_part_get_filename ((GMimePart*)mobj); self->mime_object = g_object_ref (mobj); return self; }
char* mu_msg_part_get_text (MuMsg *msg, MuMsgPart *self, MuMsgOptions opts) { GMimeObject *mobj; GMimeMessage *mime_msg; gboolean err; g_return_val_if_fail (msg, NULL); g_return_val_if_fail (self && GMIME_IS_OBJECT(self->data), NULL); mobj = (GMimeObject*)self->data; err = FALSE; if (GMIME_IS_PART (mobj)) { if (self->part_type & MU_MSG_PART_TYPE_TEXT_PLAIN) return mu_msg_mime_part_to_string ((GMimePart*)mobj, &err); else return NULL; /* non-text MimePart */ } mime_msg = NULL; if (GMIME_IS_MESSAGE_PART (mobj)) mime_msg = g_mime_message_part_get_message ((GMimeMessagePart*)mobj); else if (GMIME_IS_MESSAGE (mobj)) mime_msg = (GMimeMessage*)mobj; /* apparently, g_mime_message_part_get_message may still * return NULL */ if (mime_msg) return get_text_from_mime_msg (msg, mime_msg, opts); return NULL; }
/** * Output a list of the parts included in the current message. */ void dump_mail( char *filename ) { std::string result; GMimeMessage *m_message; GMimeParser *parser; GMimeStream *stream; int fd; std::cout << "File: " << filename << std::endl; if ((fd = open( filename, O_RDONLY, 0)) == -1) { std::cout << "Opening failed ..." << std::endl; 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); /** * Create an iterator */ GMimePartIter *iter = g_mime_part_iter_new ((GMimeObject *) m_message); int count = 1; /** * Iterate over the message. */ do { GMimeObject *part = g_mime_part_iter_get_current (iter); if ( ( GMIME_IS_OBJECT( part ) ) && ( GMIME_IS_PART(part) ) ) { /** * Get the content-type */ GMimeContentType *content_type = g_mime_object_get_content_type (part); const char *filename = g_mime_object_get_content_disposition_parameter(part, "filename"); gchar *type = g_mime_content_type_to_string ( content_type ); std::cout << count << " " << type << std::endl; if ( filename ) std::cout << "\t[This is an attachment with file-name " << filename << "]" << std::endl; } /** * Highlight inline parts - which are not attachments. */ GMimeContentDisposition *disp = g_mime_object_get_content_disposition(part); if ( disp != NULL ) { const char *str = g_mime_content_disposition_get_disposition (disp); std::cout << "\tNOTE: Content-Disposition: " << str << std::endl; } count += 1; } while (g_mime_part_iter_next (iter)); g_mime_part_iter_free (iter); g_object_unref(m_message); }
gboolean g_mime_gpgme_mps_sign(GMimeMultipartSigned * mps, GMimeObject * content, const gchar * userid, gpgme_protocol_t protocol, GtkWindow * parent, GError ** err) { GMimeStream *stream; GMimeStream *filtered; GMimeStream *sigstream; GMimeFilter *filter; GMimeContentType *content_type; GMimeDataWrapper *wrapper; GMimeParser *parser; GMimePart *signature; gchar *micalg; const gchar *proto_type; const gchar *sig_subtype; gpgme_hash_algo_t hash_algo; g_return_val_if_fail(GMIME_IS_MULTIPART_SIGNED(mps), FALSE); g_return_val_if_fail(GMIME_IS_OBJECT(content), FALSE); /* Prepare all the parts for signing... */ sign_prepare(content); /* get the cleartext */ stream = g_mime_stream_mem_new(); filtered = g_mime_stream_filter_new(stream); /* Note: see rfc3156, section 3 - second note */ filter = g_mime_filter_from_new(GMIME_FILTER_FROM_MODE_ARMOR); g_mime_stream_filter_add(GMIME_STREAM_FILTER(filtered), filter); g_object_unref(filter); /* Note: see rfc3156, section 5.4 (this is the main difference between rfc2015 and rfc3156) */ filter = g_mime_filter_strip_new(); g_mime_stream_filter_add(GMIME_STREAM_FILTER(filtered), filter); g_object_unref(filter); g_mime_object_write_to_stream(content, filtered); g_mime_stream_flush(filtered); g_object_unref(filtered); g_mime_stream_reset(stream); /* Note: see rfc2015 or rfc3156, section 5.1 */ filtered = g_mime_stream_filter_new(stream); filter = g_mime_filter_crlf_new(TRUE, FALSE); g_mime_stream_filter_add(GMIME_STREAM_FILTER(filtered), filter); g_object_unref(filter); /* construct the signature stream */ sigstream = g_mime_stream_mem_new(); /* sign the content stream */ hash_algo = libbalsa_gpgme_sign(userid, filtered, sigstream, protocol, FALSE, parent, err); g_object_unref(filtered); if (hash_algo == GPGME_MD_NONE) { g_object_unref(sigstream); g_object_unref(stream); return FALSE; } g_mime_stream_reset(sigstream); g_mime_stream_reset(stream); /* set the multipart/signed protocol and micalg */ content_type = g_mime_object_get_content_type(GMIME_OBJECT(mps)); if (protocol == GPGME_PROTOCOL_OpenPGP) { micalg = g_strdup_printf("PGP-%s", gpgme_hash_algo_name(hash_algo)); proto_type = "application/pgp-signature"; sig_subtype = "pgp-signature"; } else { micalg = g_strdup(gpgme_hash_algo_name(hash_algo)); proto_type = "application/pkcs7-signature"; sig_subtype = "pkcs7-signature"; } g_mime_content_type_set_parameter(content_type, "micalg", micalg); g_free(micalg); g_mime_content_type_set_parameter(content_type, "protocol", proto_type); g_mime_multipart_set_boundary(GMIME_MULTIPART(mps), NULL); /* construct the content part */ parser = g_mime_parser_new_with_stream(stream); content = g_mime_parser_construct_part(parser); g_object_unref(stream); g_object_unref(parser); /* construct the signature part */ signature = g_mime_part_new_with_type("application", sig_subtype); wrapper = g_mime_data_wrapper_new(); g_mime_data_wrapper_set_stream(wrapper, sigstream); g_mime_part_set_content_object(signature, wrapper); g_object_unref(sigstream); g_object_unref(wrapper); /* FIXME: temporary hack, this info should probably be set in * the CipherContext class - maybe ::sign can take/output a * GMimePart instead. */ if (protocol == GPGME_PROTOCOL_CMS) { g_mime_part_set_content_encoding(signature, GMIME_CONTENT_ENCODING_BASE64); g_mime_part_set_filename(signature, "smime.p7m"); } /* save the content and signature parts */ /* FIXME: make sure there aren't any other parts?? */ g_mime_multipart_add(GMIME_MULTIPART(mps), content); g_mime_multipart_add(GMIME_MULTIPART(mps), (GMimeObject *) signature); g_object_unref(signature); g_object_unref(content); return TRUE; }
gboolean g_mime_gpgme_mpe_encrypt(GMimeMultipartEncrypted * mpe, GMimeObject * content, GPtrArray * recipients, gboolean trust_all, GtkWindow * parent, GError ** err) { GMimeStream *filtered_stream; GMimeStream *ciphertext; GMimeStream *stream; GMimePart *version_part; GMimePart *encrypted_part; GMimeDataWrapper *wrapper; GMimeFilter *crlf_filter; g_return_val_if_fail(GMIME_IS_MULTIPART_ENCRYPTED(mpe), FALSE); g_return_val_if_fail(GMIME_IS_OBJECT(content), FALSE); /* get the cleartext */ stream = g_mime_stream_mem_new(); filtered_stream = g_mime_stream_filter_new(stream); crlf_filter = g_mime_filter_crlf_new(TRUE, FALSE); g_mime_stream_filter_add(GMIME_STREAM_FILTER(filtered_stream), crlf_filter); g_object_unref(crlf_filter); g_mime_object_write_to_stream(content, filtered_stream); g_mime_stream_flush(filtered_stream); g_object_unref(filtered_stream); /* reset the content stream */ g_mime_stream_reset(stream); /* encrypt the content stream */ ciphertext = g_mime_stream_mem_new(); if (!libbalsa_gpgme_encrypt (recipients, NULL, stream, ciphertext, GPGME_PROTOCOL_OpenPGP, FALSE, trust_all, parent, err)) { g_object_unref(ciphertext); g_object_unref(stream); return FALSE; } g_object_unref(stream); g_mime_stream_reset(ciphertext); /* construct the version part */ version_part = g_mime_part_new_with_type("application", "pgp-encrypted"); g_mime_part_set_content_encoding(version_part, GMIME_CONTENT_ENCODING_7BIT); stream = g_mime_stream_mem_new_with_buffer("Version: 1\n", strlen("Version: 1\n")); wrapper = g_mime_data_wrapper_new_with_stream(stream, GMIME_CONTENT_ENCODING_7BIT); g_mime_part_set_content_object(version_part, wrapper); g_object_unref(wrapper); g_object_unref(stream); /* construct the encrypted mime part */ encrypted_part = g_mime_part_new_with_type("application", "octet-stream"); g_mime_part_set_content_encoding(encrypted_part, GMIME_CONTENT_ENCODING_7BIT); wrapper = g_mime_data_wrapper_new_with_stream(ciphertext, GMIME_CONTENT_ENCODING_7BIT); g_mime_part_set_content_object(encrypted_part, wrapper); g_object_unref(ciphertext); g_object_unref(wrapper); /* save the version and encrypted parts */ /* FIXME: make sure there aren't any other parts?? */ g_mime_multipart_add(GMIME_MULTIPART(mpe), GMIME_OBJECT(version_part)); g_mime_multipart_add(GMIME_MULTIPART(mpe), GMIME_OBJECT(encrypted_part)); g_object_unref(encrypted_part); g_object_unref(version_part); /* set the content-type params for this multipart/encrypted part */ g_mime_object_set_content_type_parameter(GMIME_OBJECT(mpe), "protocol", "application/pgp-encrypted"); g_mime_multipart_set_boundary(GMIME_MULTIPART(mpe), NULL); return TRUE; }