예제 #1
0
파일: news.c 프로젝트: Mortal/claws
gint news_cancel_article(Folder * folder, MsgInfo * msginfo)
{
	gchar * tmp;
	FILE * tmpfp;
	gchar buf[BUFFSIZE];

	tmp = g_strdup_printf("%s%ccancel%p", get_tmp_dir(),
			      G_DIR_SEPARATOR, msginfo);
	if (tmp == NULL)
		return -1;

	if ((tmpfp = g_fopen(tmp, "wb")) == NULL) {
		FILE_OP_ERROR(tmp, "fopen");
		return -1;
	}
	if (change_file_mode_rw(tmpfp, tmp) < 0) {
		FILE_OP_ERROR(tmp, "chmod");
		g_warning("can't change file mode");
	}
	
	get_rfc822_date(buf, sizeof(buf));
	if (fprintf(tmpfp, "From: %s\r\n"
		       "Newsgroups: %s\r\n"
		       "Subject: cmsg cancel <%s>\r\n"
		       "Control: cancel <%s>\r\n"
		       "Approved: %s\r\n"
		       "X-Cancelled-by: %s\r\n"
		       "Date: %s\r\n"
		       "\r\n"
		       "removed with Claws Mail\r\n",
		       msginfo->from,
		       msginfo->newsgroups,
		       msginfo->msgid,
		       msginfo->msgid,
		       msginfo->from,
		       msginfo->from,
		       buf) < 0) {
		FILE_OP_ERROR(tmp, "fprintf");
		fclose(tmpfp);
		claws_unlink(tmp);
		g_free(tmp);
		return -1;
	}

	if (fclose(tmpfp) == EOF) {
		FILE_OP_ERROR(tmp, "fclose");
		claws_unlink(tmp);
		g_free(tmp);
		return -1;
	}

	news_post(folder, tmp);
	claws_unlink(tmp);

	g_free(tmp);

	return 0;
}
예제 #2
0
static gboolean mail_receive_hook(gpointer source, gpointer data)
{
	MailReceiveData *mail_receive_data = (MailReceiveData *) source;
	Pop3Session *session;
	gchar *newheaders;
	gchar *newdata;
	gchar date[PREFSBUFSIZE];
	
	if (!config.fetchinfo_enable) {
		return FALSE;
	}

	g_return_val_if_fail( 
			      mail_receive_data
			      && mail_receive_data->session
			      && mail_receive_data->data,
			      FALSE );

	session = mail_receive_data->session;
	get_rfc822_date(date, PREFSBUFSIZE);
	newheaders = g_strdup("");

	if (config.fetchinfo_uidl)
		fetchinfo_add_header(&newheaders, "X-FETCH-UIDL", 
			session->msg[session->cur_msg].uidl);
	if (config.fetchinfo_account)
		fetchinfo_add_header(&newheaders, "X-FETCH-ACCOUNT", 
			session->ac_prefs->account_name);
	if (config.fetchinfo_server)
		fetchinfo_add_header(&newheaders, "X-FETCH-SERVER", 
			session->ac_prefs->recv_server);
	if (config.fetchinfo_userid)
		fetchinfo_add_header(&newheaders, "X-FETCH-USERID", 
			session->ac_prefs->userid);
	if (config.fetchinfo_time)
		fetchinfo_add_header(&newheaders, "X-FETCH-TIME", 
			date);

	newdata = g_strconcat(newheaders, mail_receive_data->data, NULL);
	g_free(newheaders);
	g_free(mail_receive_data->data);
	mail_receive_data->data = newdata;
	mail_receive_data->data_len = strlen(newdata);
	return FALSE;
}
예제 #3
0
static void send_with_encryption(gpointer compose)
{
	GSList *alist, *cur;
	GHashTable *hash;
	SylPluginAttachInfo *ainfo;
	gboolean duplicated = FALSE;
	GtkWidget *dialog;
	gchar *password;
	const gchar *tmp_path;
	const gchar *arc_path;
	gchar *zip_path;
	gchar *filename;
	GString *cmdline;
	gint ret;
	gchar *orig_to;
	gchar *orig_cc;
	gchar *orig_bcc;
	gchar *orig_replyto;
	gchar *orig_subject;
	gchar *subject;
	gchar *body;
	gchar send_date[80];

	/* Check attachments */
	alist = syl_plugin_get_attach_list(compose);
	if (!alist) {
		syl_plugin_alertpanel_message(_("No attachment"), _("There is no attachment. Please attach files before sending."), 3);
		return;
	}
	hash = g_hash_table_new(str_case_hash, str_case_equal);
	for (cur = alist; cur != NULL; cur = cur->next) {
		const gchar *base;
		ainfo = (SylPluginAttachInfo *)cur->data;
		debug_print("attach: file: %s (%s) name: %s\n", ainfo->file, ainfo->content_type, ainfo->name);
		base = g_basename(ainfo->file);
		if (g_hash_table_lookup(hash, base)) {
			duplicated = TRUE;
			break;
		} else {
			g_hash_table_insert(hash, (gpointer)base, (gpointer)base);
		}
	}
	g_hash_table_destroy(hash);
	if (duplicated) {
		syl_plugin_alertpanel_message(_("Duplicate filename"), _("There are duplicate filenames. Multiple files with same name cannot be attached."), 3);
		return;
	}

	/* Get recipients */
	orig_to = syl_plugin_compose_entry_get_text(compose, 0);
	orig_cc = syl_plugin_compose_entry_get_text(compose, 1);
	orig_bcc = syl_plugin_compose_entry_get_text(compose, 2);
	orig_replyto = syl_plugin_compose_entry_get_text(compose, 3);
	orig_subject = syl_plugin_compose_entry_get_text(compose, 4);
	if (orig_to) g_strstrip(orig_to);
	if (orig_cc) g_strstrip(orig_cc);
	if (orig_bcc) g_strstrip(orig_bcc);

	if ((!orig_to || *orig_to == '\0') &&
	    (!orig_cc || *orig_cc == '\0') &&
	    (!orig_bcc || *orig_bcc == '\0')) {
		syl_plugin_alertpanel_message(_("No recipients"), _("Recipient is not specified."), 3);
		g_free(orig_subject);
		g_free(orig_replyto);
		g_free(orig_bcc);
		g_free(orig_cc);
		g_free(orig_to);
		return;
	}

	/* Show processing dialog */
	dialog = autoenc_processing_dialog_create();

	/* Generate password */
	password = generate_password();

	/* Generate encrypted zip */
	filename = generate_filename();
	tmp_path = get_autoenc_tmp_dir();
	if (!is_dir_exist(tmp_path)) {
		make_dir(tmp_path);
	}
	arc_path = get_7z_path();
	zip_path = g_strconcat(tmp_path, G_DIR_SEPARATOR_S,
			       filename, NULL);
	cmdline = g_string_new("");
	if (arc_path) {
		g_string_append_printf(cmdline, "\"%s\\7z\" a -y ", arc_path);
	} else {
		g_string_append(cmdline, "7z a -y ");
	}
	g_string_append(cmdline, "-p");
	g_string_append(cmdline, password);
	g_string_append(cmdline, " ");
	g_string_append_printf(cmdline, "\"%s\"", zip_path);
	for (cur = alist; cur != NULL; cur = cur->next) {
		ainfo = (SylPluginAttachInfo *)cur->data;
		g_string_append(cmdline, " ");
		g_string_append_printf(cmdline, "\"%s\"", ainfo->file);
	}
	debug_print("cmdline: %s\n", cmdline->str);
	ret = execute_command_line_async_wait(cmdline->str);

	/* Close processing dialog */
	gtk_widget_destroy(dialog);

	// check if zip was really created
	if (ret != 0 || !is_file_exist(zip_path) || get_file_size(zip_path) <= 0) {
		gchar message[256];

		if (ret < 0) {
			g_snprintf(message, sizeof(message), _("Error occurred while creating encrypted zip file.\n\n7z command could not be executed. Please check if 7-Zip is correctly installed."));
		} else if (ret > 0) {
			g_snprintf(message, sizeof(message), _("Error occurred while creating encrypted zip file.\n\n7z command returned error (%d)"), ret);
		} else {
			g_snprintf(message, sizeof(message), _("Encrypted zip file could not be created."));
		}
		syl_plugin_alertpanel_message(_("Encrypted zip file creation error"), message, 3);
		g_string_free(cmdline, TRUE);
		g_free(zip_path);
		g_free(filename);
		g_free(password);
		g_free(orig_subject);
		g_free(orig_replyto);
		g_free(orig_bcc);
		g_free(orig_cc);
		g_free(orig_to);
		g_slist_free(alist);
		return;
	}
	g_string_free(cmdline, TRUE);
	g_slist_free(alist);

	/* Replace attachments */
	syl_plugin_compose_attach_remove_all(compose);
	syl_plugin_compose_attach_append(compose, zip_path, filename,
					 "application/zip");

	/* Send */
	get_rfc822_date(send_date, sizeof(send_date));
	ret = syl_plugin_compose_send(compose, TRUE);
	if (ret != 0) {
		g_free(zip_path);
		g_free(filename);
		g_free(password);
		g_free(orig_subject);
		g_free(orig_replyto);
		g_free(orig_bcc);
		g_free(orig_cc);
		g_free(orig_to);
		return;
	}

	/* Create password mail */
	subject = create_password_mail_subject(orig_subject, send_date, filename, password);
	body = create_password_mail_body(orig_subject, send_date, filename, password);
	debug_print("%s\n", body);

	compose = syl_plugin_compose_new(NULL, NULL, body, NULL);
	syl_plugin_compose_entry_set(compose, orig_to, 0);
	syl_plugin_compose_entry_set(compose, orig_cc, 1);
	if (orig_bcc && *orig_bcc != '\0')
		syl_plugin_compose_entry_set(compose, orig_bcc, 2);
	if (orig_replyto && *orig_replyto != '\0')
		syl_plugin_compose_entry_set(compose, orig_replyto, 3);
	syl_plugin_compose_entry_set(compose, subject, 4);

	/* Cleanup */
	g_free(body);
	g_free(subject);
	g_free(zip_path);
	g_free(filename);
	g_free(password);
	g_free(orig_subject);
	g_free(orig_replyto);
	g_free(orig_bcc);
	g_free(orig_cc);
	g_free(orig_to);
}