Esempio n. 1
0
/**
 *
 * "util_get_msg_body" is based on mail-to-task eplugin's get_description function.
 * which is GPL licensed.
 * */
static gchar *
util_get_msg_body(CamelMimeMessage *message, gchar **text) {
   CamelDataWrapper *content;
   CamelStream *mem;
   CamelContentType *type;
   CamelMimePart *mime_part = CAMEL_MIME_PART(message);

   GSList sl;
   gchar *str, *convert_str = NULL;
   gsize bytes_read, bytes_written;
   gint count = 2;

   content = camel_medium_get_content_object((CamelMedium *) message);

   if (!content)
      return;

   /*
    * Get non-multipart content from multipart message.
    */
   while (CAMEL_IS_MULTIPART(content) && count > 0) {
      mime_part = camel_multipart_get_part(CAMEL_MULTIPART(content), 0);
      content = camel_medium_get_content_object(CAMEL_MEDIUM(mime_part));
      count--;
   }

   if (!mime_part)
      return;

   type = camel_mime_part_get_content_type(mime_part);
   if (!camel_content_type_is(type, "text", "plain"))
      return;

   mem = camel_stream_mem_new();
   camel_data_wrapper_decode_to_stream(content, mem);

   str = g_strndup((const gchar *) ((CamelStreamMem *) mem)->buffer->data, ((CamelStreamMem *) mem)->buffer->len);
   camel_object_unref(mem);

   /* convert to UTF-8 string */
   if (str && content->mime_type->params && content->mime_type->params->value) {
      convert_str = g_convert(str, strlen(str),
            "UTF-8", content->mime_type->params->value,
            &bytes_read, &bytes_written, NULL);
   }

   if (convert_str)
      *text = convert_str;
   else
      *text = str;

   /*g_free (str);
     if (convert_str)
     g_free (convert_str);
     */
}
static char *
save_attachment (CamelMimePart * part, const char *uid,
                 const char *attachment_store)
{
    CamelDataWrapper *content;
    CamelStream *stream = NULL;
    CamelStreamFs *stream_fs;
    char *attach_file = NULL;
    char *file_url = NULL;
    const char *mime_filename;

    content = camel_medium_get_content_object (CAMEL_MEDIUM (part));
    mime_filename = camel_mime_part_get_filename (part);

    attach_file = g_strdup_printf ("%s/%s-%s",
                                   attachment_store, uid, mime_filename);

    stream = camel_stream_fs_new_with_name (attach_file,
                                            O_RDWR | O_CREAT | O_TRUNC, 0600);

    if (stream == NULL)
        goto end;

    stream_fs = (CamelStreamFs *) stream;
    camel_data_wrapper_decode_to_stream (content, stream);
    file_url = g_strdup_printf ("file://%s", attach_file);

  end:
    g_free (attach_file);
    camel_object_unref (stream);

    return file_url;
}
Esempio n. 3
0
/* there is also an identical copy of this in camel-filter-search.c */
gboolean
camel_search_message_body_contains (CamelDataWrapper *object, regex_t *pattern)
{
	CamelDataWrapper *containee;
	int truth = FALSE;
	int parts, i;

	containee = camel_medium_get_content_object (CAMEL_MEDIUM (object));

	if (containee == NULL)
		return FALSE;

	/* using the object types is more accurate than using the mime/types */
	if (CAMEL_IS_MULTIPART (containee)) {
		parts = camel_multipart_get_number (CAMEL_MULTIPART (containee));
		for (i = 0; i < parts && truth == FALSE; i++) {
			CamelDataWrapper *part = (CamelDataWrapper *)camel_multipart_get_part (CAMEL_MULTIPART (containee), i);
			if (part)
				truth = camel_search_message_body_contains (part, pattern);
		}
	} else if (CAMEL_IS_MIME_MESSAGE (containee)) {
		/* for messages we only look at its contents */
		truth = camel_search_message_body_contains ((CamelDataWrapper *)containee, pattern);
	} else if (camel_content_type_is(CAMEL_DATA_WRAPPER (containee)->mime_type, "text", "*")) {
		/* for all other text parts, we look inside, otherwise we dont care */
		CamelStreamMem *mem = (CamelStreamMem *)camel_stream_mem_new ();

		camel_data_wrapper_write_to_stream (containee, CAMEL_STREAM (mem));
		camel_stream_write (CAMEL_STREAM (mem), "", 1);
		truth = regexec (pattern, (char *) mem->buffer->data, 0, NULL, 0) == 0;
		camel_object_unref (mem);
	}

	return truth;
}
Esempio n. 4
0
void
org_gnome_prefer_plain_multipart_alternative(void *ep, EMFormatHookTarget *t)
{
	CamelMultipart *mp = (CamelMultipart *)camel_medium_get_content_object((CamelMedium *)t->part);
	CamelMimePart *part, *display_part = NULL;
	int i, nparts, partidlen, displayid = 0;

	if (epp_mode == EPP_NORMAL) {
		/* Try to find text/html part even when not as last and force to show it.
		   Old handler will show the last part of multipart/alternate, but if we
		   can offer HTML, then offer it, regardless of position in multipart. */
		nparts = camel_multipart_get_number (mp);
		for (i = 0; i < nparts; i++) {
			part = camel_multipart_get_part (mp, i);
			if (part && camel_content_type_is (camel_mime_part_get_content_type (part), "text", "html")) {
				displayid = i;
				display_part = part;
				break;
			}
		}

		if (display_part) {
			g_string_append_printf (t->format->part_id, ".alternative.%d", displayid);
			em_format_part_as (t->format, t->stream, display_part, "text/html");
			g_string_truncate (t->format->part_id, partidlen);
		} else {
			t->item->handler.old->handler (t->format, t->stream, t->part, t->item->handler.old);
		}
		return;
	} else if (!CAMEL_IS_MULTIPART(mp)) {
		em_format_format_source(t->format, t->stream, t->part);
		return;
	}

	nparts = camel_multipart_get_number(mp);
	for (i=0; i<nparts; i++) {
		part = camel_multipart_get_part(mp, i);
		if (part && camel_content_type_is(camel_mime_part_get_content_type(part), "text", "plain")) {
			displayid = i;
			display_part = part;
			break;
		}
	}

	/* this part-id stuff is poking private data, needs api */
	partidlen = t->format->part_id->len;

	/* if we found a text part, show it */
	if (display_part) {
		g_string_append_printf(t->format->part_id, ".alternative.%d", displayid);
		em_format_part_as(t->format, t->stream, display_part, "text/plain");
		g_string_truncate(t->format->part_id, partidlen);
	}

	/* all other parts are attachments */
	export_as_attachments (mp, t->format, t->stream, display_part);

	g_string_truncate(t->format->part_id, partidlen);
}
Esempio n. 5
0
/**
 *
 * It dumps attachments to /tmp
 *
 **/
