Esempio n. 1
0
/**
 * internet_address_mailbox_get_addr:
 * @mailbox: a #InternetAddressMailbox
 *
 * Gets the addr-spec of the internet address mailbox.
 *
 * Returns: the address of the mailbox.
 **/
const char *
internet_address_mailbox_get_addr (InternetAddressMailbox *mailbox)
{
	g_return_val_if_fail (INTERNET_ADDRESS_IS_MAILBOX (mailbox), NULL);
	
	return mailbox->addr;
}
Esempio n. 2
0
File: mu-msg.c Progetto: akonring/mu
static gboolean
fill_contact (MuMsgContact *self, InternetAddress *addr,
	      MuMsgContactType ctype)
{
	if (!addr)
		return FALSE;

	self->name = internet_address_get_name (addr);
	self->type = ctype;

	/* we only support internet mailbox addresses; if we don't
	 * check, g_mime hits an assert
	 */
	if (INTERNET_ADDRESS_IS_MAILBOX(addr))
		self->address = internet_address_mailbox_get_addr
			(INTERNET_ADDRESS_MAILBOX(addr));
	else
		self->address  = NULL;

	/* if there's no address, just a name, it's probably a local
	 * address (without @) */
	if (self->name && !self->address)
		self->address = self->name;

	/* note, the address could NULL e.g. when the recipient is something like
	 * 'Undisclosed recipients'
	 */
	return self->address != NULL;
}
Esempio n. 3
0
/* 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;
}
Esempio n. 4
0
const gchar *
rspamd_task_get_sender (struct rspamd_task *task)
{
	InternetAddress *iaelt = NULL;
#ifdef GMIME24
	InternetAddressMailbox *imb;

	if (task->from_envelope != NULL) {
		iaelt = internet_address_list_get_address (task->from_envelope, 0);
	}
	else if (task->from_mime != NULL) {
		iaelt = internet_address_list_get_address (task->from_mime, 0);
	}
	imb = INTERNET_ADDRESS_IS_MAILBOX(iaelt) ?
			INTERNET_ADDRESS_MAILBOX (iaelt) : NULL;

	return (imb ? internet_address_mailbox_get_addr (imb) : NULL);
#else
	if (task->from_envelope != NULL) {
		iaelt = internet_address_list_get_address (task->from_envelope);
	}
	else if (task->from_mime != NULL) {
		iaelt = internet_address_list_get_address (task->from_mime);
	}

	return (iaelt != NULL ? internet_address_get_addr (iaelt) : NULL);
#endif
}
Esempio n. 5
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);
    }
  }
}
Esempio n. 6
0
/**
 * internet_address_mailbox_set_addr:
 * @mailbox: a #InternetAddressMailbox
 * @addr: contact's email address
 *
 * Set the mailbox address.
 **/
void
internet_address_mailbox_set_addr (InternetAddressMailbox *mailbox, const char *addr)
{
	g_return_if_fail (INTERNET_ADDRESS_IS_MAILBOX (mailbox));
	
	if (mailbox->addr == addr)
		return;
	
	g_free (mailbox->addr);
	mailbox->addr = g_strdup (addr);
	
	g_mime_event_emit (((InternetAddress *) mailbox)->priv, NULL);
}
Esempio n. 7
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);
  }
}
Esempio n. 8
0
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;
}