Exemple #1
0
static void
format_headers_message_part_json (GMimeMessage *message)
{
    void *ctx = talloc_new (NULL);
    void *ctx_quote = talloc_new (ctx);
    InternetAddressList *recipients;
    const char *recipients_string;

    printf ("%s: %s",
	    json_quote_str (ctx_quote, "From"),
	    json_quote_str (ctx_quote, g_mime_message_get_sender (message)));
    recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);
    recipients_string = internet_address_list_to_string (recipients, 0);
    if (recipients_string)
	printf (", %s: %s",
		json_quote_str (ctx_quote, "To"),
		json_quote_str (ctx_quote, recipients_string));
    recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC);
    recipients_string = internet_address_list_to_string (recipients, 0);
    if (recipients_string)
	printf (", %s: %s",
		json_quote_str (ctx_quote, "Cc"),
		json_quote_str (ctx_quote, recipients_string));
    printf (", %s: %s",
	    json_quote_str (ctx_quote, "Subject"),
	    json_quote_str (ctx_quote, g_mime_message_get_subject (message)));
    printf (", %s: %s",
	    json_quote_str (ctx_quote, "Date"),
	    json_quote_str (ctx_quote, g_mime_message_get_date_as_string (message)));

    talloc_free (ctx_quote);
    talloc_free (ctx);
}
Exemple #2
0
void
format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
			 notmuch_bool_t reply)
{
    /* Any changes to the JSON or S-Expression format should be
     * reflected in the file devel/schemata. */

    InternetAddressList *recipients;
    const char *recipients_string;
    const char *reply_to_string;

    sp->begin_map (sp);

    sp->map_key (sp, "Subject");
    sp->string (sp, g_mime_message_get_subject (message));

    sp->map_key (sp, "From");
    sp->string (sp, g_mime_message_get_sender (message));

    recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);
    recipients_string = internet_address_list_to_string (recipients, 0);
    if (recipients_string) {
	sp->map_key (sp, "To");
	sp->string (sp, recipients_string);
    }

    recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC);
    recipients_string = internet_address_list_to_string (recipients, 0);
    if (recipients_string) {
	sp->map_key (sp, "Cc");
	sp->string (sp, recipients_string);
    }

    recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_BCC);
    recipients_string = internet_address_list_to_string (recipients, 0);
    if (recipients_string) {
	sp->map_key (sp, "Bcc");
	sp->string (sp, recipients_string);
    }

    reply_to_string = g_mime_message_get_reply_to (message);
    if (reply_to_string) {
	sp->map_key (sp, "Reply-To");
	sp->string (sp, reply_to_string);
    }

    if (reply) {
	sp->map_key (sp, "In-reply-to");
	sp->string (sp, g_mime_object_get_header (GMIME_OBJECT (message), "In-reply-to"));

	sp->map_key (sp, "References");
	sp->string (sp, g_mime_object_get_header (GMIME_OBJECT (message), "References"));
    } else {
	sp->map_key (sp, "Date");
	sp->string (sp, g_mime_message_get_date_as_string (message));
    }

    sp->end (sp);
}
Exemple #3
0
static void
format_part_reply (mime_node_t *node)
{
    int i;

    if (node->envelope_file) {
	printf ("On %s, %s wrote:\n",
		notmuch_message_get_header (node->envelope_file, "date"),
		notmuch_message_get_header (node->envelope_file, "from"));
    } else if (GMIME_IS_MESSAGE (node->part)) {
	GMimeMessage *message = GMIME_MESSAGE (node->part);
	InternetAddressList *recipients;
	const char *recipients_string;

	printf ("> From: %s\n", g_mime_message_get_sender (message));
	recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);
	recipients_string = internet_address_list_to_string (recipients, 0);
	if (recipients_string)
	    printf ("> To: %s\n",
		    recipients_string);
	recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC);
	recipients_string = internet_address_list_to_string (recipients, 0);
	if (recipients_string)
	    printf ("> Cc: %s\n",
		    recipients_string);
	printf ("> Subject: %s\n", g_mime_message_get_subject (message));
	printf ("> Date: %s\n", g_mime_message_get_date_as_string (message));
	printf (">\n");
    } else if (GMIME_IS_PART (node->part)) {
	GMimeContentType *content_type = g_mime_object_get_content_type (node->part);
	GMimeContentDisposition *disposition = g_mime_object_get_content_disposition (node->part);

	if (g_mime_content_type_is_type (content_type, "application", "pgp-encrypted") ||
	    g_mime_content_type_is_type (content_type, "application", "pgp-signature")) {
	    /* Ignore PGP/MIME cruft parts */
	} else if (g_mime_content_type_is_type (content_type, "text", "*") &&
		   !g_mime_content_type_is_type (content_type, "text", "html")) {
	    GMimeStream *stream_stdout = g_mime_stream_file_new (stdout);
	    g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream_stdout), FALSE);
	    show_text_part_content (node->part, stream_stdout, NOTMUCH_SHOW_TEXT_PART_REPLY);
	    g_object_unref(stream_stdout);
	} else if (disposition &&
		   strcasecmp (g_mime_content_disposition_get_disposition (disposition),
			       GMIME_DISPOSITION_ATTACHMENT) == 0) {
	    const char *filename = g_mime_part_get_filename (GMIME_PART (node->part));
	    printf ("Attachment: %s (%s)\n", filename,
		    g_mime_content_type_to_string (content_type));
	} else {
	    printf ("Non-text part: %s\n",
		    g_mime_content_type_to_string (content_type));
	}
    }

    for (i = 0; i < node->nchildren; i++)
	format_part_reply (mime_node_child (node, i));
}
Exemple #4
0
static void
msg_contact_foreach_file (MuMsg *msg, MuMsgContactForeachFunc func,
			  gpointer user_data)
{
	int i;
	struct {
		GMimeRecipientType     _gmime_type;
		MuMsgContactType       _type;
	} ctypes[] = {
		{GMIME_RECIPIENT_TYPE_TO,  MU_MSG_CONTACT_TYPE_TO},
		{GMIME_RECIPIENT_TYPE_CC,  MU_MSG_CONTACT_TYPE_CC},
		{GMIME_RECIPIENT_TYPE_BCC, MU_MSG_CONTACT_TYPE_BCC},
	};

	/* sender */
	addresses_foreach (g_mime_message_get_sender (msg->_file->_mime_msg),
			   MU_MSG_CONTACT_TYPE_FROM, func, user_data);

	/* reply_to */
	addresses_foreach (g_mime_message_get_reply_to (msg->_file->_mime_msg),
			   MU_MSG_CONTACT_TYPE_REPLY_TO, func, user_data);

	/* get to, cc, bcc */
	for (i = 0; i != G_N_ELEMENTS(ctypes); ++i) {
		InternetAddressList *addrlist;
		addrlist = g_mime_message_get_recipients (msg->_file->_mime_msg,
							  ctypes[i]._gmime_type);
		address_list_foreach (addrlist, ctypes[i]._type, func, user_data);
	}
}
Exemple #5
0
void
format_headers_json (const void *ctx, GMimeMessage *message, notmuch_bool_t reply)
{
    void *local = talloc_new (ctx);
    InternetAddressList *recipients;
    const char *recipients_string;

    printf ("{%s: %s",
            json_quote_str (local, "Subject"),
            json_quote_str (local, g_mime_message_get_subject (message)));
    printf (", %s: %s",
            json_quote_str (local, "From"),
            json_quote_str (local, g_mime_message_get_sender (message)));
    recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);
    recipients_string = internet_address_list_to_string (recipients, 0);
    if (recipients_string)
        printf (", %s: %s",
                json_quote_str (local, "To"),
                json_quote_str (local, recipients_string));
    recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC);
    recipients_string = internet_address_list_to_string (recipients, 0);
    if (recipients_string)
        printf (", %s: %s",
                json_quote_str (local, "Cc"),
                json_quote_str (local, recipients_string));

    if (reply) {
        printf (", %s: %s",
                json_quote_str (local, "In-reply-to"),
                json_quote_str (local, g_mime_object_get_header (GMIME_OBJECT (message), "In-reply-to")));

        printf (", %s: %s",
                json_quote_str (local, "References"),
                json_quote_str (local, g_mime_object_get_header (GMIME_OBJECT (message), "References")));
    } else {
        printf (", %s: %s",
                json_quote_str (local, "Date"),
                json_quote_str (local, g_mime_message_get_date_as_string (message)));
    }

    printf ("}");

    talloc_free (local);
}
void extract_headers (GMimeMessage *message, GMimeStream *out_stream) {
  const char *subject;
  char *escaped_subject;
  const char *sender;
  char *escaped_sender;
  const char *reply_to;
  char *escaped_reply_to;
  time_t t;
  int tz;
  char buf[64];
  struct tm *t_m;
  subject = g_mime_message_get_subject(message);
  escaped_subject = str_replace((char *) subject, "\"", "");
  g_mime_stream_printf (out_stream, "subject: \"%s\", ", escaped_subject);
  g_mime_stream_printf (out_stream, "message_id: \"%s\", ", g_mime_message_get_message_id(message));
  sender = g_mime_message_get_sender(message);
  escaped_sender = str_replace((char *) sender, "\"", "");
  g_mime_stream_printf (out_stream, "sender: \"%s\", ", escaped_sender);
  reply_to = g_mime_message_get_reply_to(message);
  escaped_reply_to = str_replace((char *) reply_to, "\"", "");
  g_mime_stream_printf (out_stream, "reply_to: \"%s\", ", escaped_reply_to);
  g_mime_message_get_date (message, &t, &tz);
  t_m = localtime (&t);
  strftime(buf, sizeof(buf) - 1, "%c", t_m);
  g_mime_stream_printf (out_stream, "date: \"%s\", ", buf);
  strftime(buf, sizeof(buf) - 1, "%Y%m%d%H%M%S", t_m);
  g_mime_stream_printf (out_stream, "sort_date: \"%s\", ", buf);

  InternetAddressList *recipients;
  recipients = g_mime_message_get_recipients(message, GMIME_RECIPIENT_TYPE_TO);
  g_mime_stream_printf (out_stream, "recipients_to: [");
  extract_addresses(recipients, out_stream);
  g_mime_stream_printf (out_stream, "], ");

  recipients = g_mime_message_get_recipients(message, GMIME_RECIPIENT_TYPE_CC);
  g_mime_stream_printf (out_stream, "recipients_cc: [");
  extract_addresses(recipients, out_stream);
  g_mime_stream_printf (out_stream, "], ");

  recipients = g_mime_message_get_recipients(message, GMIME_RECIPIENT_TYPE_BCC);
  g_mime_stream_printf (out_stream, "recipients_bcc: [");
  extract_addresses(recipients, out_stream);
  g_mime_stream_printf (out_stream, "] ");
}
Exemple #7
0
static void
reply_headers_message_part (GMimeMessage *message)
{
    InternetAddressList *recipients;
    const char *recipients_string;

    printf ("> From: %s\n", g_mime_message_get_sender (message));
    recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);
    recipients_string = internet_address_list_to_string (recipients, 0);
    if (recipients_string)
	printf ("> To: %s\n",
		recipients_string);
    recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC);
    recipients_string = internet_address_list_to_string (recipients, 0);
    if (recipients_string)
	printf ("> Cc: %s\n",
		recipients_string);
    printf ("> Subject: %s\n", g_mime_message_get_subject (message));
    printf ("> Date: %s\n", g_mime_message_get_date_as_string (message));
}
Exemple #8
0
static gchar*
get_recip (GMimeMessage *msg, GMimeRecipientType rtype)
{
    char *recep;
    InternetAddressList *receps;

    receps = g_mime_message_get_recipients (msg, rtype);
    recep = (char*)internet_address_list_to_string (receps, FALSE);

    if (!recep || !*recep) {
        g_free (recep);
        return NULL;
    }

    return recep;
}
Exemple #9
0
static notmuch_status_t
format_part_text (const void *ctx, mime_node_t *node,
                  int indent, const notmuch_show_params_t *params)
{
    /* The disposition and content-type metadata are associated with
     * the envelope for message parts */
    GMimeObject *meta = node->envelope_part ?
                        GMIME_OBJECT (node->envelope_part) : node->part;
    GMimeContentType *content_type = g_mime_object_get_content_type (meta);
    const notmuch_bool_t leaf = GMIME_IS_PART (node->part);
    const char *part_type;
    int i;

    if (node->envelope_file) {
        notmuch_message_t *message = node->envelope_file;

        part_type = "message";
        printf ("\f%s{ id:%s depth:%d match:%d excluded:%d filename:%s\n",
                part_type,
                notmuch_message_get_message_id (message),
                indent,
                notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH) ? 1 : 0,
                notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED) ? 1 : 0,
                notmuch_message_get_filename (message));
    } else {
        GMimeContentDisposition *disposition = g_mime_object_get_content_disposition (meta);
        const char *cid = g_mime_object_get_content_id (meta);
        const char *filename = leaf ?
                               g_mime_part_get_filename (GMIME_PART (node->part)) : NULL;

        if (disposition &&
                strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0)
            part_type = "attachment";
        else
            part_type = "part";

        printf ("\f%s{ ID: %d", part_type, node->part_num);
        if (filename)
            printf (", Filename: %s", filename);
        if (cid)
            printf (", Content-id: %s", cid);
        printf (", Content-type: %s\n", g_mime_content_type_to_string (content_type));
    }

    if (GMIME_IS_MESSAGE (node->part)) {
        GMimeMessage *message = GMIME_MESSAGE (node->part);
        InternetAddressList *recipients;
        const char *recipients_string;

        printf ("\fheader{\n");
        if (node->envelope_file)
            printf ("%s\n", _get_one_line_summary (ctx, node->envelope_file));
        printf ("Subject: %s\n", g_mime_message_get_subject (message));
        printf ("From: %s\n", g_mime_message_get_sender (message));
        recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);
        recipients_string = internet_address_list_to_string (recipients, 0);
        if (recipients_string)
            printf ("To: %s\n", recipients_string);
        recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC);
        recipients_string = internet_address_list_to_string (recipients, 0);
        if (recipients_string)
            printf ("Cc: %s\n", recipients_string);
        printf ("Date: %s\n", g_mime_message_get_date_as_string (message));
        printf ("\fheader}\n");

        printf ("\fbody{\n");
    }

    if (leaf) {
        if (g_mime_content_type_is_type (content_type, "text", "*") &&
                !g_mime_content_type_is_type (content_type, "text", "html"))
        {
            GMimeStream *stream_stdout = g_mime_stream_file_new (stdout);
            g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream_stdout), FALSE);
            show_text_part_content (node->part, stream_stdout, 0);
            g_object_unref(stream_stdout);
        } else {
            printf ("Non-text part: %s\n",
                    g_mime_content_type_to_string (content_type));
        }
    }

    for (i = 0; i < node->nchildren; i++)
        format_part_text (ctx, mime_node_child (node, i), indent, params);

    if (GMIME_IS_MESSAGE (node->part))
        printf ("\fbody}\n");

    printf ("\f%s}\n", part_type);

    return NOTMUCH_STATUS_SUCCESS;
}
Exemple #10
0
static AddressesList *get_bcc_addresses(GMimeMessage *message) {
  InternetAddressList *recipients_bcc = g_mime_message_get_recipients(message, GMIME_RECIPIENT_TYPE_BCC); // transfer-none
  if (recipients_bcc)
    return collect_addresses(recipients_bcc);
  return NULL;
}