void
util_attachments_to_files(CamelMimeMessage *message) {
   gint parts, i = 0;

   char *store_dir;
   CamelDataWrapper *content = NULL;

   content = camel_medium_get_content_object((CamelMedium *) message);
   if (!content || !CAMEL_IS_MULTIPART(content))
      return;

   parts = camel_multipart_get_number(CAMEL_MULTIPART(content));
   if (parts < 1)
      return;

   store_dir = "/tmp"; // TODO home

   for (i = 1; i < parts; i++) {
      gchar *filename = NULL;
      gchar *path = NULL;
      gchar *tmp = NULL;
      const gchar *orig_filename = NULL;
      CamelMimePart *mime_part = camel_multipart_get_part(CAMEL_MULTIPART(content), i);

      orig_filename = camel_mime_part_get_filename(mime_part);
      g_debug("Orig filename : %s\n", orig_filename);
      if (orig_filename == NULL) {
         g_print("Esto es un adjunto distinto.");
         orig_filename = camel_mime_part_get_description(mime_part);
      }
      if (!orig_filename)
         continue;

      tmp = clean_name((const guchar *) orig_filename);

      filename = g_strdup_printf("%s-%s", "evosugar", tmp);
      path = g_build_filename(store_dir, filename, NULL);
      g_debug("Attach. to file : %s\n", path);
      BREAKPOINT;
      // TODO should be done in another thread
      if (em_utils_save_part_to_file(NULL, path, mime_part)) {
         gchar *uri;
         BREAKPOINT;
         uri = g_filename_to_uri(path, NULL, NULL);
         BREAKPOINT;
         g_free(uri);
      }
      BREAKPOINT;
      g_free(tmp);
      BREAKPOINT;
      g_free(filename);
      BREAKPOINT;
      g_free(path);
      BREAKPOINT;
   }

   //g_free (store_dir);
}
static gboolean
set_ical_from_mime_part (CamelMimePart * part, ScalixObject * object)
{
    CamelDataWrapper *content;
    CamelStream *stream;
    GByteArray *data;
    icalcomponent *icomp = NULL;
    icalcomponent *subcomp = NULL;
    ScalixAppointmentPrivate *priv;

    priv = SCALIX_APPOINTMENT_GET_PRIVATE (SCALIX_APPOINTMENT (object));

    content = camel_medium_get_content_object (CAMEL_MEDIUM (part));

    data = g_byte_array_new ();
    stream = camel_stream_mem_new_with_byte_array (data);
    camel_data_wrapper_decode_to_stream (content, stream);

    if (data == NULL || data->data == NULL) {
        g_print ("Found corrupt ical data\n");
        return FALSE;
    }

    icomp = icalparser_parse_string ((const char *) data->data);

    if (icalcomponent_isa (icomp) != ICAL_VCALENDAR_COMPONENT) {
        icalcomponent_free (icomp);
        return FALSE;
    }

    /* Grab the timezone if any */
    subcomp = icalcomponent_get_first_component (icomp,
                                                 ICAL_VTIMEZONE_COMPONENT);
    if (subcomp != NULL) {
        icaltimezone *zone;

        zone = icaltimezone_new ();
        icaltimezone_set_component (zone, subcomp);
        priv->timezone = zone;
    }

    /* Grab the main VEVENT */
    subcomp = icalcomponent_get_first_component (icomp, ICAL_VEVENT_COMPONENT);

    e_cal_component_set_icalcomponent (E_CAL_COMPONENT (object), subcomp);

    return TRUE;
}
Esempio n. 7
0
static void
export_as_attachments (CamelMultipart *mp, EMFormat *format, CamelStream *stream, CamelMimePart *except)
{
	int i, nparts, partidlen;
	CamelMimePart *part;

	if (!mp || !CAMEL_IS_MULTIPART (mp))
		return;

	partidlen = format->part_id->len;

	nparts = camel_multipart_get_number(mp);
	for (i = 0; i < nparts; i++) {
		part = camel_multipart_get_part (mp, i);

		if (part != except) {
			CamelMultipart *multipart = (CamelMultipart *)camel_medium_get_content_object((CamelMedium *)part);

			if (CAMEL_IS_MULTIPART (multipart)) {
				export_as_attachments (multipart, format, stream, except);
			} else {
				g_string_append_printf (format->part_id, ".alternative.%d", i);

				if (camel_content_type_is (camel_mime_part_get_content_type (part), "text", "html")) {
					/* always show HTML as attachments and not inline */
					camel_mime_part_set_disposition (part, "attachment");

					if (!camel_mime_part_get_filename (part)) {
						char *str = g_strdup_printf ("%s.html", _("attachment"));
						camel_mime_part_set_filename (part, str);
						g_free (str);
					}

					em_format_part_as (format, stream, part, "application/octet-stream");
				} else
					em_format_part (format, stream, part);

				g_string_truncate (format->part_id, partidlen);
			}
		}
	}
}
Esempio n. 8
0
/**
 *
 * It stores the attachment list into the model.
 * */
