⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main-window-callbacks.c

📁 一个功能全面的电子邮件客户端
💻 C
📖 第 1 页 / 共 5 页
字号:
/* TradeClient <http://tradeclient.sourceforge.net> * $Id: main-window-callbacks.c,v 1.112 2001/03/20 22:19:33 ttabner Exp $ * * Copyright (C) 1999-2000 Bynari Inc. * Copyright (C) 2001 Project TradeClient * * LGPL * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Library General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library * General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */#include "puma.h"#define MAX_NEW_MSG_WINDOWS   10GList *msel=NULL;int parse_from_line (char *fromline, char **email, char **first, char **last) {	char *tmp1, *tmp2;	char *tmpcs;	if (strstr (fromline, "<")) {		tmp1=cut_string (fromline, '<', 2, 1);		*email=cut_string (tmp1, '>', 1, 1);		free (tmp1);		if (strstr (fromline, "\"")) {			tmp1=cut_string (fromline, '"', 1, 2);			tmp2=cut_string (tmp1, '"', 2, 1);			free (tmp1);		} else {			tmp2=cut_string (fromline, '<', 1, 1);		}		if (strstr (tmp2, " ")) {			*first=cut_string (tmp2, ' ', 1, 1);			tmpcs=cut_string (tmp2, ' ', 2, 1);			*last=cut_string(tmpcs,' ',1,1);			free (tmp2);			free (tmpcs);			return TRUE;		} else {			*first=tmp2;			*last=NULL;			return TRUE;		}	} else {		*email=rm_crlf (fromline);		*first=NULL;		*last=NULL;		return TRUE;	}	return FALSE;}GtkWidget *make_new_message_window (GtkWidget *widget, gpointer data) {	int i=0, x, y;	if (tm_globs->num_accounts>0) {		do { 			if (tm_globs->new_messages[i]==NULL)	break;			i++; 		} while (i<MAX_NEW_MSG_WINDOWS);		if (i>=MAX_NEW_MSG_WINDOWS) { 			insert_warning (_("You cannot open any more new messages.  Close some first\n")); return NULL; 		}		tm_globs->new_messages[i]=create_new_message_window ();		y=x=i*10+20;#if 0		gtk_widget_set_uposition (tm_globs->new_messages[i], x, y);#endif		gtk_widget_show (tm_globs->new_messages[i]);		return (tm_globs->new_messages[i]);	} else {		insert_warning (_("You do not have any accounts defined\n"));	}	return NULL;}void get_messages (GtkWidget *widget, gpointer data) {	gtk_widget_set_sensitive (lookup_widget (tm_globs->main_window, "get_message"), FALSE);	gtk_widget_set_sensitive (lookup_widget (tm_globs->status, "stopthat"), TRUE);	gtk_widget_set_sensitive (lookup_widget (tm_globs->status, "skip"), TRUE);	if (!(tm_globs->flags & HIDE_STATUS_WINDOW)) {			show_status (NULL, NULL);	}	/* Now, go get those messages by creating children to do the work */	//TREYgtk_timeout_remove( tm_globs -> getMsgTimeout ) ;	nf_imap_check_mail (NULL);    fork_receive_messages (NULL);	tm_globs->getMsgTimeout = gtk_timeout_add( 125, (GtkFunction)get_message_timeout, NULL ) ;		return ;}void make_preferences (GtkWidget *widget, gpointer data) {	prefs_show (1);}void protect_unprotect_actions (int type) {	gtk_widget_set_sensitive (lookup_widget (tm_globs->main_window, "reply_to"), type);	gtk_widget_set_sensitive (lookup_widget (tm_globs->main_window, "reply_to_all"), type);	gtk_widget_set_sensitive (lookup_widget (tm_globs->main_window, "forward"), type);	gtk_widget_set_sensitive (lookup_widget (tm_globs->main_window, "delete_button"), type);	gtk_widget_set_sensitive (lookup_widget (tm_globs->main_window, "del_menu"), type);	gtk_widget_set_sensitive (lookup_widget (tm_globs->main_window, "print"), type);	gtk_widget_set_sensitive (lookup_widget (tm_globs->main_window, "save_message_as"), TRUE);}void populate_attachment_clist (Attachment *att) {	GtkCList *clist=GTK_CLIST (lookup_widget (tm_globs->main_window, "mime_clist"));	Attachment *old_att;	char *cl_data[3];	int row;	gtk_clist_freeze (clist);	old_att=gtk_clist_get_row_data (clist, 0);	if (old_att) attachments_destroy (old_att);	gtk_clist_clear (clist);	if (att) free (att->mtype);	old_att=att;	if (att) att=att->next;	if (old_att) free (old_att);	while (att) {		cl_data[0]=att->mtype;		cl_data[1]=att->fname;		cl_data[2]=(char *)calloc (1, 64);		sprintf (cl_data[2], "%d", (int)att->length);		row=gtk_clist_append (clist, cl_data);		free (cl_data[2]);		gtk_clist_set_row_data (clist, row, (gpointer)att);		att=att->next;	}	gtk_clist_thaw (clist);}void clicked_on_message (GtkWidget *widget, GdkEventButton *event, gpointer data) {	int row, column;	GtkWidget *message_body=lookup_widget (tm_globs->main_window, "message_body");	GtkWidget *folder_ctree=lookup_widget (tm_globs->main_window, "folder_tree");	Message *message;	char *msg, *tmpmsg, *tmp2, *head;	Attachment *att=NULL;	Header_Info *hinfo=NULL;	int hsize=0;	Folder *folder;	Folder *vfolder;	msg_info *info;	char *number=(char *)calloc (5, sizeof(char));	gtk_clist_get_selection_info (GTK_CLIST (widget), event->x, event->y, &row, &column);#if DEBUG > 7	printf( "clicked on message got row %d.\n", row ) ;#endif	info=gtk_clist_get_row_data (GTK_CLIST (widget), row);	if (!info) {		free (number);		return;	}	tm_globs->msg_selected=info->msg;	if ((event->button==1) || (event->button==3)) {		if (!info) {			free (number);			return;		}	}	folder_shade_row( GTK_CLIST(widget), row, info -> row, 0, info->msg->sensitivity ) ;	message=info->msg;	folder=info->fl;	if (message->folder) {		vfolder=folder_seek (folder_seek_by_name (message->folder));	} else {		vfolder=folder;	}	if ((event->type==5) && (event->button==1)) {		gtk_widget_show (message_window_new (info));		free (number);		return;	}	if (message) {		switch (event->button) {			case 1 :				tmpmsg=message_load (folder, message);				if ((message->flags & MESSAGE_UNREAD) && tmpmsg!=NULL) {					hsize=message_hsize (tmpmsg);					head=(char *)calloc (hsize+2, sizeof(char));					if (hsize > 0) {						memmove (head, tmpmsg, hsize);						hinfo=parse_header (head);						free (head);						if (hinfo->disposition_notify) {							return_receipt (hinfo->disposition_notify, hinfo->subject, strdup (tmpmsg));						}					}				}				att=(Attachment *)calloc(1, sizeof(Attachment));				att->mtype=strdup ("dummyatt");				msg=mime_process (tmpmsg, att, 1);				tmp2=rm_cr (msg);				free (msg);				msg=tmp2;				populate_attachment_clist (att);				gtk_text_freeze (GTK_TEXT (message_body));				gtk_text_set_point (GTK_TEXT(message_body), 0);				gtk_text_forward_delete (GTK_TEXT(message_body), gtk_text_get_length (GTK_TEXT(message_body)));				gtk_text_insert (GTK_TEXT(message_body), NULL, NULL, NULL, msg, -1);				gtk_text_set_point (GTK_TEXT (message_body), 0);				gtk_text_thaw (GTK_TEXT (message_body));				gtk_widget_grab_focus (message_body);				if (message->flags & MESSAGE_UNREAD) {					message->flags &=~ MESSAGE_UNREAD;					vfolder->unread--;					snprintf (number, 5, "%d", vfolder->unread);					gtk_ctree_node_set_text (GTK_CTREE (folder_ctree), vfolder->tree_item, 1, number);					snprintf (number, 5, "%d", vfolder->total);					gtk_ctree_node_set_text (GTK_CTREE (folder_ctree), vfolder->tree_item, 2, number);				}				protect_unprotect_actions (TRUE);				free (msg);				free (tmpmsg);				if (hinfo) destroy_hinfo (hinfo);				break;			case 2 :				break;			case 3 :				gtk_clist_unselect_all (GTK_CLIST (widget));				gtk_clist_select_row (GTK_CLIST (widget), row, 0);				create_popup_window (info->msg);				break;			default:		}	}	free (number);}GList *message_get_selection () {	return msel ;}void message_selection_null () {#if DEBUG > 5  printf( "Destroying list of %d nodes.\n", g_list_length( msel ) ) ;#endif  g_list_free( msel ) ;  msel = NULL ;}void clicked_on_message_handler (GtkWidget *widget, gint row, gint column, GdkEventButton *event, gpointer data) {	msg_info *info=gtk_clist_get_row_data (GTK_CLIST (widget), row);	tm_globs->msg_selected=info->msg;	tm_globs->msg_row=row;	protect_unprotect_actions (TRUE);#if DEBUG > 5	printf( "clicked on message\n" ) ;#endif	msel=g_list_prepend (msel, info);#if DEBUG > 5	printf( "message list has %d nodes.\n", g_list_length( msel ) ) ;#endif}int unclicked_ignore=FALSE;void unclicked_on_message (GtkWidget *widget, gint row, gint column, GdkEventButton *event, gpointer data) {	msg_info *info=gtk_clist_get_row_data (GTK_CLIST (widget), row);	if (unclicked_ignore) {		unclicked_ignore=FALSE;		return;	}#if DEBUG > 5	printf( "unclicked on a message.\n" ) ;#endif	msel=g_list_remove (msel, info);#if DEBUG > 5	printf( "message list has %d nodes.\n", g_list_length( msel ) ) ;#endif	if (!msel) {		protect_unprotect_actions (FALSE);		tm_globs->msg_selected=NULL;	}	}void message_clist_destroy_row (gpointer data) {	if (data) free (data);}void folder_display (GtkCList *clist, Folder *fl) {	char *cl_data[6];	msg_info *info;	int row, count=0;	int folderRowCount ;	Folder *fseek;	Message *mseek;	char date[255];	g_return_if_fail (clist != NULL);	if (!fl)		return;	//g_return_if_fail (fl != NULL);	#if DEBUG > 5	printf( "folder_display() has been called.\n" ) ;#endif	gtk_clist_freeze (clist);	gtk_clist_clear (clist);	tm_globs->visable=fl;	for (fseek=folder_first ();fseek;fseek=fseek->next) {		tm_globs->msg_selected=NULL;		protect_unprotect_actions (FALSE);		count=0;		folderRowCount = 0 ;		for (mseek=fseek->msglst;mseek;mseek=mseek->next) {			if (strcasecmp (mseek->folder, fl->name)==0) {#if 0				char *status;				if ((mseek->flags & MESSAGE_REPLY)&&(mseek->flags & MESSAGE_FORWARD))					status=strdup("RF");				else if (mseek->flags & MESSAGE_REPLY)					status=strdup("R");				else if (mseek->flags & MESSAGE_FORWARD)					status=strdup("F");				else					status=NULL;				cl_data[0]=status;#else				cl_data[0]=NULL;#endif				cl_data[1]=mseek->priority;				cl_data[2]=mseek->subject;				cl_data[3]=mseek->from;				cl_data[4]=mseek->date;				strftime (date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", localtime(&mseek->time));				cl_data[5]=strdup(date);#if 0				cl_data[5]=ctime (&mseek->time);#endif				info=(msg_info *)calloc (1, sizeof(msg_info));				info->msg=mseek;				info->fl=fseek; 				row=gtk_clist_prepend (GTK_CLIST (clist), cl_data);				free( cl_data[5] ) ;				/*				 * This is ULTRA important, otherwise, when we delete a row is will not				 * have the correct row number as required for proper highlighting since				 * we are prepending.  Also, remember, when we are prepending, the row				 * number, as returned from the prepend operation, will ALWAYS be zero!				 */				info -> row = folderRowCount ;				/* Now, call a function to do do all of the actual row work! */				folder_shade_row (GTK_CLIST(clist), row, folderRowCount, info->msg->flags & MESSAGE_UNREAD, info->msg->sensitivity) ;				/* Now, update the clist with the current info */				gtk_clist_set_row_data_full (GTK_CLIST (clist), row, 							     (gpointer)info, (GtkDestroyNotify)message_clist_destroy_row);#if DEBUG > 6				if( folderRowCount != row ) printf( "current row and folder row count differ in in count" \								    "with row = %d and folder row = %d.\n", row, folderRowCount ) ;#endif				folderRowCount++ ;			}			count++;		}	}	message_selection_null() ;	gtk_clist_thaw (GTK_CLIST (clist));}voidfolder_shade_row (GtkCList *clist, int rowNum, int msgCnt, int unread, char *sens){     int x;	gtk_clist_freeze (clist);       if (GTK_IS_CLIST (clist))     {	  if ((sens) && (strlen(sens) > 0) && (strcmp (sens, "Public-Document") != 0))	  {	       if (unread)	       {		    if (strcasecmp(sens, "Internal-Document")==0) {			 for (x=0; x < 6; x++) gtk_clist_set_cell_style (GTK_CLIST (clist), rowNum, x, tm_globs->sens_u1);		    } else if (strcasecmp(sens, "Personal")==0) {			 for (x=0; x < 6; x++) gtk_clist_set_cell_style (GTK_CLIST (clist), rowNum, x, tm_globs->sens_u2);		    } else if (strcasecmp(sens, "Private")==0) {			 for (x=0; x < 6; x++) gtk_clist_set_cell_style (GTK_CLIST (clist), rowNum, x, tm_globs->sens_u3);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -