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

📄 pop3smtp.c

📁 一个功能全面的电子邮件客户端
💻 C
📖 第 1 页 / 共 3 页
字号:
/* TradeClient <http://tradeclient.sourceforge.net> * $Id: pop3smtp.c,v 1.85 2001/03/21 04:40:55 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"#include <unistd.h>// MEMWATCH#ifdef MEMWATCH#include "memwatch.h"#endif// DMALLOC#ifdef DMALLOC#include "dmalloc.h"#endifPopAccount *popaccount_list=NULL;static char *pop_errors[]= {	NULL,	"Undefined account",	"Undefined host",	"Unknown host",	"Connection refused",	"Connection already open",	"Connection reset by peer",	"Unknown response",	"Unknown error",	NULL,	NULL, 	"Undefined login",	"Undefined password",	"Unknown user",	"Password incorrect",	"Unknown message",	"Relaying denied",	"Unknown sender domain",	"Unknown recipient domain",	"No recipient specified"};void popaccounts_dump_em_all (char *identifier) {#if DEBUG > 8	PopAccount *seek=popaccount_list;	printf ("****************************************************\n");	printf ("Identifier: %s\n", identifier);	while (seek) {		printf ("seek->name: %p '%s'\n", seek->name, seek->name);		printf ("seek->phost: %p '%s'\n", seek->phost, seek->phost);		printf ("seek->ppasswd: %p '%s'\n", seek->ppasswd, seek->ppasswd);		printf ("seek->puser: %p '%s'\n", seek->puser, seek->puser);		printf ("seek->suser: %p '%s'\n", seek->suser, seek->suser);		printf ("seek->folder: %p '%s'\n", seek->folder, seek->folder);		printf ("seek->real_name: %p '%s'\n", seek->real_name, seek->real_name);		printf ("seek->replyaddr: %p '%s'\n", seek->replyaddr, seek->replyaddr);		printf ("seek->organization: %p '%s'\n", seek->organization, seek->organization);		printf ("seek->signature: %p '%s'\n", seek->signature, seek->signature);		printf ("seek->attachdir: %p '%s'\n", seek->attachdir, seek->attachdir);		printf ("-------------------\n");		seek=seek->next;	}#endif}int new_popaccount (const char *name, const char *phost,                    const char *puser, const char *ppasswd,                    int pport, const char *shost, const char *suser,                    int sport, unsigned long flags, int timeout, char *folder,                    char *real_name, char *emailaddr, char *replyaddr,                    char *organization, char *signature, char *attachdir, int msgCount, void *extra) {	PopAccount *seek=popaccount_list, *newpopaccount;	if (popaccount_list==NULL) {		seek=(PopAccount *)calloc(1, sizeof(PopAccount));		popaccount_list=seek;		seek->next=NULL;		if (name!=NULL) {			seek->name=(char *)calloc(strlen(name)+1, sizeof(char));			memmove(seek->name, name, strlen(name));		} else seek->name=NULL;		/***** POP3 *****/		if (phost!=NULL) {			seek->phost=(char *)calloc(strlen(phost)+1, sizeof(char));			memmove(seek->phost, phost, strlen(phost));		} else seek->phost=NULL;		if (puser!=NULL) {			seek->puser=(char *)calloc(strlen(puser)+1, sizeof(char));			memmove(seek->puser, puser, strlen(puser));		} else seek->puser=NULL;		if (ppasswd!=NULL) {			seek->ppasswd=(char *)calloc(strlen(ppasswd)+1, sizeof(char));			memmove(seek->ppasswd, ppasswd, strlen(ppasswd));		} else seek->ppasswd=NULL;		if (pport>=0) {			seek->pport=pport;		} else seek->pport=110;		/***** SMTP *****/		if (shost!=NULL) {			seek->shost=(char *)calloc(strlen(shost)+1, sizeof(char));			memmove(seek->shost, shost, strlen(shost));		} else seek->shost=NULL;		if (suser!=NULL) {			seek->suser=(char *)calloc(strlen(suser)+1, sizeof(char));			memmove(seek->suser, suser, strlen(suser));		} else seek->suser=NULL;		if (sport>=0) {			seek->sport=sport;		} else seek->sport=25;		seek->smode='S';		/***** Optional *****/		if (folder!=NULL) {			seek->folder=(char *)g_malloc(strlen(folder)+1);			memmove(seek->folder, folder, strlen(folder));		} else seek->folder=NULL;		if (real_name!=NULL) {			seek->real_name=(char *)calloc(strlen(real_name)+1, sizeof(char));			memmove(seek->real_name, real_name, strlen(real_name));		} else seek->real_name=NULL;		if (emailaddr!=NULL) {			seek->emailaddr=(char *)calloc(strlen(emailaddr)+1, sizeof(char));			memmove(seek->emailaddr, emailaddr, strlen(emailaddr));		} else seek->emailaddr=NULL;		if (folder!=NULL) {			seek->folder=(char *)calloc(strlen(folder)+1, sizeof(char));			memmove(seek->folder, folder, strlen(folder));		} else seek->folder=NULL;		if (replyaddr!=NULL) {			seek->replyaddr=(char *)calloc(strlen(replyaddr)+1, sizeof(char));			memmove(seek->replyaddr, replyaddr, strlen(replyaddr));		} else seek->replyaddr=NULL;		if (organization!=NULL) {			seek->organization=(char *)calloc(strlen(organization)+1, sizeof(char));			memmove(seek->organization, organization, strlen(organization));		} else seek->organization=NULL;		if (signature!=NULL) {			seek->signature=(char *)calloc(strlen(signature)+1, sizeof(char));			memmove(seek->signature, signature, strlen(signature));		} else seek->signature=NULL;		if (attachdir!=NULL) {			seek->attachdir=(char *)calloc(strlen(attachdir)+1, sizeof(char));			memmove(seek->attachdir, attachdir, strlen(attachdir));		} else seek->attachdir=NULL;		if (extra) seek->extra=extra;		/* glob */		seek->flags=flags;		seek->timeout=timeout;		seek->pid=-1;		seek->spid=-1;		seek->id=0;		seek->busy=0;		seek->popcmsg = msgCount ;		seek->poptmsg = msgCount ;#if DEBUG > 4		if ((name)&&(msgCount))			printf( "Account '%s', currently has %d messages on server.\n", name, msgCount ) ;#endif		return seek->id;	} else {		newpopaccount=(PopAccount *)calloc(1, sizeof(PopAccount));		while (seek->next!=NULL) { seek=seek->next; }		seek->next=newpopaccount;		newpopaccount->next=NULL;		if (name!=NULL) {			newpopaccount->name=(char *)calloc(strlen(name)+1, sizeof(char));			memmove(newpopaccount->name, name, strlen(name));		} else newpopaccount->name=NULL;		/***** POP3 *****/		if (phost!=NULL) {			newpopaccount->phost=(char *)calloc(strlen(phost)+1, sizeof(char));			memmove(newpopaccount->phost, phost, strlen(phost));		} else newpopaccount->phost=NULL;		if (puser!=NULL) {			newpopaccount->puser=(char *)calloc(strlen(puser)+1, sizeof(char));			memmove(newpopaccount->puser, puser, strlen(puser));		} else newpopaccount->puser=NULL;		if (ppasswd!=NULL) {			newpopaccount->ppasswd=(char *)calloc(strlen(ppasswd)+1, sizeof(char));			memmove(newpopaccount->ppasswd, ppasswd, strlen(ppasswd));		} else newpopaccount->ppasswd=NULL;		if (pport>=0) {			newpopaccount->pport=pport;		} else newpopaccount->pport=110;		/***** SMTP *****/		if (shost!=NULL) {			newpopaccount->shost=(char *)calloc(strlen(shost)+1, sizeof(char));			memmove(newpopaccount->shost, shost, strlen(shost));		} else newpopaccount->shost=NULL;		if (suser!=NULL) {			newpopaccount->suser=(char *)calloc(strlen(suser)+1, sizeof(char));			memmove(newpopaccount->suser, suser, strlen(suser));		} else newpopaccount->suser=NULL;		if (sport>=0) {			newpopaccount->sport=sport;		} else newpopaccount->sport=25;		newpopaccount->smode='S';		/***** Optional *****/		if (folder!=NULL) {			newpopaccount->folder=(char *)g_malloc0(strlen(folder)+1);			memmove(newpopaccount->folder, folder, strlen(folder));		} else newpopaccount->folder=NULL;		if (real_name!=NULL) {			newpopaccount->real_name=(char *)calloc(strlen(real_name)+1, sizeof(char));			memmove(newpopaccount->real_name, real_name, strlen(real_name));		} else newpopaccount->real_name=NULL;		if (emailaddr!=NULL) {			newpopaccount->emailaddr=(char *)calloc(strlen(emailaddr)+1, sizeof(char));			memmove(newpopaccount->emailaddr, emailaddr, strlen(emailaddr));		} else newpopaccount->emailaddr=NULL;		if (folder!=NULL) {			newpopaccount->folder=(char *)calloc(strlen(folder)+1, sizeof(char));			memmove(newpopaccount->folder, folder, strlen(folder));		} else newpopaccount->folder=NULL;		if (replyaddr!=NULL) {			newpopaccount->replyaddr=(char *)calloc(strlen(replyaddr)+1, sizeof(char));			memmove(newpopaccount->replyaddr, replyaddr, strlen(replyaddr));		} else newpopaccount->replyaddr=NULL;		if (organization!=NULL) {			newpopaccount->organization=(char *)calloc(strlen(organization)+1, sizeof(char));			memmove(newpopaccount->organization, organization, strlen(organization));					} else newpopaccount->organization=NULL;		if (signature!=NULL) {			newpopaccount->signature=(char *)calloc(strlen(signature)+1, sizeof(char));			memmove(newpopaccount->signature, signature, strlen(signature));		} else newpopaccount->signature=NULL;		if (extra) newpopaccount->extra=extra;		if (attachdir!=NULL) {			newpopaccount->attachdir=(char *)calloc(strlen(attachdir)+1, sizeof(char));			memmove(newpopaccount->attachdir, attachdir, strlen(attachdir));		} else newpopaccount->attachdir=NULL;		/* glob */		newpopaccount->flags=flags;		newpopaccount->timeout=timeout;		newpopaccount->pid=-1 ;		newpopaccount->spid=-1 ;		newpopaccount->busy=0 ;		newpopaccount->id=seek->id+1;		newpopaccount->popcmsg = msgCount ;		newpopaccount->poptmsg = msgCount ;#if DEBUG > 4		printf( "Account '%s', currently has %d messages on server.\n", name, msgCount ) ;#endif		return newpopaccount->id;	}	return -1;}PopAccount *seek_popaccount (int id) {	PopAccount *seek ;	PopAccount *ret ;	seek = popaccount_list;	ret = (PopAccount *)NULL ;	while (seek) {		if (seek->id==id) ret = seek ;		seek=(PopAccount *)seek->next;	}	return ret ;}PopAccount *popaccount_is_my_address (char *address) {	PopAccount *seek;	for (seek=popaccount_list;seek;seek=seek->next) {		if (seek->emailaddr) {			if (strcasecmp (address, seek->emailaddr)==0) {				return seek;			}		}		if (seek->replyaddr) {			if (strcasecmp (address, seek->replyaddr)==0) {				return seek;			}		}	}	return NULL;}PopAccount *first_popaccount (void) {	return popaccount_list;}int seek_popaccount_by_flag (unsigned long flag) {	PopAccount *seek=popaccount_list;	if (seek==NULL)		return NDEFACCOUNT;	while (seek) {		if ((seek->flags&flag)==flag) return seek->id;		seek=(PopAccount *)seek->next;	}	return NDEFACCOUNT;}int seek_popaccount_by_name (char *name) {	PopAccount *seek=popaccount_list;	while (seek) {		if (strcasecmp (seek->name, name)==0) return seek->id;		seek=seek->next;	}	return NDEFACCOUNT;}int destroy_popaccount (int id) {  int ret ;  int cnt ;  PopAccount *ntmp, *prev ;  PopAccount *seek=seek_popaccount(id);  if( seek ) {    if( popaccount_list == seek ) popaccount_list = seek -> next ;    else {      prev = seek_popaccount( id - 1 ) ;      prev -> next = seek -> next ;    }    if (seek->name) free (seek->name);    if (seek->phost) free (seek->phost);    if (seek->ppasswd) free (seek->ppasswd);    if (seek->puser) free (seek->puser);    if (seek->shost) free (seek->shost);    if (seek->suser) free (seek->suser);    if (seek->folder) free (seek->folder);    if (seek->real_name) free (seek->real_name);    if (seek->emailaddr) free (seek->emailaddr);    if (seek->replyaddr) free (seek->replyaddr);    if (seek->organization) free (seek->organization);    if (seek->signature) free (seek->signature);    if (seek->attachdir) free (seek->attachdir);    if (seek->extra) free (seek->extra);    free (seek);    /*     * Now, we need to renumber every body so that we to renumber everyone     * so that the counts stay ordered.  I think that some logic may not     * like finding non-linear account numbers.     */    ntmp = first_popaccount() ;    for( cnt = 0, ntmp = first_popaccount() ; ntmp ; cnt++ ) {      ntmp -> id = cnt ;      ntmp = ntmp -> next ;    }    ret = 0 ;  } else {    ret = NDEFACCOUNT ;  }  return ret ;}int edit_popaccount (int id, const char *name, const char *phost,                    const char *puser, const char *ppasswd,                    int pport, const char *shost, const char *suser,                    int sport, unsigned long flags, int timeout, char *folder,                    char *real_name, char *emailaddr, char *replyaddr,                    char *organization, char *signature, char *attachdir, void *extra) {	PopAccount *seek=seek_popaccount (id);	if (seek==NULL)		return NDEFACCOUNT;	if (name!=NULL) {		if (seek->name) free (seek->name);		seek->name=strdup (name);	}	/***** POP3 *****/	if (phost!=NULL) {		if (seek->phost) free (seek->phost);		seek->phost=strdup (phost);	}	if (puser!=NULL) {		if (seek->puser) free (seek->puser);		seek->puser=strdup (puser);	}	if (ppasswd!=NULL) {		if (seek->ppasswd) free (seek->ppasswd);		seek->ppasswd=strdup (ppasswd);	}	if (pport>0) {		seek->pport=pport;	}	/***** SMTP *****/	if (shost!=NULL) {		if (seek->shost) free (seek->shost);		seek->shost=strdup (shost);	}	if (suser!=NULL) {		if (seek->suser) free (seek->suser);		seek->suser=strdup (suser);	}	if (sport>0) {		seek->sport=sport;	}	/***** Globs *****/	if (flags>=0) {		seek->flags=flags;	}	seek->timeout=timeout;	/***** Optional *****/	if (folder!=NULL) {		if (seek->folder) free (seek->folder);		seek->folder=strdup (folder);

⌨️ 快捷键说明

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