GtkTreeModel *
util_get_msg_attachments(CamelMimeMessage *message) {
   gint parts, i = 0;
   GtkTreeIter iter;
   CamelDataWrapper *content = NULL;
   GtkTreeStore *tree_store = gtk_tree_store_new(2, G_TYPE_BOOLEAN, G_TYPE_STRING);

   content = camel_medium_get_content_object((CamelMedium *) message);
   if (!content || !CAMEL_IS_MULTIPART(content))
      return;

   parts = camel_multipart_get_number(CAMEL_MULTIPART(content));
   if (parts < 1)
      return;

   for (i = 1; i < parts; i++) {
      const gchar *orig_filename;
      CamelMimePart *mime_part;

      mime_part = camel_multipart_get_part(CAMEL_MULTIPART(content), i);

      orig_filename = camel_mime_part_get_filename(mime_part);
      if (orig_filename == NULL) {
         g_debug("No hay filename, esto es un adjunto distinto.\n");
         orig_filename = camel_mime_part_get_description(mime_part);
      }


      gtk_tree_store_append(tree_store, &iter, NULL);
      gtk_tree_store_set(tree_store, &iter, 0, TRUE,
            1, orig_filename, -1);

      g_print("Orig filename : %s\n", orig_filename);
      if (!orig_filename)
         continue;

      BREAKPOINT;
   }

   return GTK_TREE_MODEL(tree_store);
}
gboolean
scalix_appointment_init_from_mime_message (ScalixObject * object,
                                           CamelMimeMessage * msg)
{
    const char *msgid;
    const char *attachment_store;
    const char *mime_type, *alternative_mime_type;
    const char *content_disposition;
    const char *mime_filename;
    const char *cid;
    const char *cuid;
    const char *attachment_file_url;
    GSList *attachments = NULL;
    GSList *attachments_new = NULL;
    GSList *siter = NULL;
    CamelMimePart *part, *alternative;
    CamelMultipart *multipart, *nested_multipart;
    CamelDataWrapper *content, *alternative_content;
    int i, j, num_parts, num_alternatives;
    gboolean found_ical = FALSE;

    attachment_store =
        g_object_get_data (G_OBJECT (object), "attachment-store");

    part = CAMEL_MIME_PART (msg);
    content = camel_medium_get_content_object (CAMEL_MEDIUM (part));

    if (content == NULL) {
        return FALSE;
    }

    mime_type = camel_content_type_simple (content->mime_type);

    if (CAMEL_IS_MULTIPART (content)) {
        multipart = (CamelMultipart *) content;
        num_parts = (int) camel_multipart_get_number (multipart);

        for (i = 0; i < num_parts; i++) {
            part = camel_multipart_get_part (multipart, i);
            content = camel_medium_get_content_object (CAMEL_MEDIUM (part));
            mime_type = camel_content_type_simple (content->mime_type);
            mime_filename = camel_mime_part_get_filename (part);
            content_disposition = camel_mime_part_get_disposition (part);

            if (CAMEL_IS_MULTIPART (content)) {
                nested_multipart = (CamelMultipart *) content;
                num_alternatives =
                    (int) camel_multipart_get_number (nested_multipart);
                for (j = 0; j < num_alternatives; j++) {
                    alternative =
                        camel_multipart_get_part (nested_multipart, j);
                    alternative_content =
                        camel_medium_get_content_object (CAMEL_MEDIUM
                                                         (alternative));
                    alternative_mime_type =
                        camel_content_type_simple (alternative_content->
                                                   mime_type);
                    if (g_str_equal (alternative_mime_type, "text/calendar")
                        && found_ical == FALSE) {
                        if (set_ical_from_mime_part (alternative, object) ==
                            TRUE) {
                            e_cal_component_get_uid (E_CAL_COMPONENT (object),
                                                     &cuid);
                            e_cal_component_get_attachment_list (E_CAL_COMPONENT
                                                                 (object),
                                                                 &attachments);
                            /* we are only interested in the first ical body part */
                            found_ical = TRUE;
                        }
                    }
                }
            } else if (g_str_equal (mime_type, "text/calendar")
                       && found_ical == FALSE) {
                if (set_ical_from_mime_part (part, object) == TRUE) {
                    e_cal_component_get_uid (E_CAL_COMPONENT (object), &cuid);
                    e_cal_component_get_attachment_list (E_CAL_COMPONENT
                                                         (object),
                                                         &attachments);
                    /* we are only interested in the first ical body part */
                    found_ical = TRUE;
                }
            } else if (content_disposition
                       && strcmp (content_disposition, "attachment") == 0) {
                cid = camel_mime_part_get_content_id (part);
                if (cid != NULL) {
                    for (siter = attachments; siter; siter = siter->next) {
                        if (strstr (siter->data, cid) ==
                            (char *) (siter->data) + 4) {
                            attachment_file_url =
                                save_attachment (part, cuid, attachment_store);
                            if (attachment_file_url != NULL) {
                                attachments_new =
                                    g_slist_append (attachments_new,
                                                    g_strdup
                                                    (attachment_file_url));
                            }
                        }
                    }
                }
            } else {
                g_print ("XXXXX Unhandled mime part: %s\n", mime_type);
            }
        }
    } else {
        /* just a simple ical message */
        if (g_str_equal (mime_type, "text/calendar")) {
            set_ical_from_mime_part (part, object);
        }
    }

    if (attachments_new != NULL) {
        e_cal_component_set_attachment_list (E_CAL_COMPONENT (object),
                                             attachments_new);
    }

    msgid = camel_mime_message_get_message_id (msg);

    scalix_appointment_unset (SCALIX_APPOINTMENT (object), X_SCALIX_MSG_ID);

    scalix_appointment_set (SCALIX_APPOINTMENT (object),
                            X_SCALIX_MSG_ID, msgid);

    return TRUE;
}
Esempio n. 10
0
static CamelCipherValidity *
sm_decrypt(CamelCipherContext *context, CamelMimePart *ipart, CamelMimePart *opart, CamelException *ex)
{
	NSSCMSDecoderContext *dec;
	NSSCMSMessage *cmsg;
	CamelStreamMem *istream;
	CamelStream *ostream;
	CamelCipherValidity *valid = NULL;

	/* FIXME: This assumes the content is only encrypted.  Perhaps its ok for
	   this api to do this ... */

	ostream = camel_stream_mem_new();
	camel_stream_mem_set_secure((CamelStreamMem *)ostream);

	/* FIXME: stream this to the decoder incrementally */
	istream = (CamelStreamMem *)camel_stream_mem_new();
	camel_data_wrapper_decode_to_stream(camel_medium_get_content_object((CamelMedium *)ipart), (CamelStream *)istream);
	camel_stream_reset((CamelStream *)istream);

	dec = NSS_CMSDecoder_Start(NULL,
				   sm_write_stream, ostream, /* content callback     */
				   NULL, NULL,
				   NULL, NULL); /* decrypt key callback */

	if (NSS_CMSDecoder_Update(dec, (char *) istream->buffer->data, istream->buffer->len) != SECSuccess) {
		printf("decoder update failed\n");
	}
	camel_object_unref(istream);

	cmsg = NSS_CMSDecoder_Finish(dec);
	if (cmsg == NULL) {
		camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, _("Decoder failed, error %d"), PORT_GetError());
		goto fail;
	}

