Esempio n. 1
0
FILE *procmsg_open_message(MsgInfo *msginfo)
{
	FILE *fp;
	gchar *file;

	g_return_val_if_fail(msginfo != NULL, NULL);

	file = procmsg_get_message_file_path(msginfo);
	g_return_val_if_fail(file != NULL, NULL);

	if (!is_file_exist(file)) {
		g_free(file);
		file = procmsg_get_message_file(msginfo);
		if (!file)
			return NULL;
	}

	if ((fp = fopen(file, "rb")) == NULL) {
		FILE_OP_ERROR(file, "fopen");
		g_free(file);
		return NULL;
	}

	g_free(file);

	if (MSG_IS_QUEUED(msginfo->flags) || MSG_IS_DRAFT(msginfo->flags)) {
		gchar buf[BUFFSIZE];

		while (fgets(buf, sizeof(buf), fp) != NULL)
			if (buf[0] == '\r' || buf[0] == '\n') break;
	}

	return fp;
}
Esempio n. 2
0
gboolean newmail_hook (gpointer source, gpointer data)
{
	auto MsgInfo    *msginfo = (MsgInfo *)source;
	auto FolderItem *tof;

	if (!msginfo) return FALSE;
	if (!NewLog) return FALSE;

	tof = msginfo->folder;
	(void)fprintf (NewLog, "---\n"
		"Date:\t%s\n"
		"Subject:\t%s\n"
		"From:\t%s\n"
		"To:\t%s\n"
		"Cc:\t%s\n"
		"Size:\t%jd\n"
		"Path:\t%s\n"
		"Message:\t%d\n"
		"Folder:\t%s\n",
		defstr (msginfo->date),
		defstr (msginfo->subject),
		defstr (msginfo->from),
		defstr (msginfo->to),
		defstr (msginfo->cc),
		(intmax_t) msginfo->size,
		defstr (procmsg_get_message_file_path (msginfo)),
		msginfo->msgnum,
		tof ? defstr (tof->name) : "(null)");

	return (FALSE);
} /* newmail_hook */
Esempio n. 3
0
static void copy_btn_clicked(GtkButton *button, gpointer data)
{
  
  if (data != NULL) {
    MsgInfo* msginfo = (MsgInfo*)data;
    gchar *msg_path = procmsg_get_message_file_path(msginfo);
    
    debug_print("[DEBUG] msg_path:%s\n", msg_path);

#if defined(G_OS_WIN32)
    LPDROPFILES lpDropFile;

    int mblen = MultiByteToWideChar(CP_UTF8, 0, msg_path, -1, NULL,0);
    WCHAR* pszUnicode = malloc( sizeof(WCHAR)*(mblen+1));
    memset(pszUnicode, sizeof(WCHAR), (mblen+1));

    MultiByteToWideChar(CP_UTF8, 0, msg_path, strlen(msg_path)+1, pszUnicode, mblen);
  

    HDROP hDrop = (HDROP)GlobalAlloc(GHND,sizeof(DROPFILES)+2*mblen+2);
    if (hDrop==NULL) {
      debug_print ("[DEBUG] failed to allocate Global memory.\n");
      return;
    }
  
    debug_print ("[DEBUG] lpDropFile[0] :%p\n", &lpDropFile[0]);
    debug_print ("[DEBUG] lpDropFile[1] :%p\n", &lpDropFile[1]);
    debug_print ("[DEBUG] sizeof DROPFILES :%d\n", sizeof(DROPFILES));
    debug_print ("[DEBUG] wcslen :%d\n", wcslen(pszUnicode));


    lpDropFile = (LPDROPFILES)GlobalLock(hDrop);
    lpDropFile->pFiles = sizeof(DROPFILES);
    lpDropFile->pt.x = 0;
    lpDropFile->pt.y = 0;
    lpDropFile->fNC = FALSE;
    lpDropFile->fWide = TRUE;

    char *buf;
    buf = (char *)(&lpDropFile[1]);
    wcscpy((WCHAR*)buf,pszUnicode);
    buf += 2*wcslen(pszUnicode) + 1;
    *buf++ = 0;
    *buf = 0;

    GlobalUnlock(hDrop);
 
    if (OpenClipboard(0) == 0) {
      debug_print ("[DEBUG] failed to open clipboard.\n");
      GlobalFree(hDrop);
      return;
    }
    EmptyClipboard();
    SetClipboardData(CF_HDROP, hDrop);
    CloseClipboard();
#endif
  } 
}
Esempio n. 4
0
static PyObject* get_FilePath(clawsmail_MessageInfoObject *self, void *closure)
{
  if(self->msginfo) {
    gchar *filepath;
    filepath = procmsg_get_message_file_path(self->msginfo);
    if(filepath) {
      PyObject *retval;
      retval = PyString_FromString(filepath);
      g_free(filepath);
      return retval;
    }
  }
  Py_RETURN_NONE;
}
Esempio n. 5
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);
}
Esempio n. 6
0
gint messageview_show(MessageView *messageview, MsgInfo *msginfo,
		      gboolean all_headers)
{
	gchar *file;
	MimeInfo *mimeinfo;

	g_return_val_if_fail(msginfo != NULL, -1);

	mimeinfo = procmime_scan_message(msginfo);
	if (!mimeinfo) {
		messageview_change_view_type(messageview, MVIEW_TEXT);
		textview_show_error(messageview->textview);
		return -1;
	}

	file = procmsg_get_message_file_path(msginfo);
	if (!file) {
		g_warning("can't get message file path.\n");
		procmime_mimeinfo_free_all(mimeinfo);
		messageview_change_view_type(messageview, MVIEW_TEXT);
		textview_show_error(messageview->textview);
		return -1;
	}

	if (messageview->msginfo != msginfo) {
		procmsg_msginfo_free(messageview->msginfo);
		messageview->msginfo = procmsg_msginfo_get_full_info(msginfo);
		if (!messageview->msginfo)
			messageview->msginfo = procmsg_msginfo_copy(msginfo);
	}

	if (messageview->window && msginfo->subject) {
		gchar *title;

		title = g_strconcat(msginfo->subject, " - Sylpheed", NULL);
		gtk_window_set_title(GTK_WINDOW(messageview->window), title);
		g_free(title);
	}
	headerview_show(messageview->headerview, messageview->msginfo);

	textview_set_all_headers(messageview->textview, all_headers);
	textview_set_all_headers(messageview->mimeview->textview, all_headers);

	if (mimeinfo->mime_type != MIME_TEXT &&
	    (prefs_common.html_only_as_attach ||
	     mimeinfo->mime_type != MIME_TEXT_HTML)) {
		messageview_change_view_type(messageview, MVIEW_MIME);
		mimeview_show_message(messageview->mimeview, mimeinfo, file);
	} else {
		messageview_change_view_type(messageview, MVIEW_TEXT);
		textview_show_message(messageview->textview, mimeinfo, file);
		procmime_mimeinfo_free_all(mimeinfo);
	}

	if (messageview->new_window)
		messageview_set_menu_state(messageview);

	g_free(file);

	return 0;
}
Esempio n. 7
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;
}
Esempio n. 8
0
static void messageview_show_cb(GObject *obj, gpointer msgview,
				MsgInfo *msginfo, gboolean all_headers)
{
  MessageView *messageview;
  HeaderView *headerview;
  GtkWidget *hbox;
  gchar *msg_path;
  GtkWidget *copy_btn;
  GdkPixbuf* pbuf;
  GtkWidget* image;
  GtkTooltips *tip;
  GList* wl;
  gint i;
  gboolean bfound = FALSE;
  gpointer gdata;

  
#if DEBUG
  g_print("[DEBUG] test: %p: messageview_show (%p), all_headers: %d: %s\n",
	  obj, msgview, all_headers,
	  msginfo && msginfo->subject ? msginfo->subject : "");
#endif
  
  if (!msgview) {
    g_print("[DEBUG] msgview is NULL\n");
    return;
  }

  messageview = (MessageView*)msgview;
  if (!messageview) {
    g_print("[DEBUG] messageview is NULL\n");
    return;
  }

  headerview = messageview->headerview;
  if (!headerview) {
    g_print("[DEBUG] headerview is NULL\n");
    return;
  }
  
  hbox = headerview->hbox;
  if (!hbox) {
    g_print("[DEBUG] hbox is NULL\n");
    return;
  }

  wl = gtk_container_get_children(GTK_CONTAINER(hbox));

  i = g_list_length(wl)-1;

  /* search recently added GtkImage */
  while (i >= 0) {
    gdata = g_list_nth_data(wl, i);
    if (GTK_IS_BUTTON(gdata) && gdata != headerview->image) {
      /* remove from hbox */
      g_print("[DEBUG] GTK_IS_BUTTON %p\n", gdata);
#if DEBUG
      g_print("[DEBUG] remove button: %p\n", gicon);
#endif
      gtk_container_remove(GTK_CONTAINER(hbox), GTK_WIDGET(gdata));
    }
    i--;
  }


  msg_path = procmsg_get_message_file_path(msginfo);
                    

  debug_print("[DEBUG] msg_path:%s\n", msg_path);


  if (bfound != TRUE){
    copy_btn = gtk_button_new_from_stock(GTK_STOCK_FILE);
    gtk_box_pack_end(GTK_BOX(hbox), copy_btn, FALSE, FALSE, 0);

    pbuf = gdk_pixbuf_new_from_xpm_data((const char**)page_save);
    image = gtk_image_new_from_pixbuf(pbuf);
    
    gtk_button_set_image(GTK_BUTTON(copy_btn), image);
    gtk_button_set_label(GTK_BUTTON(copy_btn), "");

    tip = gtk_tooltips_new();
    gtk_tooltips_set_tip(tip, copy_btn, _("Copy this mail to clipboard."), NULL);

    g_signal_connect(G_OBJECT(copy_btn), "clicked",
		     G_CALLBACK(copy_btn_clicked), msginfo);
    
    gtk_widget_show(image);
    gtk_widget_show_all(copy_btn);

    debug_print("[DEBUG] copy mail to clipboard icon: %p\n", copy_btn);

  }

}