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

📄 new-message-callbacks.c

📁 一个功能全面的电子邮件客户端
💻 C
📖 第 1 页 / 共 3 页
字号:
/* TradeClient <http://tradeclient.sourceforge.net> * $Id: new-message-callbacks.c,v 1.62 2001/03/21 00:45:22 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"static char *fetch_string( GtkWidget *parent, const char *string ) ;static char *get_priority_string (GtkWidget *parent) ;static char *get_keyword_string( GtkWidget *parent ) ;static char *get_sensitivity_string( GtkWidget *parent ) ;static char *get_expire_string( GtkWidget *parent ) ;static char *get_replyby_string( GtkWidget *parent ) ;static char *get_messageflag_string( GtkWidget *parent ) ;/* *************************************This is the function you will need to manipulate.  All of the data you needfor generating the header without attachments is already there.  I'll show you how to grab the information for the attachments************************************* */static char *fetch_string( GtkWidget *parent, const char *string ){  char *tmp ;  tmp = gtk_editable_get_chars (GTK_EDITABLE (lookup_widget(parent, string)), 0, -1) ;  if( !tmp || (tmp && !strlen( tmp )) ) return NULL ;  else return tmp ;}static char *get_priority_string (GtkWidget *parent){  return fetch_string( parent, "priority_to_use" ) ;}static char *get_sensitivity_string( GtkWidget *parent ){  return fetch_string( parent, "sensitivity_to_use" ) ;}static char *get_keyword_string( GtkWidget *parent ){  return fetch_string( parent, "entry9" ) ;}static char *get_expire_string( GtkWidget *parent ){  return fetch_string( parent, "msg_exp_entry" ) ;}static char *get_replyby_string( GtkWidget *parent ){  return fetch_string( parent, "replyby_entry" ) ;}static char *get_messageflag_string( GtkWidget *parent ){#if 0  return fetch_string( parent, "NA" ) ;#else  return NULL ;#endif}char *nemail_fix(char *nickname) {        Abook_entry *entry=abook_entry_seek_by_nickname(NULL,nickname);	if (entry) {        	if (entry->def_email) return (entry->def_email);	}        return nickname;}int is_email (char *addr) {	int found=0;	int i;	if( addr == NULL ) return FALSE ;	for (i=0;i< strlen (addr);i++) {		if (addr[i]=='@')			found++;	}	if (found==1)		return TRUE;	return FALSE;}int is_emailv( char *addr ){	int errors = 0 ;	int i ;	if( addr == NULL ) return FALSE ;	for( i = 0 ; i < strlen( addr ) ; i++ )	{		if( !isprint( addr[i] ) )			errors++ ;	}	if( errors )		return FALSE;	return TRUE;}int validate_email (char *addr) {	char *tmp1=NULL, *tmp2=NULL, *tmp3=NULL;	int len, i;	if (tmp2==NULL) goto failed;	len=tmp2-tmp1;	tmp3=(char *)calloc (len+1, sizeof(char));	memmove (tmp3, tmp1+1, len-1);	len=strlen(tmp3);	if (strstr (tmp3, "@")==NULL) goto failed;	for (i=0; i<len; i++) {		if ( (!isdigit(tmp3[i])) ||		     (!islower(tmp3[i])) ||		     (!isupper(tmp3[i])) ||		     (tmp3[i]!='@') ||		     (tmp3[i]!='.') ||		     (tmp3[i]!='_') ||		     (tmp3[i]!='-') ||		     (tmp3[i]!='+') ) goto failed;	}	return TRUE;failed:	if (tmp3) {		insert_warning ("'%s' is not a valid email address!\n", tmp3);		free (tmp3);	} else if (addr) {		insert_warning ("'%s' is not a valid email address!\n", addr);	} else {		insert_warning ("A NULL string was sent to validate_email!\n");	}	return FALSE;	}GList *new_message_get_recipients (GtkTree *tree) {	Recipient *recp;	GList *seek;	GList *ret=NULL;	g_return_val_if_fail (tree != NULL, NULL);		for (seek=tree->children;seek;seek=seek->next) {		GtkWidget *item=seek->data;		GtkWidget *hbox=GTK_BIN (item)->child;		GtkBoxChild *typew=GTK_BOX (hbox)->children->next->data;		GtkBoxChild *add=GTK_BOX (hbox)->children->next->next->data;		char *type=gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (typew->widget)->entry));		char *address=gtk_entry_get_text (GTK_ENTRY (add->widget));		if (strlen (address)>0) {			recp=(Recipient *)calloc (1, sizeof (Recipient));			if (is_email (address)) {				recp->email=strdup (address);			} else {				Abook_entry *entry=abook_entry_seek_by_name (NULL, address);				if (entry) {					if (entry->def_email)	recp->email=strdup (entry->def_email);				} else {					recp->email=strdup (address);				}			}			if (strcasecmp (type, "To:")==0)				recp->type=RECIPIENT_TO;			if (strcasecmp (type, "Cc:")==0) 				recp->type=RECIPIENT_CC;			if (strcasecmp (type, "Bcc:")==0)				recp->type=RECIPIENT_BCC;			ret=g_list_append (ret, recp);		}	}	return ret;}void new_message_destroy_reciplist (GList *recip) {	GList *seek;	Recipient *recp;	for (seek=recip;seek;seek=seek->next) {		recp=seek->data;		if (recp->email) free (recp->email);		free (recp);	}	g_list_free (recip);}void new_message_unprotect (GtkWidget *widget) {	gtk_widget_set_sensitive (lw (widget, "new_message_window"), TRUE);	gtk_widget_set_sensitive (lookup_widget (tm_globs->main_window, "get_message"), TRUE);	gtk_widget_set_sensitive (lookup_widget (tm_globs->status, "stopthat"), FALSE);	gtk_widget_set_sensitive (lookup_widget (tm_globs->status, "skip"), FALSE);}/* * Used for text saves, printing, and folding filing of locally generated messages. */char *new_message_generate_full (GtkWidget *parent, char **to, char **cc, char **bcc) {        char *to_line=NULL, *cc_line=NULL, *bcc_line=NULL;        char *subject_line=gtk_entry_get_text (GTK_ENTRY(lookup_widget (parent, "subject_entry")));        char *body=gtk_editable_get_chars (GTK_EDITABLE(lookup_widget (parent, "body_textbox")), 0, -1);        GtkCList *clist=GTK_CLIST (lookup_widget (parent, "attachment_clist"));        GtkTree *tree=GTK_TREE (lw (parent, "recip_tree"));        int popid=seek_popaccount_by_name (gtk_entry_get_text (GTK_ENTRY (lookup_widget (parent, "account_to_use"))));        PopAccount *pop=seek_popaccount (popid);        char *timestamp=generate_timestamp ();        char *full_message=NULL, *tmp_full_message=NULL, *sender=NULL, *org=NULL, *replyto=NULL;        char *tmp, *tmp2;        Llist *alist=NULL;        AFS *afs;        int i;        guint tol=1, ccl=1, bccl=1;        GList *s;	tmp = word_wrap_body( body, tm_globs->wwrap ) ;	if( !tmp ) {	  tmp = strdup( body ) ;	}	g_free( body ) ;	body = tmp ;	tmp = NULL ;        if (tm_globs->pid!=-1) {		insert_error ("Receive in progress.  Wait until Receive is finished\n");                return                NULL;        }        /* should never be null but just to be sure */        if (pop->emailaddr)                sender=strdup (pop->emailaddr);        else                sender=strdup ("Defunct");        if (pop->organization)                if (pop->organization[0]!='\0')                        org=strdup(pop->organization);        if (tm_globs->organization && org==NULL)                if (tm_globs->organization[0]!='\0')                        org=strdup(tm_globs->organization);                else                        org=(char *)calloc(2, sizeof(char));        else if (!org)                org=(char *)calloc(2, sizeof(char));        if (pop->replyaddr)                if (pop->replyaddr[0]!='\0')                        replyto=strdup(pop->replyaddr);        if (tm_globs->replyto && replyto==NULL)                if (tm_globs->replyto[0]!='\0')                        replyto=strdup(tm_globs->replyto);                else                        replyto=(char *)calloc(2, sizeof(char));        else if (!replyto)                replyto=(char *)calloc(2, sizeof(char));//      if (strlen (body) > 0) {                if (pop->flags & USE_THIS_SIG) {                        if (pop->signature) {                                tmp=(char *)calloc (strlen (body)+strlen (pop->signature)+4, sizeof (char));                                sprintf (tmp, "%s\n\n%s", body, pop->signature);                                free (body);                                body=tmp;                        }                } else {                        if (pop->flags & USE_THIS_UNIX_SIG) {                                tmp=(char *)calloc (1024, sizeof (char));                                snprintf (tmp, 1024, "$(HOME)/.sig");                                env_srch_rep (tmp);                                if (!access (tmp, R_OK)) {                                        struct stat buf;                                        int fd;                                        stat (tmp, &buf);                                        fd=open (tmp, O_RDONLY);                                        free (tmp);                                        tmp2=(char *)calloc (buf.st_size+1, sizeof (char));                                        read (fd, tmp2, buf.st_size+1);                                        close (fd);                                        tmp=(char *)calloc (strlen (body)+strlen (tmp2)+4, sizeof (char));                                        sprintf (tmp, "%s\n\n%s", body, tmp2);                                        free (tmp2);                                        free (body);                                        body=tmp;                                } else {                                        perror ("Unable to stat ~/.sig");                                        free (tmp);                                }                        } else {                                if (tm_globs->flags & USE_SIGNATURE) {                                        tmp=(char *)calloc (strlen (body)+strlen (tm_globs->signature)+4, sizeof (char));                                        sprintf (tmp, "%s\n\n%s", body, tm_globs->signature);                                        free (body);                                        body=tmp;                                }                        }                }                afs=(AFS *)calloc (1, sizeof (AFS));                afs->data=strdup (body);                afs->type=strdup ("text/plain");                alist=llist_append (alist, afs);//      }        for (i=0;i<clist->rows;i++) {                afs=gtk_clist_get_row_data (clist, i);#if DEBUG > 7                printf ("1afs: <%p>\nafs->filename: <%p> '%s'\n", afs, afs->filename, afs->filename);#endif                alist=llist_append (alist, afs);        }        /* generate the to, cc, and bcc lines */        for (s=tree->children;s;s=s->next) {                GtkWidget *item=s->data;                GtkWidget *hbox=GTK_BIN (item)->child;                GtkBoxChild *typew=GTK_BOX (hbox)->children->next->data;                GtkBoxChild *add=GTK_BOX (hbox)->children->next->next->data;                char *type=gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (typew->widget)->entry));                char *address=gtk_entry_get_text (GTK_ENTRY (add->widget));                if (strcasecmp (type, "To:")==0) {                        tol+=strlen (address)+3;                }                if (strcasecmp (type, "Cc:")==0) {                        ccl+=strlen (address)+3;                }                if (strcasecmp (type, "Bcc:")==0) {                        bccl+=strlen (address)+3;                }        }        if (tol>0) {                if (tol==1) {                        insert_message ("You must supply at least one To: recipient\n");                        return NULL;                }                to_line=(char *)calloc (tol, sizeof (char));        } else {                insert_message ("You must supply at least one To: recipient\n");                return NULL;        }        if (ccl>0) {                cc_line=(char *)calloc (ccl, sizeof (char));        }        if (bccl>0) {

⌨️ 快捷键说明

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