/* Does the address in the Reply-To header of 'message' already appear * in either the 'To' or 'Cc' header of the message? */ static int reply_to_header_is_redundant (notmuch_message_t *message) { const char *reply_to, *to, *cc, *addr; InternetAddressList *list; InternetAddress *address; InternetAddressMailbox *mailbox; reply_to = notmuch_message_get_header (message, "reply-to"); if (reply_to == NULL || *reply_to == '\0') return 0; list = internet_address_list_parse_string (reply_to); if (internet_address_list_length (list) != 1) return 0; address = internet_address_list_get_address (list, 0); if (INTERNET_ADDRESS_IS_GROUP (address)) return 0; mailbox = INTERNET_ADDRESS_MAILBOX (address); addr = internet_address_mailbox_get_addr (mailbox); to = notmuch_message_get_header (message, "to"); cc = notmuch_message_get_header (message, "cc"); if ((to && strstr (to, addr) != 0) || (cc && strstr (cc, addr) != 0)) { return 1; } return 0; }
gboolean rspamd_task_add_recipient (struct rspamd_task *task, const gchar *rcpt) { InternetAddressList *tmp_addr; if (task->rcpt_envelope == NULL) { task->rcpt_envelope = internet_address_list_new (); #ifdef GMIME24 rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t) g_object_unref, task->rcpt_envelope); #else rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t) internet_address_list_destroy, task->rcpt_envelope); #endif } tmp_addr = internet_address_list_parse_string (rcpt); if (tmp_addr) { internet_address_list_append (task->rcpt_envelope, tmp_addr); #ifdef GMIME24 g_object_unref (tmp_addr); #else internet_address_list_destroy (tmp_addr); #endif return TRUE; } return FALSE; }
/* Extract just the email address from the contents of a From: * header. */ static const char * _extract_email_address (const void *ctx, const char *from) { InternetAddressList *addresses; InternetAddress *address; InternetAddressMailbox *mailbox; const char *email = "MAILER-DAEMON"; addresses = internet_address_list_parse_string (from); /* Bail if there is no address here. */ if (addresses == NULL || internet_address_list_length (addresses) < 1) goto DONE; /* Otherwise, just use the first address. */ address = internet_address_list_get_address (addresses, 0); /* The From header should never contain an address group rather * than a mailbox. So bail if it does. */ if (! INTERNET_ADDRESS_IS_MAILBOX (address)) goto DONE; mailbox = INTERNET_ADDRESS_MAILBOX (address); email = internet_address_mailbox_get_addr (mailbox); email = talloc_strdup (ctx, email); DONE: if (addresses) g_object_unref (addresses); return email; }
static void addresses_foreach (const char* addrs, MuMsgContactType ctype, MuMsgContactForeachFunc func, gpointer user_data) { InternetAddressList *addrlist; if (!addrs) return; addrlist = internet_address_list_parse_string (addrs); if (addrlist) { address_list_foreach (addrlist, ctype, func, user_data); g_object_unref (addrlist); } }
static void json_add_recipients(JsonBuilder *builder, MuMsg *msg) { InternetAddressList *addr_from; InternetAddressList *addr_to; InternetAddressList *addr_cc; addr_from = internet_address_list_parse_string( mu_msg_get_from (msg) ); if (addr_from) { json_builder_set_member_name (builder, "from"); json_builder_begin_array (builder); json_add_address_list(builder, addr_from); json_builder_end_array (builder); g_object_unref(addr_from); } addr_to = internet_address_list_parse_string( mu_msg_get_to (msg) ); if (addr_to) { json_builder_set_member_name (builder, "to"); json_builder_begin_array (builder); json_add_address_list(builder, addr_to); json_builder_end_array (builder); g_object_unref(addr_to); } addr_cc = internet_address_list_parse_string( mu_msg_get_cc (msg) ); if (addr_cc) { json_builder_set_member_name (builder, "cc"); json_builder_begin_array (builder); json_add_address_list(builder, addr_cc); json_builder_end_array (builder); g_object_unref(addr_cc); } }
static AddressesList *collect_str_addresses(const gchar* addresses_list_str) { g_return_val_if_fail(addresses_list_str != NULL, NULL); AddressesList* result = NULL; InternetAddressList *addresses = internet_address_list_parse_string(addresses_list_str); // transfer-FULL if (addresses) { guint addresses_length = internet_address_list_length(addresses); if (addresses_length) { result = new_addresses_list(); collect_addresses_into(addresses, result, addresses_length); } g_object_unref(addresses); } return result; }
/* Print or prepare for printing addresses from a message header. */ static void process_address_header (const search_context_t *ctx, const char *value) { InternetAddressList *list; if (value == NULL) return; list = internet_address_list_parse_string (value); if (list == NULL) return; process_address_list (ctx, list); g_object_unref (list); }
/* For each address in 'recipients' that is not configured as one of * the user's addresses in 'config', add that address to 'message' as * an address of 'type'. * * The first address encountered that *is* the user's address will be * returned, (otherwise NULL is returned). */ static const char * add_recipients_for_string (GMimeMessage *message, notmuch_config_t *config, GMimeRecipientType type, const char *recipients) { InternetAddressList *list; if (recipients == NULL) return NULL; list = internet_address_list_parse_string (recipients); if (list == NULL) return NULL; return add_recipients_for_address_list (message, config, type, list); }
/* Scan addresses in 'recipients'. * * See the documentation of scan_address_list() above. This function * does exactly the same, but converts 'recipients' to an * InternetAddressList first. */ static unsigned int scan_address_string (const char *recipients, notmuch_config_t *config, GMimeMessage *message, GMimeRecipientType type, const char **user_from) { InternetAddressList *list; if (recipients == NULL) return 0; list = internet_address_list_parse_string (recipients); if (list == NULL) return 0; return scan_address_list (list, config, message, type, user_from); }
gboolean rspamd_task_add_sender (struct rspamd_task *task, const gchar *sender) { InternetAddressList *tmp_addr; if (task->from_envelope == NULL) { task->from_envelope = internet_address_list_new (); #ifdef GMIME24 rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t) g_object_unref, task->from_envelope); #else rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t) internet_address_list_destroy, task->from_envelope); #endif } if (strcmp (sender, "<>") == 0) { /* Workaround for gmime */ internet_address_list_add (task->from_envelope, internet_address_mailbox_new ("", "")); return TRUE; } else { tmp_addr = internet_address_list_parse_string (sender); if (tmp_addr) { internet_address_list_append (task->from_envelope, tmp_addr); #ifdef GMIME24 g_object_unref (tmp_addr); #else internet_address_list_destroy (tmp_addr); #endif return TRUE; } } return FALSE; }
static void vevent_reply(GObject * button, GtkWidget * box) { LibBalsaVEvent *event = LIBBALSA_VEVENT(g_object_get_data(button, "event")); LibBalsaVCalPartStat pstat = GPOINTER_TO_INT(g_object_get_data(button, "mode")); gchar *rcpt; LibBalsaMessage *message; LibBalsaMessageBody *body; gchar *dummy; gchar **params; GError *error = NULL; LibBalsaMsgCreateResult result; LibBalsaIdentity *ident; g_return_if_fail(event != NULL); rcpt = (gchar *) g_object_get_data(G_OBJECT(event), "ev:sender"); g_return_if_fail(rcpt != NULL); ident = g_object_get_data(G_OBJECT(event), "ev:ident"); g_return_if_fail(ident != NULL); /* make the button box insensitive... */ gtk_widget_set_sensitive(box, FALSE); /* create a message with the header set from the incoming message */ message = libbalsa_message_new(); message->headers->from = internet_address_list_new(); internet_address_list_add(message->headers->from, ident->ia); message->headers->to_list = internet_address_list_parse_string(rcpt); message->headers->date = time(NULL); /* create the message subject */ dummy = g_strdup_printf("%s: %s", event->summary ? event->summary : _("iTIP Calendar Request"), libbalsa_vcal_part_stat_to_str(pstat)); libbalsa_message_set_subject(message, dummy); g_free(dummy); /* the only message part is the calendar object */ body = libbalsa_message_body_new(message); body->buffer = libbalsa_vevent_reply(event, INTERNET_ADDRESS_MAILBOX(ident->ia)->addr, pstat); body->charset = g_strdup("utf-8"); body->content_type = g_strdup("text/calendar"); libbalsa_message_append_part(message, body); /* set the text/calendar parameters */ params = g_new(gchar *, 3); params[0] = g_strdup("method"); params[1] = g_strdup("reply"); params[2] = NULL; message->parameters = g_list_prepend(message->parameters, params); #if ENABLE_ESMTP result = libbalsa_message_send(message, balsa_app.outbox, NULL, balsa_find_sentbox_by_url, ident->smtp_server, GTK_WINDOW(gtk_widget_get_toplevel ((GtkWidget *) button)), FALSE, balsa_app.debug, &error); #else result = libbalsa_message_send(message, balsa_app.outbox, NULL, balsa_find_sentbox_by_url, GTK_WINDOW(gtk_widget_get_toplevel ((GtkWidget *) button)), FALSE, balsa_app.debug, &error); #endif if (result != LIBBALSA_MESSAGE_CREATE_OK) libbalsa_information(LIBBALSA_INFORMATION_ERROR, _("Sending the iTIP calendar reply failed: %s"), error ? error->message : "?"); if (error) g_error_free(error); g_object_unref(G_OBJECT(message)); }
static int display_message_list (SpruceFolder *folder, GPtrArray *uids, int first, int last, int cursor) { char padding[40]; char flag; char cur; int i; fprintf (stdout, "%s: %d messages, %d new\n", folder->name, spruce_folder_get_message_count (folder), spruce_folder_get_unread_message_count (folder)); memset (padding, ' ', sizeof (padding) - 1); padding[sizeof (padding) - 1] = '\0'; for (i = first; i < last; i++) { SpruceMessageInfo *info; if ((info = spruce_folder_get_message_info (folder, uids->pdata[i]))) { char *from, frombuf[21], date[17]; int subjlen, fromlen, frommax, n; InternetAddressList *list; InternetAddress *ia; if ((list = internet_address_list_parse_string (info->from))) { ia = internet_address_list_get_address (list, 0); if (INTERNET_ADDRESS_IS_MAILBOX (ia)) from = INTERNET_ADDRESS_MAILBOX (ia)->addr; else from = ia->name; } else from = ""; strftime (date, sizeof (date), "%a %b %e %H:%M", localtime (&info->date_sent)); frommax = 20; if ((n = num_digits (i + 1)) > 2) { /*fprintf (stderr, "%d > 2 digits (%d digits)\n", i + 1, n);*/ frommax -= n - 2; } fromlen = MIN (frommax, strlen (from)); memcpy (frombuf, from, fromlen); for (n = 0; n < fromlen; n++) if (!isprint (frombuf[n])) frombuf[n] = 'x'; while (fromlen < frommax) frombuf[fromlen++] = ' '; frombuf[fromlen] = '\0'; subjlen = 23; if ((n = (num_digits (info->lines))) > 2) subjlen -= n - 2; if ((n = (num_digits (info->size))) > 4) subjlen -= n - 4; if ((info->flags & SPRUCE_MESSAGE_DELETED)) flag = 'D'; else if ((info->flags & SPRUCE_MESSAGE_ANSWERED)) flag = 'A'; else if ((info->flags & SPRUCE_MESSAGE_SEEN)) flag = 'O'; else if ((info->flags & SPRUCE_MESSAGE_RECENT)) flag = 'N'; else flag = 'U'; if ((cursor >= 0 && cursor == i) || (cursor == -1 && flag == 'N')) { cursor = i; cur = '>'; } else cur = ' '; fprintf (stdout, "%c%c %s%d %s %.16s %.2u/%.4zu %.*s\n", cur, flag, (i + 1) < 10 ? " " : "", i + 1, frombuf, date, info->lines, info->size, subjlen, info->subject ? info->subject : EMPTY_SUBJECT); g_object_unref (list); spruce_folder_free_message_info (folder, info); } } return cursor == -1 ? first : cursor; }
END_TEST START_TEST(test_internet_address_list_parse_string) { char * trythese [][2] = { { "undisclosed-recipients", "((NIL NIL \"undisclosed-recipients\" NIL))"}, { "undisclosed-recipients;", "((NIL NIL \"undisclosed-recipients\" NIL))"}, { "undisclosed-recipients:", "((NIL NIL \"undisclosed-recipients\" NIL)(NIL NIL NIL NIL))"}, { "undisclosed-recipients:;", "((NIL NIL \"undisclosed-recipients\" NIL)(NIL NIL NIL NIL))"}, { "undisclosed-recipients: ;", "((NIL NIL \"undisclosed-recipients\" NIL)(NIL NIL NIL NIL))"}, { NULL, NULL } }; int i; for (i = 0; trythese[i][0] != NULL; i++) { char *input = trythese[i][0]; char *expect = trythese[i][1]; char *t, *result; InternetAddressList *alist; GList *list = NULL; t = imap_cleanup_address(input); alist = internet_address_list_parse_string(t); g_free(t); list = dbmail_imap_append_alist_as_plist(list, alist); g_object_unref(alist); alist = NULL; result = dbmail_imap_plist_as_string(list); fail_unless(strcmp(result,expect)==0, "internet_address_list_parse_string failed to generate correct undisclosed-recipients plist " "for [%s], expected\n[%s] got\n[%s]", input, expect, result); g_list_destroy(list); g_free(result); } char * testlist[][2] = { { "<*****@*****.**>", "((NIL NIL \"i_am_not\" \"broken.org\"))" }, { "Break me: <*****@*****.**>", "((NIL NIL \"Break me\" NIL)(NIL NIL \"foo\" \"bar.org\")(NIL NIL NIL NIL))" }, { "Joe's Friends: [email protected], [email protected], [email protected];", "((NIL NIL \"Joe's Friends\" NIL)(NIL NIL \"mary\" \"joe.com\")" "(NIL NIL \"joe\" \"joe.com\")(NIL NIL \"jane\" \"joe.com\")(NIL NIL NIL NIL))" }, // These have the wrong separator; ms lookout style. { "[email protected];[email protected]", "((NIL NIL \"one\" \"my.dom\")(NIL NIL \"two\" \"my.dom\"))" }, { "[email protected]; [email protected]", "((NIL NIL \"one\" \"my.dom\")(NIL NIL \"two\" \"my.dom\"))" }, { "Group: [email protected];, [email protected]", "((NIL NIL \"Group\" NIL)(NIL NIL \"one\" \"my.dom\")(NIL NIL NIL NIL)(NIL NIL \"two\" \"my.dom\"))" }, { NULL, NULL } }; char *input, *expect; for (i = 0; testlist[i][0] != NULL; i++) { input = testlist[i][0]; expect = testlist[i][1]; InternetAddressList *alist; GList *list = NULL; char *result; int res; char *t; t = imap_cleanup_address(input); alist = internet_address_list_parse_string(t); list = dbmail_imap_append_alist_as_plist(list, alist); result = dbmail_imap_plist_as_string(list); res = strcmp(result, expect); fail_unless(res == 0, "dbmail_imap_append_alist_as_plist failed, expected:\n[%s]\ngot:\n[%s]\n", expect, result); g_object_unref(alist); alist = NULL; g_list_destroy(list); g_free(result); g_free(t); } }