static void is_info_cb(ImapMboxHandle *h, ImapResponse rc, const gchar* str, void *arg) { LibBalsaInformationType it; LibBalsaServer *is = LIBBALSA_SERVER(arg); const gchar *fmt; switch(rc) { case IMR_ALERT: /* IMAP host name + message */ fmt = _("IMAP server %s alert:\n%s"); it = LIBBALSA_INFORMATION_ERROR; break; case IMR_BAD: /* IMAP host name + message */ fmt = _("IMAP server %s error: %s"); it = LIBBALSA_INFORMATION_ERROR; break; case IMR_BYE: case IMR_NO: /* IMAP host name + message */ fmt = "%s: %s"; it = LIBBALSA_INFORMATION_MESSAGE; break; default: return; } libbalsa_information(it, fmt, is->host, str); }
static gboolean move_from_msgdrop(const gchar *tmp_path, LibBalsaMailbox *dest, gchar *pop_name, unsigned msgno) { gint fd; GMimeStream *stream; gboolean success; GError *err = NULL; struct stat buf; if(stat(tmp_path, &buf) != 0) return FALSE; if(buf.st_size == 0) /* filtered out? Nothing to move in any case */ return TRUE; fd = open(tmp_path, O_RDWR); stream = g_mime_stream_fs_new(fd); success = libbalsa_mailbox_add_message(dest, stream, LIBBALSA_MESSAGE_FLAG_NEW | LIBBALSA_MESSAGE_FLAG_RECENT, &err) && ftruncate(fd, 0) == 0; g_object_unref(stream); if(!success) libbalsa_information(LIBBALSA_INFORMATION_WARNING, _("Error appending message %d from %s to %s: %s"), msgno, pop_name, dest->name, err ? err->message : "?"); g_clear_error(&err); return success; }
static gint lbm_mh_check_files(const gchar * path, gboolean create) { g_return_val_if_fail(path != NULL, -1); if (access(path, F_OK) == 0) { /* File exists. Check if it is a mh... */ if (libbalsa_mailbox_type_from_path(path) != LIBBALSA_TYPE_MAILBOX_MH) { libbalsa_information(LIBBALSA_INFORMATION_WARNING, _("Mailbox %s does not appear to be an MH mailbox."), path); return -1; } } else if (create) { gint fd; gchar *sequences_filename; if (mkdir(path, S_IRWXU)) { libbalsa_information(LIBBALSA_INFORMATION_WARNING, _("Could not create MH directory at %s (%s)"), path, strerror(errno)); return -1; } sequences_filename = g_build_filename(path, ".mh_sequences", NULL); fd = creat(sequences_filename, S_IRWXU); g_free(sequences_filename); if (fd == -1) { libbalsa_information (LIBBALSA_INFORMATION_WARNING, _("Could not create MH structure at %s (%s)"), path, strerror(errno)); rmdir(path); return -1; } else close(fd); } else return -1; return 0; }
static void lbm_mh_remove_files(LibBalsaMailboxLocal *mailbox) { const gchar* path; g_return_if_fail(LIBBALSA_IS_MAILBOX_MH(mailbox)); path = libbalsa_mailbox_local_get_path(mailbox); if (!libbalsa_delete_directory_contents(path)) { libbalsa_information(LIBBALSA_INFORMATION_ERROR, _("Could not remove contents of %s:\n%s"), path, strerror(errno)); return; } if ( rmdir(path) == -1 ) { libbalsa_information(LIBBALSA_INFORMATION_ERROR, _("Could not remove %s:\n%s"), path, strerror(errno)); } LIBBALSA_MAILBOX_LOCAL_CLASS(parent_class)->remove_files(mailbox); }
static void lsv_escape_change_state(GSimpleAction * action, GVariant * state, gpointer user_data) { LibBalsaSourceViewerInfo *lsvi = g_object_get_data(G_OBJECT(user_data), "lsvi"); LibBalsaMessage *msg = lsvi->msg; GMimeStream *msg_stream; GMimeStream *mem_stream; char *raw_message; if (!msg->mailbox) { libbalsa_information(LIBBALSA_INFORMATION_WARNING, _("Mailbox closed")); return; } msg_stream = libbalsa_mailbox_get_message_stream(msg->mailbox, msg->msgno, TRUE); if (msg_stream == NULL) return; mem_stream = g_mime_stream_mem_new(); libbalsa_mailbox_lock_store(msg->mailbox); g_mime_stream_write_to_stream(msg_stream, mem_stream); libbalsa_mailbox_unlock_store(msg->mailbox); g_mime_stream_write(mem_stream, "", 1); /* close string */ raw_message = (char *) GMIME_STREAM_MEM(mem_stream)->buffer->data; *(lsvi->escape_specials) = g_variant_get_boolean(state); lsv_show_message(raw_message, lsvi, *(lsvi->escape_specials)); g_object_unref(msg_stream); g_object_unref(mem_stream); g_simple_action_set_state(action, state); }
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)); }
void libbalsa_show_message_source(GtkApplication * application, LibBalsaMessage * msg, const gchar * font, gboolean * escape_specials, gint * width, gint * height) { GtkWidget *text; gchar *css; GtkCssProvider *css_provider; GtkWidget *vbox, *interior; GtkWidget *window; gchar *ui_file; GtkWidget *menu_bar; GError *err = NULL; LibBalsaSourceViewerInfo *lsvi; GAction *escape_action; g_return_if_fail(msg); g_return_if_fail(MAILBOX_OPEN(msg->mailbox)); text = gtk_text_view_new(); gtk_widget_set_name(text, BALSA_SOURCE_VIEWER); css = libbalsa_font_string_to_css(font, BALSA_SOURCE_VIEWER); css_provider = gtk_css_provider_new(); gtk_css_provider_load_from_data(css_provider, css, -1, NULL); g_free(css); gtk_style_context_add_provider(gtk_widget_get_style_context(text) , GTK_STYLE_PROVIDER(css_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); g_object_unref(css_provider); gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR); interior = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(interior), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); gtk_container_add(GTK_CONTAINER(interior), GTK_WIDGET(text)); window = gtk_application_window_new(application); gtk_window_set_title(GTK_WINDOW(window), _("Message Source")); gtk_window_set_role(GTK_WINDOW(window), "message-source"); gtk_window_set_default_size(GTK_WINDOW(window), *width, *height); ui_file = g_build_filename(BALSA_DATA_PREFIX, "ui", "source-viewer.ui", NULL); menu_bar = libbalsa_window_get_menu_bar(GTK_APPLICATION_WINDOW(window), win_entries, G_N_ELEMENTS(win_entries), ui_file, &err, window); if (!menu_bar) { libbalsa_information(LIBBALSA_INFORMATION_WARNING, _("Error adding from %s: %s\n"), ui_file, err->message); g_free(ui_file); g_error_free(err); return; } g_free(ui_file); vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 1); #if HAVE_MACOSX_DESKTOP libbalsa_macosx_menu(window, GTK_MENU_SHELL(menu_bar)); #else gtk_box_pack_start(GTK_BOX(vbox), menu_bar, FALSE, TRUE, 1); #endif gtk_box_pack_start(GTK_BOX(vbox), interior, TRUE, TRUE, 0); gtk_container_add(GTK_CONTAINER(window), vbox); lsvi = g_new(LibBalsaSourceViewerInfo, 1); lsvi->msg = g_object_ref(msg); lsvi->text = text; lsvi->window = window; lsvi->escape_specials = escape_specials; lsvi->width = width; lsvi->height = height; g_object_set_data_full(G_OBJECT(window), "lsvi", lsvi, (GDestroyNotify) lsv_window_destroy_notify); g_signal_connect(window, "size-allocate", G_CALLBACK(lsv_size_allocate_cb), lsvi); gtk_widget_show_all(window); escape_action = g_action_map_lookup_action(G_ACTION_MAP(window), "lsv-escape"); lsv_escape_change_state(G_SIMPLE_ACTION(escape_action), g_variant_new_boolean(*escape_specials), window); }
static void lbc_init(LibBalsaConf * conf, const gchar * filename, const gchar * old_dir) { struct stat buf; GError *error = NULL; gint rc; if (!conf->path) conf->path = g_build_filename(g_get_home_dir(), ".balsa", filename, NULL); rc = stat(conf->path, &buf); if (conf->key_file) { if (rc >= 0 && buf.st_mtime <= conf->mtime) /* found the config file, and it hasn't been touched since * we loaded it */ return; } else { conf->key_file = g_key_file_new(); if (rc < 0) /* no config file--must be first time startup */ return; } conf->mtime = buf.st_mtime; libbalsa_assure_balsa_dir(); if (!g_key_file_load_from_file (conf->key_file, conf->path, G_KEY_FILE_NONE, &error)) { gchar *old_path; gchar *buf; static gboolean warn = TRUE; old_path = g_build_filename(g_get_home_dir(), old_dir, "balsa", NULL); #if DEBUG g_message("Could not load config from \"%s\":\n %s\n" " trying \"%s\"", conf->path, error->message, old_path); #endif /* DEBUG */ g_clear_error(&error); buf = lbc_readfile(old_path); if (buf) { /* GnomeConfig used ' ' as the list separator... */ g_key_file_set_list_separator(conf->key_file, ' '); g_key_file_load_from_data(conf->key_file, buf, -1, G_KEY_FILE_KEEP_COMMENTS, &error); g_free(buf); /* ...but GKeyFile doesn't handle it properly, so we'll * revert to the default ';'. */ g_key_file_set_list_separator(conf->key_file, ';'); } if (!buf || error) { #if DEBUG g_message("Could not load key file from file \"%s\": %s", old_path, error ? error->message : g_strerror(errno)); #endif /* DEBUG */ g_clear_error(&error); warn = FALSE; } g_free(old_path); if (warn) libbalsa_information(LIBBALSA_INFORMATION_WARNING, _("Your Balsa configuration " "is now stored in " "\"~/.balsa/config\".")); } }
static BalsaMimeWidget * balsa_mime_widget_new_unknown(BalsaMessage * bm, LibBalsaMessageBody * mime_body, const gchar * content_type) { GtkWidget *hbox; GtkWidget *button = NULL; gchar *msg; GtkWidget *msg_label; gchar *content_desc; BalsaMimeWidget *mw; gchar *use_content_type; g_return_val_if_fail(mime_body, NULL); mw = g_object_new(BALSA_TYPE_MIME_WIDGET, NULL); mw->widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, BMW_VBOX_SPACE); gtk_container_set_border_width(GTK_CONTAINER(mw->widget), BMW_CONTAINER_BORDER); if (mime_body->filename) { msg = g_strdup_printf(_("File name: %s"), mime_body->filename); gtk_box_pack_start(GTK_BOX(mw->widget), gtk_label_new(msg), FALSE, FALSE, 0); g_free(msg); } /* guess content_type if not specified or if generic app/octet-stream */ /* on local mailboxes only, to avoid possibly long downloads */ if ((content_type == NULL || g_ascii_strcasecmp(content_type, "application/octet-stream") == 0) && LIBBALSA_IS_MAILBOX_LOCAL(mime_body->message->mailbox)) { GError *err = NULL; gpointer buffer; GMimeStream *stream = libbalsa_message_body_get_stream(mime_body, &err); if(!stream) { libbalsa_information(LIBBALSA_INFORMATION_ERROR, _("Error reading message part: %s"), err ? err->message : "Unknown error"); g_clear_error(&err); use_content_type = g_strdup(content_type); } else { ssize_t length = 1024 /* g_mime_stream_length(stream) */ ; ssize_t size; buffer = g_malloc(length); libbalsa_mime_stream_shared_lock(stream); size = g_mime_stream_read(stream, buffer, length); libbalsa_mime_stream_shared_unlock(stream); g_object_unref(stream); use_content_type = libbalsa_vfs_content_type_of_buffer(buffer, size); if (g_ascii_strncasecmp(use_content_type, "text", 4) == 0 && (libbalsa_text_attr_string(buffer) & LIBBALSA_TEXT_HI_BIT)) { /* Hmmm...better stick with application/octet-stream. */ g_free(use_content_type); use_content_type = g_strdup("application/octet-stream"); } g_free(buffer); } } else use_content_type = g_strdup(content_type); content_desc = libbalsa_vfs_content_description(use_content_type); if (content_desc) { msg = g_strdup_printf(_("Type: %s (%s)"), content_desc, use_content_type); g_free(content_desc); } else msg = g_strdup_printf(_("Content Type: %s"), use_content_type); msg_label = gtk_label_new(msg); g_free(msg); gtk_label_set_ellipsize(GTK_LABEL(msg_label), PANGO_ELLIPSIZE_END); gtk_box_pack_start(GTK_BOX(mw->widget), msg_label, FALSE, FALSE, 0); hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, BMW_HBOX_SPACE); gtk_box_set_homogeneous(GTK_BOX(hbox), TRUE); if ((button = libbalsa_vfs_mime_button(mime_body, use_content_type, G_CALLBACK(balsa_mime_widget_ctx_menu_cb), (gpointer) mime_body))) gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); else gtk_box_pack_start(GTK_BOX(mw->widget), gtk_label_new(_("No open or view action " "defined for this content type")), FALSE, FALSE, 0); g_free(use_content_type); button = gtk_button_new_with_mnemonic(_("S_ave part")); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(balsa_mime_widget_ctx_menu_save), (gpointer) mime_body); gtk_box_pack_start(GTK_BOX(mw->widget), hbox, FALSE, FALSE, 0); return mw; }