#if 0
	/* not sure if we really care about this? */
	if (!NSS_CMSMessage_IsEncrypted(cmsg)) {
		camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, _("S/MIME Decrypt: No encrypted content found"));
		NSS_CMSMessage_Destroy(cmsg);
		goto fail;
	}
#endif

	camel_stream_reset(ostream);
	camel_data_wrapper_construct_from_stream((CamelDataWrapper *)opart, ostream);

	if (NSS_CMSMessage_IsSigned(cmsg)) {
		valid = sm_verify_cmsg(context, cmsg, NULL, ex);
	} else {
		valid = camel_cipher_validity_new();
		valid->encrypt.description = g_strdup(_("Encrypted content"));
		valid->encrypt.status = CAMEL_CIPHER_VALIDITY_ENCRYPT_ENCRYPTED;
	}

	NSS_CMSMessage_Destroy(cmsg);
fail:
	camel_object_unref(ostream);

	return valid;
}
Esempio n. 11
0
static CamelCipherValidity *
sm_verify(CamelCipherContext *context, CamelMimePart *ipart, CamelException *ex)
{
	NSSCMSDecoderContext *dec;
	NSSCMSMessage *cmsg;
	CamelStreamMem *mem;
	CamelStream *constream = NULL;
	CamelCipherValidity *valid = NULL;
	CamelContentType *ct;
	const char *tmp;
	CamelMimePart *sigpart;
	CamelDataWrapper *dw;

	dw = camel_medium_get_content_object((CamelMedium *)ipart);
	ct = dw->mime_type;

	/* FIXME: we should stream this to the decoder */
	mem = (CamelStreamMem *)camel_stream_mem_new();

	if (camel_content_type_is(ct, "multipart", "signed")) {
		CamelMultipart *mps = (CamelMultipart *)dw;

		tmp = camel_content_type_param(ct, "protocol");
		if (!CAMEL_IS_MULTIPART_SIGNED(mps)
		    || tmp == NULL
		    || (g_ascii_strcasecmp(tmp, context->sign_protocol) != 0
			&& g_ascii_strcasecmp(tmp, "application/pkcs7-signature") != 0)) {
			camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
					     _("Cannot verify message signature: Incorrect message format"));
			goto fail;
		}

		constream = camel_multipart_signed_get_content_stream((CamelMultipartSigned *)mps, ex);
		if (constream == NULL)
			goto fail;

		sigpart = camel_multipart_get_part(mps, CAMEL_MULTIPART_SIGNED_SIGNATURE);
		if (sigpart == NULL) {
			camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
					     _("Cannot verify message signature: Incorrect message format"));
			goto fail;
		}
	} else if (camel_content_type_is(ct, "application", "x-pkcs7-mime")) {
		sigpart = ipart;
	} else {
		camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
				     _("Cannot verify message signature: Incorrect message format"));
		goto fail;
	}

	dec = NSS_CMSDecoder_Start(NULL,
				   NULL, NULL, /* content callback     */
				   NULL, NULL, 	/* password callback    */
				   NULL, NULL); /* decrypt key callback */

	camel_data_wrapper_decode_to_stream(camel_medium_get_content_object((CamelMedium *)sigpart), (CamelStream *)mem);
	(void)NSS_CMSDecoder_Update(dec, (char *) mem->buffer->data, mem->buffer->len);
	cmsg = NSS_CMSDecoder_Finish(dec);
	if (cmsg == NULL) {
		camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, _("Decoder failed"));
		goto fail;
	}

	valid = sm_verify_cmsg(context, cmsg, constream, ex);

	NSS_CMSMessage_Destroy(cmsg);
