Exemplo n.º 1
0
/**
 * internet_address_group_get_members:
 * @group: a #InternetAddressGroup
 *
 * Gets the #InternetAddressList containing the group members of an
 * rfc822 group address.
 *
 * Returns: (transfer none): a #InternetAddressList containing the
 * members of @group.
 **/
InternetAddressList *
internet_address_group_get_members (InternetAddressGroup *group)
{
	g_return_val_if_fail (INTERNET_ADDRESS_IS_GROUP (group), NULL);
	
	return group->members;
}
Exemplo n.º 2
0
/* 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;
}
Exemplo n.º 3
0
static void collect_addresses_into(InternetAddressList *ilist, AddressesList *addr_list, guint size) {
  g_return_if_fail(ilist != NULL);
  g_return_if_fail(addr_list != NULL);
  g_return_if_fail(size != 0);

  guint i;
  for (i = 0; i < size; i++) {
    InternetAddress *address = internet_address_list_get_address(ilist, i); // transfer none

    if (INTERNET_ADDRESS_IS_GROUP(address)) {
      InternetAddressGroup *group = INTERNET_ADDRESS_GROUP(address);
      InternetAddressList *group_list = internet_address_group_get_members(group); // transer none

      if (group_list) {
        guint gsize = internet_address_list_length(group_list);
        if (gsize)
          collect_addresses_into(group_list, addr_list, gsize);
      }

    } else if (INTERNET_ADDRESS_IS_MAILBOX(address)) {
      InternetAddressMailbox *mailbox = INTERNET_ADDRESS_MAILBOX(address);
      const gchar *name    = internet_address_get_name(address);
      const gchar *address = internet_address_mailbox_get_addr(mailbox);
      Address *addr = new_address(address, name);
      addresses_list_add(addr_list, addr);
    }
  }
}
Exemplo n.º 4
0
/**
 * internet_address_group_add_member:
 * @group: a #InternetAddressGroup
 * @member: a #InternetAddress
 *
 * Add a contact to the internet address group.
 *
 * Returns: the index of the newly added member.
 **/
int
internet_address_group_add_member (InternetAddressGroup *group, InternetAddress *member)
{
	g_return_val_if_fail (INTERNET_ADDRESS_IS_GROUP (group), -1);
	g_return_val_if_fail (IS_INTERNET_ADDRESS (member), -1);
	
	return internet_address_list_add (group->members, member);
}
Exemplo n.º 5
0
/* Scan addresses in 'list'.
 *
 * If 'message' is non-NULL, then for each address in 'list' that is
 * not configured as one of the user's addresses in 'config', add that
 * address to 'message' as an address of 'type'.
 *
 * If 'user_from' is non-NULL and *user_from is NULL, *user_from will
 * be set to the first address encountered in 'list' that is the
 * user's address.
 *
 * Return the number of addresses added to 'message'. (If 'message' is
 * NULL, the function returns 0 by definition.)
 */
