/** * Free a condition tree. */ static void c2_free(c2_ptr_t p) { // For a branch element if (p.isbranch) { c2_b_t * const pbranch = p.b; if (!pbranch) return; c2_free(pbranch->opr1); c2_free(pbranch->opr2); free(pbranch); } // For a leaf element else { c2_l_t * const pleaf = p.l; if (!pleaf) return; free(pleaf->tgt); free(pleaf->ptnstr); #ifdef CONFIG_REGEX_PCRE pcre_free(pleaf->regex_pcre); LPCRE_FREE_STUDY(pleaf->regex_pcre_extra); #endif free(pleaf); } }
static gboolean gui_ask_password (Account *account) { GtkWidget *table; GtkWidget *label; GtkWidget *vbox; char *buf; password_go = FALSE; password_gbool = TRUE; password_window = gnome_dialog_new (_("Incorrect Password"), GNOME_STOCK_BUTTON_OK, GNOME_STOCK_BUTTON_CANCEL, NULL); vbox = GNOME_DIALOG (password_window)->vbox; buf = g_strdup_printf (_("The password of the account %s is wrong"), account->acc_name); label = gtk_label_new (buf); gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); gtk_widget_show (label); c2_free (buf); table = gtk_table_new (2, 2, FALSE); gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0); gtk_widget_show (table); label = gtk_label_new (_("Username:"******"Password:"******"Y"); gnome_dialog_button_connect (GNOME_DIALOG (password_window), 1, GTK_SIGNAL_FUNC (password_cb), (gpointer) "N"); gdk_threads_leave (); while (!password_go) usleep (500); if (!password_gbool) return FALSE; buf = gtk_entry_get_text (GTK_ENTRY (password_entry)); gdk_threads_enter (); if (!buf) return FALSE; c2_free (account->protocol.pop.pass); account->protocol.pop.pass = g_strdup (buf); gtk_widget_destroy (password_window); return TRUE; }
void rc_save (void) { char *buf; FILE *fd; buf = g_strconcat (getenv ("HOME"), ROOT, "/cronos.rc", NULL); if ((fd = fopen (buf, "w")) == NULL) { cronos_error (errno, "Opening rc file for writing", ERROR_WARNING); c2_free (buf); return; } c2_free (buf); fprintf (fd, "h_pan %d\n", GTK_PANED (WMain->hpaned)->child1_size); fprintf (fd, "v_pan %d\n", GTK_PANED (WMain->vpaned)->child1_size); fprintf (fd, "mime_win_mode %d\n", rc->mime_win_mode); fprintf (fd, "clist_0 %d\n", GTK_CLIST (WMain->clist)->column[0].width); fprintf (fd, "clist_1 %d\n", GTK_CLIST (WMain->clist)->column[1].width); fprintf (fd, "clist_2 %d\n", GTK_CLIST (WMain->clist)->column[2].width); fprintf (fd, "clist_3 %d\n", GTK_CLIST (WMain->clist)->column[3].width); fprintf (fd, "clist_4 %d\n", GTK_CLIST (WMain->clist)->column[4].width); fprintf (fd, "clist_5 %d\n", GTK_CLIST (WMain->clist)->column[5].width); fprintf (fd, "clist_6 %d\n", GTK_CLIST (WMain->clist)->column[6].width); fprintf (fd, "clist_7 %d\n", GTK_CLIST (WMain->clist)->column[7].width); fprintf (fd, "font_read \"%s\"\n", rc->font_read); fprintf (fd, "font_unread \"%s\"\n", rc->font_unread); fprintf (fd, "font_body \"%s\"\n", rc->font_body); fprintf (fd, "font_print \"%s\"\n", rc->font_print); fprintf (fd, "title \"%s\"\n", rc->title); fprintf (fd, "toolbar %d\n", rc->toolbar); fprintf (fd, "main_window_width %d\n", rc->main_window_width); fprintf (fd, "main_window_height %d\n", rc->main_window_height); fprintf (fd, "\"showable_headers:preview\" %d\n", rc->showable_headers[SHOWABLE_HEADERS_PREVIEW]); fprintf (fd, "\"showable_headers:message\" %d\n", rc->showable_headers[SHOWABLE_HEADERS_MESSAGE]); fprintf (fd, "\"showable_headers:compose\" %d\n", rc->showable_headers[SHOWABLE_HEADERS_COMPOSE]); fprintf (fd, "\"showable_headers:save\" %d\n", rc->showable_headers[SHOWABLE_HEADERS_SAVE]); fprintf (fd, "\"showable_headers:print\" %d\n", rc->showable_headers[SHOWABLE_HEADERS_PRINT]); #if FALSE fprintf (fd, "sort_column %d\n", rc->sort_column); fprintf (fd, "sort_type %d\n", rc->sort_type); #endif fclose (fd); }
char * decode_8bit (const char *text) { const char *ptr; char *buf; GString *str; int words = 0, i; g_return_val_if_fail (text, NULL); str = g_string_new (NULL); /* Count the words */ for (ptr = text; *ptr != '\0'; ptr++) { if (*ptr == ' ' && *(ptr+1) != ' ') words++; } for (i = 0; i <= words; i++) { if ((buf = str_get_word (i, text, ' ')) == NULL) break; if (i) g_string_append_c (str, ' '); /* Check if the word is wrong */ if (strneq (buf, "=?iso-8859-1?Q?", 15)) { for (ptr = buf+15; *ptr != '\0'; ptr++) { if (strneq (ptr, "?=", 2)) break; if (*ptr == '=') { int num; ptr += sscanf (ptr, "=%X", &num)+1; g_string_append_c (str, (char)num); } else g_string_append_c (str, *ptr); } c2_free (buf); } else { g_string_append (str, buf); c2_free (buf); } } if (*(str->str+strlen (str->str)-1) != '\n') g_string_append_c (str, '\n'); buf = str->str; g_string_free (str, FALSE); return buf; }
/** * Free a condition tree in c2_lptr_t. */ c2_lptr_t * c2_free_lptr(c2_lptr_t *lp) { if (!lp) return NULL; c2_lptr_t *pnext = lp->next; c2_free(lp->ptr); free(lp); return pnext; }
void uidl_register (const char *uidl, const char *account) { char *path; FILE *fd; g_return_if_fail (uidl); g_return_if_fail (account); path = g_strconcat (getenv ("HOME"), ROOT, "/", account, ".uidl", NULL); if ((fd = fopen (path, "a")) == NULL) { cronos_error (errno, _("Opening the UIDL database"), ERROR_WARNING); return; } c2_free (path); fprintf (fd, "%s\n", uidl); fclose (fd); }
gboolean uidl_check (const char *uidl, const char *account) { char *db_uidl; char *path; FILE *fd; g_return_val_if_fail (uidl, FALSE); g_return_val_if_fail (account, FALSE); path = g_strconcat (getenv ("HOME"), ROOT, "/", account, ".uidl", NULL); if ((fd = fopen (path, "r")) == NULL) { if (errno == ENOENT) { if ((fd = fopen (path, "w")) == NULL) { cronos_error (errno, _("Creating the UIDL database"), ERROR_WARNING); return FALSE; } fclose (fd); fd = fopen (path, "r"); } else { cronos_error (errno, _("Opening the UIDL database"), ERROR_WARNING); return FALSE; } } c2_free (path); for (;;) { if ((db_uidl = fd_get_line (fd)) == NULL) { fclose (fd); return FALSE; } if (streq (db_uidl, uidl)) { fclose (fd); return TRUE; } } return FALSE; }
void file_init (Conf *config) { char *buffer; char *key, *val; FILE *fd; char *old_version = NULL; buffer = CONFIG_FILE; if ((fd = fopen (buffer, "r")) == NULL) { first_run (buffer); if ((fd = fopen (buffer, "r")) == NULL) { exit(1); } } c2_free (buffer); /* Start reading the file */ for (;;) { if ((key = fd_get_word (fd)) == NULL) break; if ((val = fd_get_word (fd)) == NULL) break; if (fd_move_to (fd, '\n', 1, TRUE, TRUE) == EOF) fseek (fd, -1, SEEK_CUR); if (streq (key, "empty_garbage")) { config->empty_garbage = atoi (val); c2_free (val); } else if (streq (key, "account")) { load_account (&config->account_head, val); } else if (streq (key, "mailbox")) { c2_mailbox_load (&config->mailbox_head, val); } else if (streq (key, "check_timeout")) { config->check_timeout = atoi (val); c2_free (val); } else if (streq (key, "check_at_start")) { config->check_at_start = atoi (val); c2_free (val); } else if (streq (key, "use_outbox")) { config->use_outbox = atoi (val); c2_free (val); } else if (streq (key, "use_persistent_smtp_connection")) { config->use_persistent_smtp_connection = atoi (val); c2_free (val); } else if (streq (key, "persistent_smtp_address")) { config->persistent_smtp_address = val; } else if (streq (key, "persistent_smtp_port")) { config->persistent_smtp_port = atoi (val); c2_free (val); } else if (streq (key, "prepend_char_on_re")) { c2_free (config->prepend_char_on_re); config->prepend_char_on_re = val; } else if (streq (key, "message_bigger")) { config->message_bigger = atoi (val); c2_free (val); } else if (streq (key, "timeout")) { config->timeout = atoi (val); c2_free (val); } else if (streq (key, "mark_as_read")) { config->mark_as_read = atoi (val); c2_free (val); } #ifdef BUILD_ADDRESS_BOOK else if (streq (key, "addrbook_init")) { config->addrbook_init = atoi (val); c2_free (val); } #endif else if (streq (key, "color_reply_original_message")) { sscanf (val, "%dx%dx%d", (int *) &config->color_reply_original_message.red, (int *) &config->color_reply_original_message.green, (int *) &config->color_reply_original_message.blue); c2_free (val); } else if (streq (key, "color_misc_body")) { sscanf (val, "%dx%dx%d", (int *) &config->color_misc_body.red, (int *) &config->color_misc_body.green, (int *) &config->color_misc_body.blue); c2_free (val); } else if (streq (key, "cronosII")) { if (strne (val+2, VERSION)) { old_version = g_strdup (val+2); } } else { buffer = g_strdup_printf (_("Unknown command in config file: %s"), key); cronos_error (ERROR_INTERNAL, buffer, ERROR_WARNING); c2_free (val); } c2_free (key); } fclose (fd); if (old_version) { pthread_t thread; pthread_create (&thread, NULL, PTHREAD_FUNC (c2_version_difference), old_version); } }
static void first_run (char path[]) { char *buffer; int calc; FILE *fd; /* If the error is that the file doesn't exists... */ if (errno != ENOENT) { cronos_error (errno, _("Reading the config file"), ERROR_FATAL); return; } /* ...create it */ /* First create the dir */ calc = strlen (path)-strlen (CONFIG); buffer = (char *) malloc ((calc+1) * sizeof (char)); strncpy (buffer, path, calc); buffer[calc] = '\0'; if ((calc = mkdir (buffer, 0700)) == -1) { c2_free (buffer); cronos_error (errno, "Creating the directory", ERROR_FATAL); } /* Create the file */ if ((fd = fopen (path, "w")) == NULL) { /* Failed creating the file! */ cronos_error (errno, "Creating the config file", ERROR_FATAL); } fprintf (fd, "\nmailbox \"0\r%s\r0\"\n" "mailbox \"2\r%s\r2\"\n" "mailbox \"1\r%s\r1\"\n" "mailbox \"3\r%s\r3\"\n" "mailbox \"4\r%s\r4\"\n", MAILBOX_INBOX, MAILBOX_OUTBOX, MAILBOX_QUEUE, MAILBOX_GARBAGE, MAILBOX_DRAFTS); fclose (fd); chmod (path, S_IRUSR | S_IWUSR); /* Now create the mailbox's dirs */ /* Check which is the longest name (MAILBOX_*) */ calc = strlen (MAILBOX_INBOX); if (calc < strlen (MAILBOX_OUTBOX)) calc = strlen (MAILBOX_OUTBOX); if (calc < strlen (MAILBOX_QUEUE)) calc = strlen (MAILBOX_QUEUE); if (calc < strlen (MAILBOX_GARBAGE)) calc = strlen (MAILBOX_GARBAGE); if (calc < strlen (MAILBOX_DRAFTS)) calc = strlen (MAILBOX_DRAFTS); c2_free (buffer); calc += strlen (path)-strlen (CONFIG)+15; buffer = (char *) malloc (calc * sizeof (char)); snprintf (buffer, calc, "%s%s/%s.mbx", getenv ("HOME"), ROOT, MAILBOX_INBOX); if (mkdir (buffer, 0700) == -1) { cronos_error (errno, "Creating the Inbox directory", ERROR_WARNING); } else { strcat (buffer, "/index"); fd = fopen (buffer, "w"); fclose (fd); chmod (buffer, S_IRUSR | S_IWUSR); } snprintf (buffer, calc, "%s%s/%s.mbx", getenv ("HOME"), ROOT, MAILBOX_OUTBOX); if (mkdir (buffer, 0700) == -1) { cronos_error (errno, "Creating the Outbox directory", ERROR_WARNING); } else { strcat (buffer, "/index"); fd = fopen (buffer, "w"); fclose (fd); chmod (buffer, S_IRUSR | S_IWUSR); } snprintf (buffer, calc, "%s%s/%s.mbx", getenv ("HOME"), ROOT, MAILBOX_QUEUE); if (mkdir (buffer, 0700) == -1) { cronos_error (errno, "Creating the Queue directory", ERROR_WARNING); } else { strcat (buffer, "/index"); fd = fopen (buffer, "w"); fclose (fd); chmod (buffer, S_IRUSR | S_IWUSR); } snprintf (buffer, calc, "%s%s/%s.mbx", getenv ("HOME"), ROOT, MAILBOX_GARBAGE); if (mkdir (buffer, 0700) == -1) { cronos_error (errno, "Creating the Garbage directory", ERROR_WARNING); } else { strcat (buffer, "/index"); fd = fopen (buffer, "w"); fclose (fd); chmod (buffer, S_IRUSR | S_IWUSR); } snprintf (buffer, calc, "%s%s/%s.mbx", getenv ("HOME"), ROOT, MAILBOX_DRAFTS); if (mkdir (buffer, 0700) == -1) { cronos_error (errno, "Creating the Drafts directory", ERROR_WARNING); } else { strcat (buffer, "/index"); fd = fopen (buffer, "w"); fclose (fd); chmod (buffer, S_IRUSR | S_IWUSR); } c2_free (buffer); buffer = g_strconcat (getenv ("HOME"), ROOT, "/cronos.rc", NULL); if ((fd = fopen (buffer, "w")) == NULL) { cronos_error (errno, "Creating the rc file", ERROR_FATAL); c2_free (buffer); return; } c2_free (buffer); fclose (fd); }
static gboolean gui_message_big_new (const char *from, const char *subject, const char *date, const char *account, const char *kbytes) { GtkWidget *vbox, *hbox; GtkWidget *table; GtkWidget *label; GtkWidget *hsep; GtkStyle *style1; GtkStyle *style2; char *buf; GtkWidget *xpm; go = FALSE; gbool = TRUE; window = gnome_dialog_new (_("Confirm message downloading"), GNOME_STOCK_BUTTON_YES, GNOME_STOCK_BUTTON_NO, NULL); gtk_window_set_modal (GTK_WINDOW (window), TRUE); gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (WMain->window)); gnome_dialog_set_default (GNOME_DIALOG (window), 0); vbox = GNOME_DIALOG (window)->vbox; label = gtk_label_new (_("There's a message bigger than what you allowed to automatically download.")); gtk_widget_show (label); gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); table = gtk_table_new (5, 2, FALSE); gtk_widget_show (table); gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0); gtk_table_set_row_spacings (GTK_TABLE (table), 2); gtk_table_set_col_spacings (GTK_TABLE (table), 2); if (from && subject && date) { label = gtk_label_new (_("From:")); gtk_widget_show (label); gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); style1 = gtk_widget_get_style (label); style2 = gtk_style_copy (style1); style2->font = gdk_font_load ("-adobe-helvetica-bold-r-normal-*-*-120-*-*-p-*-iso8859-1"); gtk_widget_set_style (label, style2); label = gtk_label_new (from); gtk_widget_show (label); gtk_table_attach (GTK_TABLE (table), label, 1, 2, 0, 1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_misc_set_alignment (GTK_MISC (label), 7.45058e-09, 0.5); style1 = gtk_widget_get_style (label); style2 = gtk_style_copy (style1); style2->font = gdk_font_load ("-adobe-courier-medium-r-normal-*-*-120-*-*-m-*-iso8859-1"); gtk_widget_set_style (label, style2); label = gtk_label_new (_("Date:")); gtk_widget_show (label); gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_misc_set_alignment (GTK_MISC (label), 7.45058e-09, 0.5); style1 = gtk_widget_get_style (label); style2 = gtk_style_copy (style1); style2->font = gdk_font_load ("-adobe-helvetica-bold-r-normal-*-*-120-*-*-p-*-iso8859-1"); gtk_widget_set_style (label, style2); label = gtk_label_new (date); gtk_widget_show (label); gtk_table_attach (GTK_TABLE (table), label, 1, 2, 1, 2, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_misc_set_alignment (GTK_MISC (label), 7.45058e-09, 0.5); style1 = gtk_widget_get_style (label); style2 = gtk_style_copy (style1); style2->font = gdk_font_load ("-adobe-courier-medium-r-normal-*-*-120-*-*-m-*-iso8859-1"); gtk_widget_set_style (label, style2); } else { label = gtk_label_new (_("Since the server doesn't support advanced POP commands very little information about this message could be extracted.")); gtk_widget_show (label); gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); } label = gtk_label_new (_("Account:")); gtk_widget_show (label); gtk_table_attach (GTK_TABLE (table), label, 0, 1, 3, 4, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_misc_set_alignment (GTK_MISC (label), 7.45058e-09, 0.5); style1 = gtk_widget_get_style (label); style2 = gtk_style_copy (style1); style2->font = gdk_font_load ("-adobe-helvetica-bold-r-normal-*-*-120-*-*-p-*-iso8859-1"); gtk_widget_set_style (label, style2); if (from && subject && date) { label = gtk_label_new (_("Subject:")); gtk_widget_show (label); gtk_table_attach (GTK_TABLE (table), label, 0, 1, 4, 5, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_misc_set_alignment (GTK_MISC (label), 7.45058e-09, 0.5); style1 = gtk_widget_get_style (label); style2 = gtk_style_copy (style1); style2->font = gdk_font_load ("-adobe-helvetica-bold-r-normal-*-*-120-*-*-p-*-iso8859-1"); gtk_widget_set_style (label, style2); label = gtk_label_new (subject); gtk_widget_show (label); gtk_table_attach (GTK_TABLE (table), label, 1, 2, 4, 5, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_misc_set_alignment (GTK_MISC (label), 7.45058e-09, 0.5); style1 = gtk_widget_get_style (label); style2 = gtk_style_copy (style1); style2->font = gdk_font_load ("-adobe-courier-medium-r-normal-*-*-120-*-*-m-*-iso8859-1"); gtk_widget_set_style (label, style2); } label = gtk_label_new (_("Size:")); gtk_widget_show (label); gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_misc_set_alignment (GTK_MISC (label), 7.45058e-09, 0.5); style1 = gtk_widget_get_style (label); style2 = gtk_style_copy (style1); style2->font = gdk_font_load ("-adobe-helvetica-bold-r-normal-*-*-120-*-*-p-*-iso8859-1"); gtk_widget_set_style (label, style2); buf = g_strdup_printf ("%s (%d Kb)", kbytes, atoi (kbytes)/1024); label = gtk_label_new (buf); c2_free (buf); gtk_widget_show (label); gtk_table_attach (GTK_TABLE (table), label, 1, 2, 2, 3, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_misc_set_alignment (GTK_MISC (label), 7.45058e-09, 0.5); style1 = gtk_widget_get_style (label); style2 = gtk_style_copy (style1); style2->font = gdk_font_load ("-adobe-courier-medium-r-normal-*-*-120-*-*-m-*-iso8859-1"); gtk_widget_set_style (label, style2); label= gtk_label_new (account); gtk_widget_show (label); gtk_table_attach (GTK_TABLE (table), label, 1, 2, 3, 4, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_misc_set_alignment (GTK_MISC (label), 7.45058e-09, 0.5); style1 = gtk_widget_get_style (label); style2 = gtk_style_copy (style1); style2->font = gdk_font_load ("-adobe-courier-medium-r-normal-*-*-120-*-*-m-*-iso8859-1"); gtk_widget_set_style (label, style2); hsep = gtk_hseparator_new (); gtk_widget_show (hsep); gtk_box_pack_start (GTK_BOX (vbox), hsep, FALSE, TRUE, 0); hbox = gtk_hbox_new (FALSE, 0); gtk_widget_show (hbox); gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0); buf = gnome_unconditional_pixmap_file("gnome-question.png"); if (buf) { xpm = gnome_pixmap_new_from_file(buf); c2_free(buf); gtk_widget_show (xpm); gtk_box_pack_start (GTK_BOX (hbox), xpm, FALSE, FALSE, 0); } label = gtk_label_new (_("Do you want to download it?")); gtk_widget_show (label); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0); gnome_dialog_button_connect (GNOME_DIALOG (window), 0, GTK_SIGNAL_FUNC (cb), (gpointer) "Y"); gnome_dialog_set_accelerator (GNOME_DIALOG (window), 0, GDK_Y, 0); gnome_dialog_button_connect (GNOME_DIALOG (window), 1, GTK_SIGNAL_FUNC (cb), (gpointer) "N"); gnome_dialog_set_accelerator (GNOME_DIALOG (window), 1, GDK_N, 0); gtk_widget_show (window); gdk_threads_leave (); while (!go) usleep (500); gdk_threads_enter (); return gbool; }
void * check_pop_main (Account *account) { char *buf = NULL, *buf2, *buf3; C2ResolveNode *resolve; int sock; int timedout = FALSE; struct sockaddr_in server; int messages = 0, bytes = 0, downloaded_bytes = 0, i = 0, password_errors = 3; GList *download[DOWNLOAD_LIST_LAST], *uidl_search = NULL, *top_search = NULL; GList *list; gboolean supports_uidl = FALSE; mid_t mid; FILE *index; FILE *mail; Message message; char *mailbox; Mailbox *mbox; GString *strmsg; char *header[HEADER_LAST]; gboolean reading_header = TRUE; gboolean with_attachs = FALSE; char *content_type; char *row[8]; GtkStyle *style, *style2; gboolean clisted = FALSE; g_return_val_if_fail (account, NULL); g_return_val_if_fail (account->type == C2_ACCOUNT_POP, NULL); download[DOWNLOAD_LIST_TOTAL] = NULL; download[DOWNLOAD_LIST_UIDL] = NULL; download[DOWNLOAD_LIST_TOP] = NULL; resolve = c2_resolve (account->protocol.pop.host, &buf); if (buf) { gdk_threads_enter (); window_checking_report (C2_CHECK_ERR, account->acc_name, buf); gdk_threads_leave (); return NULL; } sock = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); if (sock < 0) { gdk_threads_enter (); window_checking_report (C2_CHECK_ERR, account->acc_name, _("Failed to create socket")); gdk_threads_leave (); return NULL; } server.sin_family = AF_INET; server.sin_port = htons (account->protocol.pop.host_port); server.sin_addr.s_addr= inet_addr (resolve->ip); if (connect (sock, (struct sockaddr *)&server, sizeof (server)) < 0) { buf = g_strerror (errno); gdk_threads_enter (); window_checking_report (C2_CHECK_ERR, account->acc_name, buf); gdk_threads_leave (); return NULL; } /* Guten Morgen, Herr Server! */ buf = sock_read (sock, &timedout); if (pop_check_answer (buf, account, timedout) < 0) { if (timedout) goto run_for_your_life; goto bye_bye_server; } c2_free (buf); /* Log In */ gdk_threads_enter (); gtk_progress_set_format_string (GTK_PROGRESS (window_checking->mail_progress), _("Logging in...")); gdk_threads_leave (); retry_login: if (sock_printf (sock, "USER %s\r\n", account->protocol.pop.usr_name) < 0) { buf = g_strerror (errno); gdk_threads_enter (); window_checking_report (C2_CHECK_ERR, account->acc_name, buf); gdk_threads_leave (); goto bye_bye_server; } buf = sock_read (sock, &timedout); if (pop_check_answer (buf, account, timedout) < 0) { if (timedout) goto run_for_your_life; goto bye_bye_server; } c2_free (buf); if (sock_printf (sock, "PASS %s\r\n", account->protocol.pop.pass) < 0) { buf = g_strerror (errno); gdk_threads_enter (); window_checking_report (C2_CHECK_ERR, account->acc_name, buf); gdk_threads_leave (); goto bye_bye_server; } buf = sock_read (sock, &timedout); if (strnne (buf, "+OK", 3)) { if (--password_errors < 0) { if (pop_check_answer (buf, account, timedout) < 0) { if (timedout) goto run_for_your_life; goto bye_bye_server; } } gdk_threads_enter (); if (!gui_ask_password (account)) { gdk_threads_leave (); if (pop_check_answer (buf, account, timedout) < 0) { if (timedout) goto run_for_your_life; goto bye_bye_server; } } else { gdk_threads_leave (); goto retry_login; } } c2_free (buf); /* STAT */ gdk_threads_enter (); gtk_progress_set_format_string (GTK_PROGRESS (window_checking->mail_progress), _("Checking for number of mails in server...")); gdk_threads_leave (); if (sock_printf (sock, "STAT\r\n") < 0) { buf = g_strerror (errno); gdk_threads_enter (); window_checking_report (C2_CHECK_ERR, account->acc_name, buf); gdk_threads_leave (); goto bye_bye_server; } buf = sock_read (sock, &timedout); if (pop_check_answer (buf, account, timedout) < 0) { if (timedout) goto run_for_your_life; goto bye_bye_server; } sscanf (buf, "+OK %d ", &messages); c2_free (buf); if (!messages) { gdk_threads_enter (); gtk_progress_set_format_string (GTK_PROGRESS (window_checking->mail_progress), _("No messages in server")); window_checking_report (C2_CHECK_OK, account->acc_name, _("No messages to download")); gdk_threads_leave (); clisted = TRUE; goto bye_bye_server; } else if (messages != 1) buf = g_strdup_printf (_("%d messages in server"), messages); else buf = g_strdup_printf (_("1 message in server")); gdk_threads_enter (); gtk_progress_set_format_string (GTK_PROGRESS (window_checking->mail_progress), buf); gdk_threads_leave (); c2_free (buf); /* UIDL */ if (!account->keep_copy) { dont_use_uidl: /* Without UIDL*/ for (i = 1; i <= messages; i++) { buf = g_strdup_printf ("%d", i); download[DOWNLOAD_LIST_UIDL] = g_list_append (download[DOWNLOAD_LIST_UIDL], (gpointer) buf); } } else { /* With UIDL */ if (sock_printf (sock, "UIDL\r\n") < 0) { buf = g_strerror (errno); gdk_threads_enter (); window_checking_report (C2_CHECK_ERR, account->acc_name, buf); gdk_threads_leave (); goto bye_bye_server; } for (i = 0;; i++) { buf = sock_read (sock, &timedout); if (!i && strnne (buf, "+OK", 3)) { /* UIDL is optional for POP servers, * so I won't complain if server doesn't like it */ buf2 = g_strdup_printf (_("The POP server of the account %s doesn't support UIDL."), account->acc_name); gdk_threads_enter (); gnome_appbar_set_status (GNOME_APPBAR (WMain->appbar), buf2); gdk_threads_leave (); supports_uidl = FALSE; goto dont_use_uidl; } supports_uidl = TRUE; if (!i) continue; if (streq (buf, ".\r\n")) break; buf2 = str_get_word (1, buf, ' '); buf3 = str_strip (buf2, '\r'); buf2 = str_strip (buf3, '\n'); if (!uidl_check (buf2, account->acc_name)) { download[DOWNLOAD_LIST_UIDL] = g_list_append (download[DOWNLOAD_LIST_UIDL], buf); } } } /* TOP */ if (!config->message_bigger) { /* Without TOP */ dont_use_list: dont_use_top: for (i = 1; i <= messages; i++) download[DOWNLOAD_LIST_TOP] = g_list_append (download[DOWNLOAD_LIST_TOP], (gpointer) i); } else { /* With TOP */ char *subject, *from, *date, *kbytes; if (sock_printf (sock, "LIST\r\n") < 0) { buf = g_strerror (errno); gdk_threads_enter (); window_checking_report (C2_CHECK_ERR, account->acc_name, buf); gdk_threads_leave (); goto bye_bye_server; } for (i = 0;; i++) { buf = sock_read (sock, &timedout); if (!i && strnne (buf, "+OK", 3)) { buf2 = g_strdup_printf (_("The POP server of the account %s doesn't support LIST."), account->acc_name); gdk_threads_enter (); gnome_appbar_set_status (GNOME_APPBAR (WMain->appbar), buf2); gdk_threads_leave (); goto dont_use_list; } if (!i) continue; if (streq (buf, ".\r\n")) break; buf2 = str_get_word (1, buf, ' '); str_strip (buf2, '\r'); str_strip (buf2, '\n'); download[DOWNLOAD_LIST_TOP] = g_list_append (download[DOWNLOAD_LIST_TOP], buf); c2_free (buf2); } for (list = download[DOWNLOAD_LIST_TOP]; list; list = list->next) { if (sock_printf (sock, "TOP %d 0\r\n", atoi (CHAR (list->data))) < 0) { buf = g_strerror (errno); gdk_threads_enter (); window_checking_report (C2_CHECK_ERR, account->acc_name, buf); gdk_threads_leave (); goto bye_bye_server; } strmsg = g_string_new (NULL); for (i = 0;; i++) { buf = sock_read (sock, &timedout); if (!i && strnne (buf, "+OK", 3)) { buf2 = g_strdup_printf (_("The POP server of the account %s doesn't support TOP."), account->acc_name); gdk_threads_enter (); gnome_appbar_set_status (GNOME_APPBAR (WMain->appbar), buf2); gdk_threads_leave (); goto dont_use_top; } if (!i) continue; if (streq (buf, ".\r\n")) break; g_string_append (strmsg, buf); c2_free (buf); } subject = message_get_header_field (NULL, strmsg->str, "\nSubject:"); from = message_get_header_field (NULL, strmsg->str, "From:"); date = message_get_header_field (NULL, strmsg->str, "\nDate:"); kbytes = str_get_word (1, CHAR (list->data), ' '); str_strip (kbytes, '\r');str_strip (kbytes, '\n'); gdk_threads_enter (); if ((atoi (kbytes) >= config->message_bigger*1024) && (!gui_message_big_new (from, subject, date, account->acc_name, kbytes))) { gdk_threads_leave (); c2_free (list->data); list->data = NULL; download[DOWNLOAD_LIST_TOP] = g_list_remove_link (download[DOWNLOAD_LIST_TOP], list); } else gdk_threads_leave (); } } /* Learn messages to download */ if (!account->keep_copy && !config->message_bigger) { /* !UIDL AND !TOP */ download[DOWNLOAD_LIST_TOTAL] = download[DOWNLOAD_LIST_UIDL]; } else if (account->keep_copy && !config->message_bigger) { /* UIDL AND !TOP */ for (list = download[DOWNLOAD_LIST_UIDL]; list; list = list->next) { download[DOWNLOAD_LIST_TOTAL] = g_list_append (download[DOWNLOAD_LIST_TOTAL], str_get_word (0, CHAR (list->data), ' ')); } } else if (!account->keep_copy && config->message_bigger) { /* !UIDL AND TOP */ download[DOWNLOAD_LIST_TOTAL] = download[DOWNLOAD_LIST_TOP]; } else if (account->keep_copy && config->message_bigger) { /* UIDL AND TOP */ for (uidl_search = download[DOWNLOAD_LIST_UIDL]; !uidl_search; uidl_search = uidl_search->next) { for (top_search = download[DOWNLOAD_LIST_TOP]; !top_search; top_search = top_search->next) { printf ("%d %d\n", (int) uidl_search->data, (int) top_search->data); /* TODO */ } } } messages = g_list_length (download[DOWNLOAD_LIST_TOTAL]); gdk_threads_enter (); gtk_progress_configure (GTK_PROGRESS (window_checking->mail_progress), 0, 0, messages); gtk_progress_set_format_string (GTK_PROGRESS (window_checking->mail_progress), _("%p%% downloaded (%v of %u messages)")); gdk_threads_leave (); strmsg = g_string_new (NULL); message.message = message.header = NULL; for (list = download[DOWNLOAD_LIST_TOTAL]; list; list = list->next) { buf = str_get_word (0, CHAR (list->data), ' '); i = atoi (buf); c2_free (buf); /* Ask for the mail */ if (sock_printf (sock, "RETR %d\r\n", i) < 0) { buf = g_strerror (errno); gdk_threads_enter (); window_checking_report (C2_CHECK_ERR, account->acc_name, buf); gdk_threads_leave (); goto bye_bye_server; } /* Read the first line */ buf = sock_read (sock, &timedout); if (pop_check_answer (buf, account, timedout) < 0) { if (timedout) goto run_for_your_life; goto bye_bye_server; } /* Learn bytes in the messages */ sscanf (buf, "+OK %d octets\r\n", &bytes); if (bytes) { gdk_threads_enter (); gtk_progress_configure (GTK_PROGRESS (window_checking->bytes_progress), 0, 0, bytes); gtk_widget_show (window_checking->bytes_progress); gdk_threads_leave (); } else { gdk_threads_enter (); gtk_widget_hide (window_checking->bytes_progress); gdk_threads_leave (); } c2_free (buf); /* Get the mail */ reading_header = TRUE; for (;;) { buf = sock_read (sock, &timedout); if (bytes) { downloaded_bytes += strlen (buf); gdk_threads_enter (); gtk_progress_set_value (GTK_PROGRESS (window_checking->bytes_progress), downloaded_bytes); gdk_threads_leave (); } if (streq (buf, ".\r\n")) { message.message = g_strdup (strmsg->str); g_string_assign (strmsg, ""); str_strip (message.message, '\r'); break; } if (reading_header && strlen (buf) > 2) { char *buf2; buf2 = decode_8bit (buf); c2_free (buf); buf = buf2; } if (reading_header && strlen (buf) == 2) { /* Still reading header and is an empty line */ buf2 = g_strdup_printf ("X-CronosII-Account: %s\r\n", account->acc_name); g_string_append (strmsg, buf2); c2_free (buf2); reading_header = FALSE; } g_string_append (strmsg, buf); } gtk_progress_set_percentage (GTK_PROGRESS (window_checking->bytes_progress), 1); /* Write to the mail file */ mailbox = account->mailbox->name; #if USE_PLUGINS c2_dynamic_module_signal_emit (C2_DYNAMIC_MODULE_MESSAGE_DOWNLOAD_POP, &message, &mailbox, NULL, NULL, NULL); #endif mbox = search_mailbox_name (config->mailbox_head, mailbox); if (!mbox) { /* Mailbox couldn't be found, going with the default */ mbox = account->mailbox; } mid = c2_mailbox_get_next_mid (mbox); buf = c2_mailbox_mail_path (mailbox, mid); if ((mail = fopen (buf, "w")) == NULL) { gdk_threads_enter (); window_checking_report (C2_CHECK_ERR, account->acc_name, _("Error opening the file where to store the new mail")); cronos_error (errno, _("Opening the mail file"), ERROR_WARNING); gdk_threads_leave (); c2_free (buf); continue; } c2_free (buf); fprintf (mail, "%s", message.message); fclose (mail); /* Write to the index file */ buf = c2_mailbox_index_path (mailbox); if ((index = fopen (buf, "a")) == NULL) { gdk_threads_enter (); window_checking_report (C2_CHECK_ERR, account->acc_name, _("Error opening the main DB file to store the new mail")); cronos_error (errno, _("Opening the main DB file"), ERROR_WARNING); gdk_threads_leave (); c2_free (buf); goto bye_bye_server; } header[HEADER_SUBJECT] = message_get_header_field (&message, NULL, "\nSubject:"); header[HEADER_FROM] = message_get_header_field (&message, NULL, "\nFrom:"); header[HEADER_DATE] = message_get_header_field (&message, NULL, "\nDate:"); content_type = message_get_header_field (&message, NULL, "\nContent-Type:"); with_attachs = FALSE; /* if (content_type) { message_mime_parse_content_type (content_type, &type, &subtype, ¶meter); if (streq (type, "multipart")) { GList *s; MimeHash *mime; message_mime_parse (&message, NULL); for (s = message.mime; s != NULL; s = s->next) { mime = MIMEHASH (s->data); if (!mime) continue; if (strneq (mime->disposition, "attachment", 10)) with_attachs = TRUE; } } }*/ if (!header[HEADER_SUBJECT]) header[HEADER_SUBJECT] = ""; if (!header[HEADER_FROM]) header[HEADER_FROM] = ""; if (!header[HEADER_DATE]) header[HEADER_DATE] = ""; fprintf (index, "N\r\r%s\r%s\r%s\r%s\r%s\r%d\n", with_attachs ? "1" : "", header[HEADER_SUBJECT], header[HEADER_FROM], header[HEADER_DATE], account->acc_name, mid); fclose (index); c2_free (message.message); c2_free (message.header); message.message = message.header = NULL; if (!account->keep_copy) { /* Delete the message */ if (sock_printf (sock, "DELE %d\r\n", i) < 0) { buf = g_strerror (errno); gdk_threads_enter (); window_checking_report (C2_CHECK_ERR, account->acc_name, buf); gdk_threads_leave (); goto bye_bye_server; } buf = sock_read (sock, &timedout); if (pop_check_answer (buf, account, timedout) < 0) { if (timedout) goto run_for_your_life; goto bye_bye_server; } } if (streq (selected_mbox, mailbox)) { row[0] = ""; row[1] = ""; row[2] = ""; row[3] = header[HEADER_SUBJECT]; row[4] = header[HEADER_FROM]; row[5] = header[HEADER_DATE]; row[6] = account->acc_name; row[7] = g_strdup_printf ("%d", mid); gdk_threads_enter (); gtk_clist_freeze (GTK_CLIST (WMain->clist)); gtk_clist_append (GTK_CLIST (WMain->clist), row); style = gtk_widget_get_style (WMain->clist); style2 = gtk_style_copy (style); style2->font = font_unread; gtk_clist_set_row_style (GTK_CLIST (WMain->clist), GTK_CLIST (WMain->clist)->rows-1, style2); gtk_clist_set_pixmap (GTK_CLIST (WMain->clist), GTK_CLIST (WMain->clist)->rows-1, 0, pixmap_unread, mask_unread); if (with_attachs) gtk_clist_set_pixmap (GTK_CLIST (WMain->clist), GTK_CLIST (WMain->clist)->rows-1, 2, pixmap_attach, mask_attach); new_messages++; gtk_clist_thaw (GTK_CLIST (WMain->clist)); gtk_clist_set_row_data (GTK_CLIST (WMain->clist), GTK_CLIST (WMain->clist)->rows-1, (gpointer) "N"); update_wm_title (); gtk_progress_set_value (GTK_PROGRESS (window_checking->mail_progress), i); gdk_threads_leave (); clisted = TRUE; } gdk_threads_enter (); gtk_progress_set_value (GTK_PROGRESS (window_checking->mail_progress), gtk_progress_get_value (GTK_PROGRESS (window_checking->mail_progress))+1); gdk_threads_leave (); } if (supports_uidl) { GList *llist; for (llist = download[DOWNLOAD_LIST_UIDL]; llist != NULL; llist = llist->next) { char *uidl; uidl = CHAR (llist->data); buf2 = str_get_word (1, uidl, ' '); buf3 = str_strip (buf2, '\r'); buf2 = str_strip (buf3, '\n'); if (buf2) { uidl_register (buf2, account->acc_name); } } } if (messages != 1) buf = g_strdup_printf (_("%d messages downloaded."), messages); else buf = g_strdup_printf (_("1 message downloaded.")); gdk_threads_enter (); gtk_progress_configure (GTK_PROGRESS (window_checking->mail_progress), messages, 0, messages); gtk_progress_set_format_string (GTK_PROGRESS (window_checking->mail_progress), buf); window_checking_report (C2_CHECK_OK, account->acc_name, buf); gdk_threads_leave (); bye_bye_server: if (sock_printf (sock, "QUIT\r\n") < 0) { buf = g_strerror (errno); } buf = sock_read (sock, &timedout); if (pop_check_answer (buf, account, timedout) < 0) { if (timedout) goto run_for_your_life; } run_for_your_life: close (sock); return NULL; }
void rc_init (void) { char *key; char *val; char *buf; FILE *fd; buf = g_strconcat (getenv ("HOME"), ROOT, "/cronos.rc", NULL); rc = g_new0 (Rc, 1); rc->h_pan = 120; rc->v_pan = 120; rc->clist_0 = 20; rc->clist_1 = 10; rc->clist_2 = 10; rc->clist_3 = 150; rc->clist_4 = 150; rc->clist_5 = 100; rc->clist_6 = 65; rc->clist_7 = 15; rc->font_body = g_strdup ("-adobe-times-medium-r-normal-*-*-140-*-*-p-*-iso8859-1"); rc->font_unread = g_strdup ("-b&h-lucida-bold-r-normal-*-*-100-*-*-p-*-iso8859-1"); rc->font_read = g_strdup ("-b&h-lucida-medium-r-normal-*-*-100-*-*-p-*-iso8859-1"); rc->font_print = g_strdup ("-adobe-helvetica-medium-r-normal-*-*-120-*-*-p-*-iso8859-1"); /* set window manager title here "Conversion chars: */ /* %a = App Name (Cronos II),%v = Version, */ /* %m = Messages in selected mailbox, */ /* %n = New messages in selected mailbox, */ /* %M = Selected mailbox. */ rc->title = g_strdup ("%a v.%v - %M - %m"); rc->toolbar = GTK_TOOLBAR_BOTH; rc->main_window_width = 600; rc->main_window_height= 400; rc->mime_win_mode = MIME_WIN_AUTOMATICALLY; rc->showable_headers[SHOWABLE_HEADERS_PREVIEW] = SHOWABLE_HEADER_FIELD_TO | SHOWABLE_HEADER_FIELD_FROM | SHOWABLE_HEADER_FIELD_SUBJECT; rc->showable_headers[SHOWABLE_HEADERS_MESSAGE] = SHOWABLE_HEADER_FIELD_TO | SHOWABLE_HEADER_FIELD_FROM | SHOWABLE_HEADER_FIELD_SUBJECT | SHOWABLE_HEADER_FIELD_DATE | SHOWABLE_HEADER_FIELD_ACCOUNT | SHOWABLE_HEADER_FIELD_CC; rc->showable_headers[SHOWABLE_HEADERS_COMPOSE] = SHOWABLE_HEADER_FIELD_TO | SHOWABLE_HEADER_FIELD_FROM | SHOWABLE_HEADER_FIELD_ACCOUNT | SHOWABLE_HEADER_FIELD_SUBJECT | SHOWABLE_HEADER_FIELD_CC; #if FALSE rc->sort_column = 5; rc->sort_type = GTK_SORT_ASCENDING; #endif if ((fd = fopen (buf, "r")) == NULL) { cronos_error (errno, "Opening rc file for reading", ERROR_WARNING); c2_free (buf); return; } c2_free (buf); for (;;) { if ((key = fd_get_word (fd)) == NULL) break; if ((val = fd_get_word (fd)) == NULL) break; if (fd_move_to (fd, '\n', 1, TRUE, TRUE) == EOF) fseek (fd, -1, SEEK_CUR); if (!strcmp (key, "h_pan")) { rc->h_pan = atoi (val); c2_free (val); } else if (!strcmp (key, "v_pan")) { rc->v_pan = atoi (val); c2_free (val); } else if (streq (key, "mime_win_mode")) { rc->mime_win_mode = atoi (val); c2_free (val); } else if (!strcmp (key, "clist_0")) { rc->clist_0 = atoi (val); c2_free (val); } else if (!strcmp (key, "clist_1")) { rc->clist_1 = atoi (val); c2_free (val); } else if (!strcmp (key, "clist_2")) { rc->clist_2 = atoi (val); c2_free (val); } else if (!strcmp (key, "clist_3")) { rc->clist_3 = atoi (val); c2_free (val); } else if (!strcmp (key, "clist_4")) { rc->clist_4 = atoi (val); c2_free (val); } else if (!strcmp (key, "clist_5")) { rc->clist_5 = atoi (val); c2_free (val); } else if (!strcmp (key, "clist_6")) { rc->clist_6 = atoi (val); c2_free (val); } else if (!strcmp (key, "clist_7")) { rc->clist_7 = atoi (val); c2_free (val); } else if (!strcmp (key, "font_read")) { c2_free (rc->font_read); rc->font_read = val; } else if (!strcmp (key, "font_unread")) { c2_free (rc->font_unread); rc->font_unread = val; } else if (!strcmp (key, "font_body")) { c2_free (rc->font_body); rc->font_body = val; } else if (!strcmp (key, "font_print")) { c2_free (rc->font_print); rc->font_print = val; } else if (!strcmp (key, "title")) { c2_free (rc->title); rc->title = val; } else if (!strcmp (key, "toolbar")) { rc->toolbar = atoi (val); c2_free (val); } else if (!strcmp (key, "main_window_width")) { rc->main_window_width = atoi (val); c2_free (val); } else if (!strcmp (key, "main_window_height")) { rc->main_window_height = atoi (val); c2_free (val); } else if (streq (key, "showable_headers:preview")) { rc->showable_headers[SHOWABLE_HEADERS_PREVIEW] = atoi (val); c2_free (val); } else if (streq (key, "showable_headers:message")) { rc->showable_headers[SHOWABLE_HEADERS_MESSAGE] = atoi (val); c2_free (val); } else if (streq (key, "showable_headers:compose")) { rc->showable_headers[SHOWABLE_HEADERS_COMPOSE] = atoi (val); c2_free (val); } else if (streq (key, "showable_headers:print")) { rc->showable_headers[SHOWABLE_HEADERS_PRINT] = atoi (val); c2_free (val); } else if (streq (key, "showable_headers:save")) { rc->showable_headers[SHOWABLE_HEADERS_SAVE] = atoi (val); c2_free (val); } #if FALSE else if (!strcmp (key, "sort_column")) { rc->sort_column = atoi (val); c2_free (val); } else if (!strcmp (key, "sort_type")) { rc->sort_type = atoi (val); c2_free (val); } #endif else { buf = g_strconcat ("Unknown command in rc file: ", key, NULL); cronos_error (ERROR_INTERNAL, buf, ERROR_WARNING); c2_free (val); } c2_free (key); } fclose (fd); }