fail:
	camel_object_unref(mem);
	if (constream)
		camel_object_unref(constream);

	return valid;
}
Esempio n. 12
0
/* TODO: This is suboptimal, but the only other solution is to pass around NSSCMSMessages */
guint32
camel_smime_context_describe_part(CamelSMIMEContext *context, CamelMimePart *part)
{
	guint32 flags = 0;
	CamelContentType *ct;
	const char *tmp;

	if (!part)
		return flags;

	ct = camel_mime_part_get_content_type(part);

	if (camel_content_type_is(ct, "multipart", "signed")) {
		tmp = camel_content_type_param(ct, "protocol");
		if (tmp &&
		    (g_ascii_strcasecmp(tmp, ((CamelCipherContext *)context)->sign_protocol) == 0
		     || g_ascii_strcasecmp(tmp, "application/pkcs7-signature") == 0))
			flags = CAMEL_SMIME_SIGNED;
	} else if (camel_content_type_is(ct, "application", "x-pkcs7-mime")) {
		CamelStreamMem *istream;
		NSSCMSMessage *cmsg;
		NSSCMSDecoderContext *dec;

		/* FIXME: stream this to the decoder incrementally */
		istream = (CamelStreamMem *)camel_stream_mem_new();
		camel_data_wrapper_decode_to_stream(camel_medium_get_content_object((CamelMedium *)part), (CamelStream *)istream);
		camel_stream_reset((CamelStream *)istream);

		dec = NSS_CMSDecoder_Start(NULL,
					   NULL, NULL,
					   NULL, NULL,	/* password callback    */
					   NULL, NULL); /* decrypt key callback */

		NSS_CMSDecoder_Update(dec, (char *) istream->buffer->data, istream->buffer->len);
		camel_object_unref(istream);

		cmsg = NSS_CMSDecoder_Finish(dec);
		if (cmsg) {
			if (NSS_CMSMessage_IsSigned(cmsg)) {
				printf("message is signed\n");
				flags |= CAMEL_SMIME_SIGNED;
			}

			if (NSS_CMSMessage_IsEncrypted(cmsg)) {
				printf("message is encrypted\n");
				flags |= CAMEL_SMIME_ENCRYPTED;
			}
#if 0
			if (NSS_CMSMessage_ContainsCertsOrCrls(cmsg)) {
				printf("message contains certs or crls\n");
				flags |= CAMEL_SMIME_CERTS;
			}
#endif
			NSS_CMSMessage_Destroy(cmsg);
		} else {
			printf("Message could not be parsed\n");
		}
	}

	return flags;
}
Esempio n. 13
0
void
org_gnome_format_tnef(void *ep, EMFormatHookTarget *t)
{
	char *tmpdir = NULL, *name = NULL;
	CamelStream *out;
	struct dirent *d;
	DIR *dir;
	CamelMultipart *mp;
	CamelMimePart *mainpart;
	CamelDataWrapper *content;
	int len;
	TNEFStruct *tnef;
	tnef = (TNEFStruct *) g_malloc(sizeof(TNEFStruct));

	tmpdir = e_mkdtemp("tnef-attachment-XXXXXX");
	if (tmpdir == NULL)
		return;

	filepath = tmpdir;

	name = g_build_filename(tmpdir, ".evo-attachment.tnef", NULL);

	out = camel_stream_fs_new_with_name(name, O_RDWR|O_CREAT, 0666);
	if (out == NULL)
	    goto fail;
	content = camel_medium_get_content_object((CamelMedium *)t->part);
	if (content == NULL)
		goto fail;
	if (camel_data_wrapper_decode_to_stream(content, out) == -1
	    || camel_stream_close(out) == -1) {
		camel_object_unref(out);
 		goto fail;
	}
	camel_object_unref(out);

	/* Extracting the winmail.dat */
        TNEFInitialize(tnef);
	tnef->Debug = verbose;
        if (TNEFParseFile(name, tnef) == -1) {
            printf("ERROR processing file\n");
        }
	processTnef(tnef);

        TNEFFree(tnef);
	/* Extraction done */

	dir = opendir(tmpdir);
	if (dir == NULL)
	    goto fail;

	mainpart = camel_mime_part_new();

	mp = camel_multipart_new();
	camel_data_wrapper_set_mime_type((CamelDataWrapper *)mp, "multipart/mixed");
	camel_multipart_set_boundary(mp, NULL);

	camel_medium_set_content_object((CamelMedium *)mainpart, (CamelDataWrapper *)mp);

	while ((d = readdir(dir))) {
		CamelMimePart *part;
		CamelDataWrapper *content;
		CamelStream *stream;
		char *path;
		const char *type;

		if (!strcmp(d->d_name, ".")
		    || !strcmp(d->d_name, "..")
		    || !strcmp(d->d_name, ".evo-attachment.tnef"))
		    continue;

		path = g_build_filename(tmpdir, d->d_name, NULL);

		stream = camel_stream_fs_new_with_name(path, O_RDONLY, 0);
		content = camel_data_wrapper_new();
		camel_data_wrapper_construct_from_stream(content, stream);
		camel_object_unref(stream);

		part = camel_mime_part_new();
		camel_mime_part_set_encoding(part, CAMEL_TRANSFER_ENCODING_BINARY);

		camel_medium_set_content_object((CamelMedium *)part, content);
		camel_object_unref(content);

		type = em_utils_snoop_type(part);
		if (type)
		    camel_data_wrapper_set_mime_type((CamelDataWrapper *)part, type);

		camel_mime_part_set_filename(part, d->d_name);

		g_free(path);

		camel_multipart_add_part(mp, part);
	}

	closedir(dir);

	len = t->format->part_id->len;
	g_string_append_printf(t->format->part_id, ".tnef");

	if (camel_multipart_get_number(mp) > 0)
		em_format_part_as(t->format, t->stream, mainpart, "multipart/mixed");
	else if (t->item->handler.old)
	    t->item->handler.old->handler(t->format, t->stream, t->part, t->item->handler.old);

	g_string_truncate(t->format->part_id, len);

	camel_object_unref(mainpart);

	goto ok;
 fail:
	if (t->item->handler.old)
	    t->item->handler.old->handler(t->format, t->stream, t->part, t->item->handler.old);
 ok:
	g_free(name);
	g_free(tmpdir);
}
Esempio n. 14
0
static void
fill_model_rec(CamelMimeMessage *msg, CamelMimePart *part, GtkTreeStore *model, GtkTreeIter *parent, GString *name)
{
	CamelDataWrapper *containee;
	int parts, i;
	char *type;
	GtkTreeIter iter;
	int len = name->len;
	CamelContentType *mime;

	containee = camel_medium_get_content_object((CamelMedium *)part);
	if (containee == NULL)
		return;

	mime = ((CamelDataWrapper *)containee)->mime_type;
	type = camel_content_type_simple(mime);

	if (CAMEL_IS_MULTIPART(containee)) {
		gtk_tree_store_append(model, &iter, parent);
		g_string_append_printf(name, ".multipart");
		gtk_tree_store_set(model, &iter, 0, FALSE, 1, type, 2, name->str, 3, name->str, 4, part, -1);

		parts = camel_multipart_get_number((CamelMultipart *)containee);
		for (i = 0; i < parts; i++) {
			CamelMimePart *mpart = camel_multipart_get_part((CamelMultipart *)containee, i);

			g_string_truncate(name, len);
			g_string_append_printf(name, ".%d", i);
			fill_model_rec(msg, mpart, model, &iter, name);
		}
	} else if (CAMEL_IS_MIME_MESSAGE(containee)) {
		gtk_tree_store_append(model, &iter, parent);
		g_string_append_printf(name, ".msg");
		gtk_tree_store_set(model, &iter, 0, FALSE, 1, type, 2, name->str, 3, name->str, 4, part, -1);
		fill_model_rec(msg, (CamelMimePart *)containee, model, &iter, name);
	} else {
		char *filename = NULL;
		const char *ext = NULL, *tmp;
		int save = FALSE;

		gtk_tree_store_append(model, &iter, parent);
		tmp = camel_mime_part_get_filename(part);
		if (tmp) {
			filename = clean_name(tmp);
			ext = strrchr(filename, '.');
		}
		tmp = camel_mime_part_get_disposition(part);
		if (tmp && !strcmp(tmp, "attachment"))
			save = TRUE;

		if (camel_content_type_is(mime, "text", "*")) {
			if (ext == NULL) {
				if ((ext = mime->subtype) == NULL || !strcmp(ext, "plain"))
					ext = "text";
			}
		} else if (camel_content_type_is(mime, "image", "*")) {
			if (ext == NULL) {
				if ((ext = mime->subtype) == NULL)
					ext = "image";
			}
			save = TRUE;
		}

		g_string_append_printf(name, ".%s", ext);
		gtk_tree_store_set(model, &iter, 0, save, 1, type, 2, filename?filename:name->str, 3, filename?NULL:name->str, 4, part, -1);
		g_free(filename);
	}
	g_free(type);

	g_string_truncate(name, len);
}