static unsigned int
scan_address_list (InternetAddressList *list,
		   notmuch_config_t *config,
		   GMimeMessage *message,
		   GMimeRecipientType type,
		   const char **user_from)
{
    InternetAddress *address;
    int i;
    unsigned int n = 0;

    for (i = 0; i < internet_address_list_length (list); i++) {
	address = internet_address_list_get_address (list, i);
	if (INTERNET_ADDRESS_IS_GROUP (address)) {
	    InternetAddressGroup *group;
	    InternetAddressList *group_list;

	    group = INTERNET_ADDRESS_GROUP (address);
	    group_list = internet_address_group_get_members (group);
	    if (group_list == NULL)
		continue;

	    n += scan_address_list (group_list, config, message, type, user_from);
	} else {
	    InternetAddressMailbox *mailbox;
	    const char *name;
	    const char *addr;

	    mailbox = INTERNET_ADDRESS_MAILBOX (address);

	    name = internet_address_get_name (address);
	    addr = internet_address_mailbox_get_addr (mailbox);

	    if (address_is_users (addr, config)) {
		if (user_from && *user_from == NULL)
		    *user_from = addr;
	    } else if (message) {
		g_mime_message_add_recipient (message, type, name, addr);
		n++;
	    }
	}
    }

    return n;
}
Exemplo n.º 6
0
/* For each address in 'list' 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_address_list (GMimeMessage *message,
				 notmuch_config_t *config,
				 GMimeRecipientType type,
				 InternetAddressList *list)
{
    InternetAddress *address;
    int i;
    const char *ret = NULL;

    for (i = 0; i < internet_address_list_length (list); i++) {
	address = internet_address_list_get_address (list, i);
	if (INTERNET_ADDRESS_IS_GROUP (address)) {
	    InternetAddressGroup *group;
	    InternetAddressList *group_list;

	    group = INTERNET_ADDRESS_GROUP (address);
	    group_list = internet_address_group_get_members (group);
	    if (group_list == NULL)
		continue;

	    add_recipients_for_address_list (message, config,
					     type, group_list);
	} else {
	    InternetAddressMailbox *mailbox;
	    const char *name;
	    const char *addr;

	    mailbox = INTERNET_ADDRESS_MAILBOX (address);

	    name = internet_address_get_name (address);
	    addr = internet_address_mailbox_get_addr (mailbox);

	    if (address_is_users (addr, config)) {
		if (ret == NULL)
		    ret = addr;
	    } else {
		g_mime_message_add_recipient (message, type, name, addr);
	    }
	}
    }

    return ret;
}
Exemplo n.º 7
0
/* Print or prepare for printing addresses from InternetAddressList. */
static void
process_address_list (const search_context_t *ctx,
		      InternetAddressList *list)
{
    InternetAddress *address;
    int i;

    for (i = 0; i < internet_address_list_length (list); i++) {
	address = internet_address_list_get_address (list, i);
	if (INTERNET_ADDRESS_IS_GROUP (address)) {
	    InternetAddressGroup *group;
	    InternetAddressList *group_list;

	    group = INTERNET_ADDRESS_GROUP (address);
	    group_list = internet_address_group_get_members (group);
	    if (group_list == NULL)
		continue;

	    process_address_list (ctx, group_list);
	} else {
	    InternetAddressMailbox *mailbox = INTERNET_ADDRESS_MAILBOX (address);
	    mailbox_t mbx = {
		.name = internet_address_get_name (address),
		.addr = internet_address_mailbox_get_addr (mailbox),
	    };

	    /* OUTPUT_COUNT only works with deduplication */
	    if (ctx->dedup != DEDUP_NONE &&
		is_duplicate (ctx, mbx.name, mbx.addr))
		continue;

	    /* OUTPUT_COUNT and DEDUP_ADDRESS require a full pass. */
	    if (ctx->output & OUTPUT_COUNT || ctx->dedup == DEDUP_ADDRESS)
		continue;

	    print_mailbox (ctx, &mbx);
	}
    }
}
Exemplo n.º 8
0
static void
json_add_address (JsonBuilder *builder, InternetAddress *ia)
{
        if (INTERNET_ADDRESS_IS_GROUP(ia)) {
    InternetAddressGroup *group;
    InternetAddressList *group_list;

    group = INTERNET_ADDRESS_GROUP(ia);
    group_list = internet_address_group_get_members(group);

    json_add_address_list(builder, group_list);
        } else if (INTERNET_ADDRESS_IS_MAILBOX(ia)) {
    InternetAddressMailbox *mailbox;
    const char *addr_name;
    const char *addr_address;

    mailbox = INTERNET_ADDRESS_MAILBOX(ia);
    addr_name = internet_address_get_name(ia);
        addr_address = internet_address_mailbox_get_addr(mailbox);

        if (!addr_name && !addr_address)
                return;

        json_builder_begin_object (builder);

    if (addr_name) {
                json_builder_set_member_name (builder, "name");
                json_builder_add_string_value (builder, addr_name);
        }

        if (addr_address) {
                json_builder_set_member_name (builder, "address");
                json_builder_add_string_value (builder, addr_address);
        }

        json_builder_end_object (builder);
  }
}
Exemplo n.º 9
0
/**
 * internet_address_group_set_members:
 * @group: a #InternetAddressGroup
 * @members: a #InternetAddressList
 *
 * Set the members of the internet address group.
 **/
void
internet_address_group_set_members (InternetAddressGroup *group, InternetAddressList *members)
{
	g_return_if_fail (INTERNET_ADDRESS_IS_GROUP (group));
	g_return_if_fail (IS_INTERNET_ADDRESS_LIST (members));
	
	if (group->members == members)
		return;
	
	if (group->members) {
		g_mime_event_remove (group->members->priv, (GMimeEventCallback) members_changed, group);
		g_object_unref (group->members);
	}
	
	if (members) {
		g_mime_event_add (members->priv, (GMimeEventCallback) members_changed, group);
		g_object_ref (members);
	}
	
	group->members = members;
	
	g_mime_event_emit (((InternetAddress *) group)->priv, NULL);
}