Beispiel #1
0
void extract_addresses(InternetAddressList *address_list, GMimeStream *out_stream) {
  int i;
  for (i=0; i<internet_address_list_length(address_list); i++) {
    if (i > 0) {
      g_mime_stream_printf (out_stream, ", ");
    }
    InternetAddress *address;
    char *address_string;
    address = internet_address_list_get_address(address_list, i);
    address_string = internet_address_to_string(address, TRUE);
    address_string = str_replace(address_string, "\"", "\\\"");
    g_mime_stream_printf (out_stream, "\"%s\"", address_string);
  }
}
Beispiel #2
0
static void
print_mailbox (const search_context_t *ctx, const mailbox_t *mailbox)
{
    const char *name = mailbox->name;
    const char *addr = mailbox->addr;
    int count = mailbox->count;
    sprinter_t *format = ctx->format;
    InternetAddress *ia = internet_address_mailbox_new (name, addr);
    char *name_addr;

    /* name_addr has the name part quoted if necessary. Compare
     * 'John Doe <*****@*****.**>' vs. '"Doe, John" <*****@*****.**>' */
    name_addr = internet_address_to_string (ia, FALSE);

    if (format->is_text_printer) {
	if (ctx->output & OUTPUT_COUNT) {
	    format->integer (format, count);
	    format->string (format, "\t");
	}
	format->string (format, name_addr);
	format->separator (format);
    } else {
	format->begin_map (format);
	format->map_key (format, "name");
	format->string (format, name);
	format->map_key (format, "address");
	format->string (format, addr);
	format->map_key (format, "name-addr");
	format->string (format, name_addr);
	if (ctx->output & OUTPUT_COUNT) {
	    format->map_key (format, "count");
	    format->integer (format, count);
	}
	format->end (format);
	format->separator (format);
    }

    g_object_unref (ia);
    g_free (name_addr);
}
Beispiel #3
0
static GtkWidget *
balsa_vevent_widget(LibBalsaVEvent * event, gboolean may_reply,
		    InternetAddress * sender)
{
    GtkGrid *grid;
    int row = 0;
    LibBalsaIdentity *vevent_ident = NULL;

    grid = GTK_GRID(gtk_grid_new());
    gtk_grid_set_row_spacing(grid, 6);
    gtk_grid_set_column_spacing(grid, 12);
    GRID_ATTACH(grid, event->summary, _("Summary:"));
    GRID_ATTACH_ADDRESS(grid, event->organizer, _("Organizer:"));
    GRID_ATTACH_DATE(grid, event->start, _("Start:"));
    GRID_ATTACH_DATE(grid, event->end, _("End:"));
    GRID_ATTACH(grid, event->location, _("Location:"));
    if (event->attendee) {
	GList *att;
	GString *all_atts = NULL;

	for (att = event->attendee; att; att = att->next) {
	    LibBalsaAddress *lba = LIBBALSA_ADDRESS(att->data);
	    gchar *this_att = libbalsa_vcal_attendee_to_str(lba);

	    if (all_atts)
		g_string_append_printf(all_atts, "\n%s", this_att);
	    else
		all_atts = g_string_new(this_att);
	    g_free(this_att);

	    if (may_reply && libbalsa_vcal_attendee_rsvp(lba)) {
		InternetAddress *ia =
                    internet_address_mailbox_new(NULL,
                                                 lba->address_list->data);
                GList *list;

                for (list = balsa_app.identities; list; list = list->next) {
                    LibBalsaIdentity *ident = list->data;
                    if (libbalsa_ia_rfc2821_equal(ident->ia, ia)) {
                        vevent_ident = ident;
                        break;
                    }
                }
		g_object_unref(ia);
	    }
	}
	GRID_ATTACH(grid, all_atts->str,
                    ngettext("Attendee:", "Attendees:",
                             g_list_length(event->attendee)));
	g_string_free(all_atts, TRUE);
    }
    GRID_ATTACH_TEXT(grid, event->description, _("Description:"));

    if (sender && vevent_ident) {
	GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6);
	GtkWidget *label;
	GtkWidget *bbox;
	GtkWidget *button;

	/* add the callback data to the event object */
	g_object_ref(event);
	g_object_ref(sender);
	g_object_set_data_full(G_OBJECT(event), "ev:sender",
			       internet_address_to_string(sender, FALSE),
			       (GDestroyNotify) g_free);
        g_object_set_data_full(G_OBJECT(event), "ev:ident",
                               g_object_ref(vevent_ident),
			       (GDestroyNotify) g_object_unref);

	/* pack everything into a box */
	gtk_container_add(GTK_CONTAINER(box), GTK_WIDGET(grid));
	label =
	    gtk_label_new(_("The sender asks you for a reply to this request:"));
	gtk_container_add(GTK_CONTAINER(box), label);
	bbox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
	gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox),
				  GTK_BUTTONBOX_SPREAD);
	gtk_container_add(GTK_CONTAINER(box), bbox);

	button = gtk_button_new_with_label(_("Accept"));
	g_object_set_data_full(G_OBJECT(button), "event", event,
                               (GDestroyNotify) g_object_unref);
	g_object_set_data(G_OBJECT(button), "mode",
			  GINT_TO_POINTER(VCAL_PSTAT_ACCEPTED));
	g_signal_connect(G_OBJECT(button), "clicked",
			 G_CALLBACK(vevent_reply), bbox);
	gtk_container_add(GTK_CONTAINER(bbox), button);

	button = gtk_button_new_with_label(_("Accept tentatively"));
	g_object_set_data(G_OBJECT(button), "event", event);
	g_object_set_data(G_OBJECT(button), "mode",
			  GINT_TO_POINTER(VCAL_PSTAT_TENTATIVE));
	g_signal_connect(G_OBJECT(button), "clicked",
			 G_CALLBACK(vevent_reply), bbox);
	gtk_container_add(GTK_CONTAINER(bbox), button);

	button = gtk_button_new_with_label(_("Decline"));
	g_object_set_data(G_OBJECT(button), "event", event);
	g_object_set_data(G_OBJECT(button), "mode",
			  GINT_TO_POINTER(VCAL_PSTAT_DECLINED));
	g_signal_connect(G_OBJECT(button), "clicked",
			 G_CALLBACK(vevent_reply), bbox);
	gtk_container_add(GTK_CONTAINER(bbox), button);

	return box;
    } else
	return GTK_WIDGET(grid);
}
Beispiel #4
0
document* parse_file(const char *file_name) {
  int tallied_length = 0;
  GMimeStream *stream;
  GMimeMessage *msg = 0;
  // struct stat stat_buf;
  const char *author, *subject, *xref, *xref_end;
  time_t date;
  int offset;
  int num_words = 0;
  int file;
  InternetAddress *iaddr;
  InternetAddressList *iaddr_list;
  char *address;

#if DEBUG
  printf("%s\n", file_name);
#endif

  /*
  if ((file = stat(file_name, &stat_buf)) == -1) {
    perror("tokenizer");
    return NULL;
  }
  */

  // |O_STREAMING
  if ((file = open(file_name, O_RDONLY|O_STREAMING)) == -1) {
    perror("tokenizer");
    return NULL;
  }

#ifdef POSIX_FADV_NOREUSE
  no_reuse(file);
#endif

  stream = g_mime_stream_fs_new(file);
  msg = g_mime_parser_construct_message(stream);
  g_mime_stream_unref(stream);

  if (msg != 0) {
    table = g_hash_table_new(g_str_hash, g_str_equal);
    bufp = buffer;
    dword_table[0].word = NULL;
    bzero(saved_body, MAX_SAVED_BODY_LENGTH);
    saved_body_length = 0;
    author = g_mime_message_get_sender(msg);
    subject = g_mime_message_get_subject(msg);
    xref = g_mime_message_get_header(msg, "Xref");
    g_mime_message_get_date(msg, &date, &offset);
    if (author != NULL && subject != NULL && xref != NULL) {
      tallied_length = tally_string(author, tallied_length);
      strncpy(doc.author, author, MAX_HEADER_LENGTH-1);

      /* Get the address from the From header. */
      if ((iaddr_list = internet_address_parse_string(author)) != NULL) {
	iaddr = iaddr_list->address;
	internet_address_set_name(iaddr, NULL);
	address = internet_address_to_string(iaddr, FALSE);
	strncpy(doc.address, address, MAX_HEADER_LENGTH-1);
	downcase_string(doc.address);
	free(address);
	internet_address_list_destroy(iaddr_list);
      } else {
	*doc.address = 0;
      }

      tallied_length = tally_string(subject, tallied_length);
      strncpy(doc.subject, subject, MAX_HEADER_LENGTH-1);

      doc.time = date;

      if ((xref = strchr(xref, ' ')) != NULL) {
	xref++;
	xref_end = strchr(xref, ':');
	*doc.group = 0;
	strncat(doc.group, xref, min(xref_end-xref, MAX_HEADER_LENGTH-1));
	xref_end++;
	sscanf(xref_end, "%d", &doc.article);
      }

      g_mime_message_foreach_part(msg, partFound, (gpointer) &tallied_length);

      strncpy(doc.body, saved_body, MAX_SAVED_BODY_LENGTH);

      g_hash_table_foreach(table, add_word_to_table, (gpointer) &num_words);
      dword_table[num_words].word = NULL;
      g_hash_table_destroy(table);
      g_mime_object_unref(GMIME_OBJECT(msg));
    } else {
      close(file);
      return NULL;
    }
  }
  close(file);
  doc.words = dword_table;
  doc.num_words = num_words;

  return &doc;
}
Beispiel #5
0
static int
envelope_decode_address (SpruceIMAPEngine *engine, GString *addrs, GError **err)
{
	char *addr, *name = NULL, *user = NULL;
	unsigned char *literal = NULL;
	spruce_imap_token_t token;
	const char *domain = NULL;
	InternetAddress *ia;
	int part = 0;
	size_t n;
	
	if (spruce_imap_engine_next_token (engine, &token, err) == -1)
		return -1;
	
	if (token.token == SPRUCE_IMAP_TOKEN_NIL) {
		return 0;
	} else if (token.token != '(') {
		spruce_imap_utils_set_unexpected_token_error (err, engine, &token);
		return -1;
	}
	
	if (addrs->len > 0)
		g_string_append (addrs, ", ");
	
	do {
		if (spruce_imap_engine_next_token (engine, &token, err) == -1)
			goto exception;
		
		literal = NULL;
		switch (token.token) {
		case SPRUCE_IMAP_TOKEN_NIL:
			break;
		case SPRUCE_IMAP_TOKEN_ATOM:
		case SPRUCE_IMAP_TOKEN_QSTRING:
			switch (part) {
			case 0:
				name = g_mime_utils_header_decode_phrase (token.v.qstring);
				break;
			case 2:
				user = g_strdup (token.v.qstring);
				break;
			case 3:
				domain = token.v.qstring;
				break;
			}
			break;
		case SPRUCE_IMAP_TOKEN_LITERAL:
			if (spruce_imap_engine_literal (engine, &literal, &n, err) == -1)
				goto exception;
			
			switch (part) {
			case 0:
				name = g_mime_utils_header_decode_phrase ((char *) literal);
				g_free (literal);
				break;
			case 2:
				user = (char *) literal;
				break;
			case 3:
				domain = (char *) literal;
				break;
			}
			
			break;
		default:
			spruce_imap_utils_set_unexpected_token_error (err, engine, &token);
			goto exception;
		}
		
		part++;
	} while (part < 4);
	
	addr = g_strdup_printf ("%s@%s", user, domain);
	g_free (literal);
	g_free (user);
	
	ia = internet_address_mailbox_new (name, addr);
	g_free (name);
	g_free (addr);
	
	addr = internet_address_to_string (ia, FALSE);
	g_object_unref (ia);
	
	g_string_append (addrs, addr);
	g_free (addr);
	
	if (spruce_imap_engine_next_token (engine, &token, err) == -1)
		return -1;
	
	if (token.token != ')') {
		spruce_imap_utils_set_unexpected_token_error (err, engine, &token);
		return -1;
	}
	
	return 0;
	
 exception:
	
	g_free (name);
	g_free (user);
	
	return -1;
}