示例#1
0
文件: mh.c 项目: ignatenkobrain/claws
static MsgInfo *mh_parse_msg(const gchar *file, FolderItem *item)
{
	MsgInfo *msginfo;
	MsgFlags flags;

	cm_return_val_if_fail(item != NULL, NULL);
	cm_return_val_if_fail(file != NULL, NULL);

	flags.perm_flags = MSG_NEW|MSG_UNREAD;
	flags.tmp_flags = 0;

	if (folder_has_parent_of_type(item, F_QUEUE)) {
		MSG_SET_TMP_FLAGS(flags, MSG_QUEUED);
	} else if (folder_has_parent_of_type(item, F_DRAFT)) {
		MSG_SET_TMP_FLAGS(flags, MSG_DRAFT);
	}

	msginfo = procheader_parse_file(file, flags, FALSE, FALSE);
	if (!msginfo) return NULL;

	msginfo->msgnum = atoi(file);
	msginfo->folder = item;

	return msginfo;
}
示例#2
0
MsgInfo *procmsg_msginfo_new_from_mimeinfo(MsgInfo *src_msginfo, MimeInfo *mimeinfo)
{
	MsgInfo *tmp_msginfo = NULL;
	MsgFlags flags = {0, 0};
	
	
	if (!mimeinfo || mimeinfo->type != MIMETYPE_MESSAGE ||
	    g_strcasecmp(mimeinfo->subtype, "rfc822")) {
		g_warning("procmsg_msginfo_new_from_mimeinfo(): unsuitable mimeinfo");
		return NULL;
	}
		    
	if (mimeinfo->content == MIMECONTENT_MEM) {
		gchar *tmpfile = get_tmp_file();
		str_write_to_file(mimeinfo->data.mem, tmpfile);
		g_free(mimeinfo->data.mem);
		mimeinfo->content == MIMECONTENT_FILE;
		mimeinfo->data.filename = g_strdup(tmpfile);
		g_free(tmpfile);
	}

	tmp_msginfo = procheader_parse_file(mimeinfo->data.filename,
				flags, TRUE, FALSE);

	if (tmp_msginfo != NULL) {
		tmp_msginfo->folder = src_msginfo->folder;
		tmp_msginfo->plaintext_file = g_strdup(mimeinfo->data.filename);
	} else {
		g_warning("procmsg_msginfo_new_from_mimeinfo(): Can't generate new msginfo");
	}
	
	return tmp_msginfo;
}
示例#3
0
void mimeview_print_part(MimeView *mimeview, MimeInfo *partinfo)
{
	g_return_if_fail(partinfo != NULL);

	if (!mimeview->messageview->file) return;

	if (partinfo->mime_type == MIME_MESSAGE_RFC822) {
		gchar *filename;
		MsgInfo *msginfo;
		MsgFlags flags = {0, 0};

		filename = procmime_get_tmp_file_name(partinfo);
		if (procmime_get_part(filename, mimeview->messageview->file, partinfo) < 0) {
			alertpanel_error
				(_("Can't save the part of multipart message."));
			g_free(filename);
			return;
		}

		msginfo = procheader_parse_file(filename, flags, TRUE);
		msginfo->file_path = filename;
		filename = NULL;
		printing_print_message
			(msginfo, mimeview->textview->show_all_headers);
		procmsg_msginfo_free(msginfo);
	} else if (partinfo->mime_type == MIME_TEXT ||
		   partinfo->mime_type == MIME_TEXT_HTML) {
		printing_print_message_part(mimeview->messageview->msginfo,
					    partinfo);
	}
}
示例#4
0
MsgInfo *procmsg_msginfo_get_full_info(MsgInfo *msginfo)
{
	MsgInfo *full_msginfo;
	gchar *file;

	if (msginfo == NULL) return NULL;

	file = procmsg_get_message_file_path(msginfo);
	if (!file || !is_file_exist(file)) {
		g_free(file);
		file = procmsg_get_message_file(msginfo);
	}
	if (!file || !is_file_exist(file)) {
		g_warning("procmsg_msginfo_get_full_info(): can't get message file.\n");
		return NULL;
	}

	full_msginfo = procheader_parse_file(file, msginfo->flags, TRUE, FALSE);
	g_free(file);
	if (!full_msginfo) return NULL;

	/* CLAWS: make sure we add the missing members; see: 
	 * procheader.c::procheader_get_headernames() */
	if (!msginfo->xface)
		msginfo->xface = g_strdup(full_msginfo->xface);
	if (!msginfo->dispositionnotificationto)
		msginfo->dispositionnotificationto = 
			g_strdup(full_msginfo->dispositionnotificationto);
	if (!msginfo->returnreceiptto)
		msginfo->returnreceiptto = g_strdup
			(full_msginfo->returnreceiptto);
	if (!msginfo->partial_recv && full_msginfo->partial_recv)
		msginfo->partial_recv = g_strdup
			(full_msginfo->partial_recv);
	msginfo->total_size = full_msginfo->total_size;
	if (!msginfo->account_server && full_msginfo->account_server)
		msginfo->account_server = g_strdup
			(full_msginfo->account_server);
	if (!msginfo->account_login && full_msginfo->account_login)
		msginfo->account_login = g_strdup
			(full_msginfo->account_login);
	msginfo->planned_download = full_msginfo->planned_download;
	procmsg_msginfo_free(full_msginfo);

	return procmsg_msginfo_new_ref(msginfo);
}
示例#5
0
static void mimeview_reply(MimeView *mimeview, guint action)
{
	MimeInfo *partinfo;
	gchar *filename;
	MsgInfo *msginfo;
	MsgFlags flags = {0, 0};
	ComposeMode mode = action;

	if (!mimeview->opened) return;
	if (!mimeview->messageview->file) return;

	partinfo = mimeview_get_selected_part(mimeview);
	g_return_if_fail(partinfo != NULL);

	if (partinfo->mime_type != MIME_MESSAGE_RFC822)
		return;

	filename = procmime_get_tmp_file_name(partinfo);
	if (procmime_get_part(filename, mimeview->messageview->file, partinfo) < 0) {
		alertpanel_error
			(_("Can't save the part of multipart message."));
			g_free(filename);
			return;
	}

	msginfo = procheader_parse_file(filename, flags, TRUE);
	msginfo->file_path = filename;
	filename = NULL;
	if (prefs_common.reply_with_quote)
		mode |= COMPOSE_WITH_QUOTE;

	if (mimeview->messageview->mainwin)
		compose_reply(msginfo, mimeview->messageview->mainwin->summaryview->folder_item,
			      mode, NULL);
	else
		compose_reply(msginfo, NULL, mode, NULL);

	g_unlink(msginfo->file_path);
	procmsg_msginfo_free(msginfo);
}
示例#6
0
static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
{
	gchar *path;
	gchar *pathnew;
	FILE *fp;
	FILE *fpnew;
	gchar buf[POPBUFSIZE];
	gchar uidl[POPBUFSIZE];
	time_t recv_time;
	time_t now;
	gchar partial_recv[POPBUFSIZE];
	int err = -1;
	gchar *filename;
	MsgInfo *tinfo;
	gchar *sanitized_uid = NULL;	

	filename = procmsg_get_message_file_path(msginfo);
	if (!filename) {
		g_warning("can't get message file path.");
		return err;
	}
	tinfo = procheader_parse_file(filename, msginfo->flags, TRUE, TRUE);
	
	if (!tinfo->extradata) {
		g_free(filename);
		return err;
	}

	sanitized_uid = g_strdup(tinfo->extradata->account_login);
	subst_for_filename(sanitized_uid);

	if (!tinfo->extradata->account_server
	||  !tinfo->extradata->account_login
	||  !tinfo->extradata->partial_recv) {
		goto bail;
	}
	path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
			   "uidl", G_DIR_SEPARATOR_S, tinfo->extradata->account_server,
			   "-", sanitized_uid, NULL);

	if ((fp = g_fopen(path, "rb")) == NULL) {
		perror("fopen1");
		if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
		g_free(path);
		path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
				   "uidl-", tinfo->extradata->account_server,
				   "-", tinfo->extradata->account_login, NULL);
		if ((fp = g_fopen(path, "rb")) == NULL) {
			if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
			g_free(path);
			goto bail;
		}
	}

	pathnew = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
			   "uidl", G_DIR_SEPARATOR_S, tinfo->extradata->account_server,
			   "-", sanitized_uid, ".new", NULL);
	
	g_free(sanitized_uid);

	if ((fpnew = g_fopen(pathnew, "wb")) == NULL) {
		perror("fopen2");
		fclose(fp);
		g_free(pathnew);
		goto bail;
	}
	
	now = time(NULL);

	while (fgets(buf, sizeof(buf), fp) != NULL) {
		strretchomp(buf);
		recv_time = RECV_TIME_NONE;
		sprintf(partial_recv,"0");
		
		if (sscanf(buf, "%s\t%ld\t%s", 
			   uidl, (long int *) &recv_time, partial_recv) < 2) {
			if (sscanf(buf, "%s", uidl) != 1)
				continue;
			else {
				recv_time = now;
			}
		}
		if (strcmp(tinfo->extradata->partial_recv, uidl)) {
			if (fprintf(fpnew, "%s\t%ld\t%s\n", 
				uidl, (long int) recv_time, partial_recv) < 0) {
				FILE_OP_ERROR(pathnew, "fprintf");
				fclose(fpnew);
				fclose(fp);
				g_free(path);
				g_free(pathnew);
				goto bail;
			}
		} else {
			gchar *stat = NULL;
			if (download == POP3_PARTIAL_DLOAD_DLOAD) {
				gchar *folder_id = folder_item_get_identifier(
							msginfo->folder);
				stat = g_strdup_printf("%s:%d",
					folder_id, msginfo->msgnum);
				g_free(folder_id);
			}
			else if (download == POP3_PARTIAL_DLOAD_UNKN)
				stat = g_strdup("1");
			else if (download == POP3_PARTIAL_DLOAD_DELE)
				stat = g_strdup("0");
			
			if (fprintf(fpnew, "%s\t%ld\t%s\n", 
				uidl, (long int) recv_time, stat) < 0) {
				FILE_OP_ERROR(pathnew, "fprintf");
				fclose(fpnew);
				fclose(fp);
				g_free(path);
				g_free(pathnew);
				goto bail;
			}
			g_free(stat);
		}
	}
	if (fclose(fpnew) == EOF) {
		FILE_OP_ERROR(pathnew, "fclose");
		fclose(fp);
		g_free(path);
		g_free(pathnew);
		goto bail;
	}
	fclose(fp);

	move_file(pathnew, path, TRUE);

	g_free(path);
	g_free(pathnew);
	
	if ((fp = g_fopen(filename,"rb")) == NULL) {
		perror("fopen3");
		goto bail;
	}
	pathnew = g_strdup_printf("%s.new", filename);
	if ((fpnew = g_fopen(pathnew, "wb")) == NULL) {
		perror("fopen4");
		fclose(fp);
		g_free(pathnew);
		goto bail;
	}
	
	if (fprintf(fpnew, "SC-Marked-For-Download: %d\n", 
			download) < 0) {
		FILE_OP_ERROR(pathnew, "fprintf");
		fclose(fpnew);
		fclose(fp);
		g_free(pathnew);
		goto bail;
	}
	while (fgets(buf, sizeof(buf)-1, fp) != NULL) {
		if(strlen(buf) > strlen("SC-Marked-For-Download: x\n")
		&& !strncmp(buf, "SC-Marked-For-Download:", 
		            strlen("SC-Marked-For-Download:"))) {
			if (fprintf(fpnew, "%s", 
			 buf+strlen("SC-Marked-For-Download: x\n")) < 0) {
				FILE_OP_ERROR(pathnew, "fprintf");
				fclose(fpnew);
				fclose(fp);
				g_free(pathnew);
				goto bail;
			}
			continue;
		} else if (strlen(buf) == strlen("SC-Marked-For-Download: x\n")
		&& !strncmp(buf, "SC-Marked-For-Download:", 
		            strlen("SC-Marked-For-Download:"))) {
			continue;
		}
		if (fprintf(fpnew, "%s", buf) < 0) {
			FILE_OP_ERROR(pathnew, "fprintf");
			fclose(fpnew);
			fclose(fp);
			g_free(pathnew);
			goto bail;
		}
	}
	if (fclose(fpnew) == EOF) {
		FILE_OP_ERROR(pathnew, "fclose");
		fclose(fp);
		g_free(pathnew);
		goto bail;
	}

	fclose(fp);
	if (rename_force(pathnew, filename) != 0) {
		g_free(pathnew);
		goto bail;
	}

	g_free(pathnew);
	msginfo->planned_download = download;
	msgcache_update_msg(msginfo->folder->cache, msginfo);

	err = 0;
bail:
	g_free(filename);
	procmsg_msginfo_free(&tinfo);
	
	return err;
}