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

📄 pop3smtp.c

📁 一个功能全面的电子邮件客户端
💻 C
📖 第 1 页 / 共 3 页
字号:
	}	if (real_name!=NULL) {		if (seek->real_name) free (seek->real_name);		seek->real_name=strdup (real_name);	}	if (emailaddr!=NULL) {		if (seek->emailaddr) free (seek->emailaddr);		seek->emailaddr=strdup (emailaddr);	}	if (replyaddr!=NULL) {		if (seek->replyaddr) free (seek->replyaddr);		seek->replyaddr=strdup (replyaddr);	}	if (organization!=NULL) {		if (seek->organization) free (seek->organization);		seek->organization=strdup (organization);	}	if (signature!=NULL) {		if (seek->signature) free (seek->signature);		seek->signature=strdup (signature);	}	if (attachdir!=NULL) {		if (seek->attachdir) free (seek->attachdir);		seek->attachdir=strdup (attachdir);	}	if (extra) {		free (extra);		seek->extra=extra;	}	return 0;}int is_popaccount_password_set (int id) {	PopAccount *curpop=seek_popaccount(id);	if (curpop==NULL)		return NDEFACCOUNT;	if (curpop->ppasswd==NULL)		return FALSE;	return TRUE;}int destroy_popaccount_password (int id) {	PopAccount *curpop=seek_popaccount(id);	if (curpop==NULL)		return NDEFACCOUNT;	if (curpop->ppasswd!=NULL) {		memset (curpop->ppasswd, 0, strlen(curpop->ppasswd));		free(curpop->ppasswd);		curpop->ppasswd=NULL;	}	return 0;}unsigned long get_popaccount_flags (int id) {	PopAccount *curpop=seek_popaccount(id);	if (curpop==NULL)		return NDEFACCOUNT;	return curpop->flags;}int new_smtpconnect(int id) {	return 0;}int new_smtpehlo (int id, char *domain) {	return 0;}	int splitit(char *to,Nto *nto[256]) {        char *tmp = NULL;	int i,j;	j=0;		for(i=0;i<strlen(to);i++) {		if(to[i]!=',') {		  tmp[j]=to[i];		  j++;		} else {		  //we should check if it has a personal name		  fprintf(stderr,"TO match found\n");		  j=0;		}      }	return 0;}/* * This function is influenced by PINE's function of a like name. */char *generate_msg_id( void ) {  char r ;  int val ;  time_t t ;  char *tmp ;  char *ret ;  char *host ;  char *os_info ;  struct tm *t_tm ;  t = time( NULL ) ;  t_tm = localtime( &t ) ;  ret = (char *)malloc( 2048*sizeof(char) ) ;  if( t_tm -> tm_sec != 0 ) {    srand( t_tm -> tm_sec + t ) ;    val = rand() + t_tm -> tm_sec ;    r = ((char)rand()%64)+ 32 ;  } else {    r = ((char)rand()%64)+ 32 ;    val = rand() + t_tm -> tm_sec + t_tm -> tm_min ;  }  /* Get the os information and then replace any spaces with '-''s */  tmp = os_info = generate_os_info() ;  while( *tmp ) {    if( *tmp == 0x20 ) *tmp = '-' ;    tmp++ ;  }  /* Make sure we always have a hostname value defined! */  host = getenv( "HOSTNAME" ) ;  if( !host ) host = "localhost" ;  sprintf( ret, "<TradeClient.%.20s.%.20s.%02d%02d%02d%02d%02d%02d%X.%d@%.50s>",	   VERSION, os_info, (t_tm -> tm_year) % 100, t_tm -> tm_mon + 1,	   t_tm -> tm_mday, t_tm -> tm_hour, t_tm -> tm_min, t_tm -> tm_sec, 	   r, getpid(), host ) ;  #if DEBUG > 8  printf( "\nos info = '%s'\n", os_info ) ;  printf( "Generated message id = '%s'\n\n", ret ) ;#endif  return ret ;}int new_sendmessage (MailMessage *message) {  PopAccount *curpop=seek_popaccount(message->popid);  SENDSTREAM *stream=NULL;  char from[1024];  char *from2 = NULL;  ENVELOPE *msg = mail_newenvelope ();  BODY *body = mail_newbody ();  PART *part = mail_newbody_part() ;  char **hostlist ;  int smtpport,i;  char *type,*subtype;  char *curhost = NULL ;  char *reply ;  int hdrCntr ;    #if DEBUG > 6  fprintf(stderr,"sendmessage INIT\n");#endif	      /* Properly create the hostlist */  hostlist = (char **)calloc( 2, sizeof(char *) ) ;  hostlist[0]=strdup(curpop->shost);  hostlist[1] = (char *)NULL ;    /* Now, set the port! */  if(curpop->sport) {    smtpport=curpop->sport;  } else {    smtpport=25;  }#ifdef DMALLOC  dmalloc_verify( 0 ) ;#endif  curhost=cut_string (curpop->emailaddr, '@', 2, 1);  if(message->to) {#if DEBUG > 3    printf("Sendmsg: sending to: %s\n",message->to);#endif	      rfc822_parse_adrlist (&msg->to,message->to,curhost);  }    if(message->cc) {#if DEBUG > 3    printf("Sendmsg: sending cc: %s\n",message->cc);#endif	      rfc822_parse_adrlist (&msg->cc,message->cc,curhost);  }    if(message->bcc) {#if DEBUG > 3    printf("Sendmsg: sending bcc: %s\n",message->bcc);#endif	      rfc822_parse_adrlist (&msg->bcc,message->bcc,curhost);  }    if(message->from) {    if(curpop->real_name && curpop->emailaddr) {      sprintf(from,"\"%s\"<%s>",curpop->real_name,curpop->emailaddr);    } else if(curpop->emailaddr) {      sprintf(from,"%s",curpop->emailaddr);    } else {#if DEBUG > 3      printf("pop3smtp: No valid address");#endif	        return NOSENDERDOM;    }#if DEBUG > 3    printf("Sendmsg: sending from: %s\n",from);#endif	      /* Check to see if we need generate a rr header for this email. */#if DEBUG > 5    printf( "sendmsg: message has rr turned '%s'.\n", message -> rr?"ON":"OFF" ) ;#endif    if( message -> rr ) {      reply = from ;      #if DEBUG > 5      printf( "Reply has been set to '%s'.\n", reply ) ;#endif            /* Now, find the last item in the extra header list */      hdrCntr = 0 ;      while( message -> extraHeader[hdrCntr++] ) ;      message -> extraHeader[hdrCntr-1] = strdup( "Disposition-Notification-To" ) ;      message -> extraValue[hdrCntr-1] = strdup( reply ) ;      message -> extraHeader[hdrCntr] = (char *)NULL ;      message -> extraValue[hdrCntr] = (char *)NULL ;    }    /* Charles Hornberger <hornberger@tradeclient.org> found the problem with     * this, it seems rfc822_parse_adrlist() is mangling ``from'', we need to     * use a copy.     */    from2 = strdup (from);    rfc822_parse_adrlist (&msg->from, from, curhost);    /* use from2, if we have it, otherwise use the probably mangled ``from'' */    rfc822_parse_adrlist (&msg->return_path,				((from2 != NULL) ? from2 : from), curhost);    if (from2) free (from2);  }    from[0] = (char)0x00 ;  if(curpop->replyaddr) {    sprintf(from,"%s",curpop->replyaddr);    rfc822_parse_adrlist (&msg->reply_to,from,curhost);  } else {    /* Use the global value if one exists */    if( (tm_globs -> replyto) && strlen(tm_globs -> replyto) )      {	sprintf( from, "%s", tm_globs -> replyto ) ;	rfc822_parse_adrlist( &msg -> reply_to, from, curhost ) ;      }  }#if DEBUG > 3  if( strlen( from ) ) printf("Sendmsg: replyaddr: %s\n",from);#endif	    /*   * Now, handle the extra header values.  This is where we pick up things   * like rr, message priorities, X-Mailers, Organization, etc...   * Thanks Mahogany for this patch.  It saved me from having to do it.   */  rfc822_setextraheaders( (const char **)message -> extraHeader, (const char **)message -> extraValue ) ;  if(message->body) {#if DEBUG > 8    printf("Sendmsg: sending body: (%d attachments) \n%s\nSendmsg: end of body\n",message->attach_count,message->body);#endif	  #ifdef DMALLOC    dmalloc_verify( 0 ) ;#endif#if DEBUG > 4    printf( "We have %d attachments to encode! (body+n-1)\n", message -> attach_count ) ;#endif    if(!message->attach_count) {      body->type=TYPETEXT;      body->contents.text.data=(unsigned char *) message->body;      body->contents.text.size=strlen(message->body);    } else {      body->type=TYPEMULTIPART;      body->contents.text.data=(unsigned char *) message->body;      body->contents.text.size=strlen(message->body);      if (!body->parameter) {	char tmp[MAILTMPLEN];	sprintf( tmp, "---TradeClientMIMEBOUNDRY---%ld-%ld-%ld=:%ld", 		 gethostid(), random()*time(NULL)/getpid(), time(NULL), (long)getpid ) ;	body->parameter = mail_newbody_parameter ();	body->parameter->attribute = cpystr ("BOUNDARY");	body->parameter->value = cpystr (tmp);      }      part=body->nested.part=mail_newbody_part();      part->body.type=TYPETEXT;      part->body.contents.text.data=(unsigned char *) message->body;      part->body.contents.text.size=strlen(message->body);      for(i=0;i<message->attach_count-1;i++) {#if DEBUG > 4	printf( "Adding a new body part #%d of %d to MIME message.\n", i, message->attach_count-1 ) ;#endif	part=part->next=mail_newbody_part();	part->body.contents.text.data=cpystr(message->attach[i]);	part->body.contents.text.size=strlen(message->attach[i]);        part->body.parameter=mail_newbody_parameter ();        part->body.parameter->attribute = cpystr ("name");        part->body.parameter->value=cpystr(message->attachname[i]);	/* Now, set the encoding type.  If it's not a message, assume it's BASE64! */	if( strncasecmp( message->attachtype[i], "message", 7 ) == 0 ) part->body.encoding=ENC7BIT ;	else part->body.encoding=ENCBASE64;	part->body.disposition.type=cpystr("attachment");	part->body.disposition.parameter=mail_newbody_parameter ();	part->body.disposition.parameter->attribute=cpystr("filename");	part->body.disposition.parameter->value=cpystr(message->attachname[i]);	subtype=strchr(message->attachtype[i],'/');#if DEBUG > 4	printf("trying to encode the msg\n");	printf("------------------------------\n%s\n-------------------------------\n",message->attach[i]);        printf("attachtype: %s - %s\n",message->attachtype[i], subtype ) ;#endif		  	if(subtype!=NULL) {	  subtype++;		  type=strdup(message->attachtype[i]);	  if(strncmp(type,"audio",5) == 0) {	    part->body.type=TYPEAUDIO;	    part->body.subtype=strdup(subtype);	  } else if(strncmp(type,"text",4) == 0) {	    part->body.type=TYPETEXT;	    part->body.subtype=strdup(subtype);	  } else if(strncmp(type,"message",7) == 0) {	    part->body.type=TYPEMESSAGE;	    part->body.subtype=strdup(subtype);#if DEBUG > 4	    printf( "body part is now '%s'.\n", part->body.subtype ) ;#endif	  } else if(strncmp(type,"application",11) == 0) {	    part->body.type=TYPEAPPLICATION;	    part->body.subtype=strdup(subtype);	  } else if(strncmp(type,"image",5) == 0) {	    part->body.type=TYPEIMAGE;	    part->body.subtype=strdup(subtype);	  } else if(strncmp(type,"video",5) == 0) {	    part->body.type=TYPEVIDEO;	    part->body.subtype=strdup(subtype);	  } else if(strncmp(type,"other",5) == 0) {	    part->body.type=TYPEOTHER;	    part->body.subtype=strdup(subtype);	  } else {	    part->body.type=TYPEAPPLICATION;	    part->body.subtype=strdup(subtype);	  }	}else { 	  part->body.type=TYPEAPPLICATION;	  part->body.subtype=("octet-stream");	}	      }    }  }#ifdef DMALLOC  dmalloc_verify( 0 ) ;#endif  if(message->subject) {#if DEBUG > 4    printf("Sendmsg: subject: %s\n",message->subject);#endif	      msg->subject=cpystr(message->subject);  }  if(message->timestamp) {#if DEBUG > 4    printf("Sendmsg: timestamp: %s\n",message->timestamp);#endif	      msg->date=cpystr(message->timestamp);  }#if DEBUG > 4  printf("Try to open smtp connection to %s:%d : ",curpop->shost,smtpport);#endif  msg -> message_id = generate_msg_id() ;  if( !(stream=smtp_open_full (NIL,hostlist,"smtp",smtpport,(long)NULL)) ) {#ifdef DEBUG    printf("error opening SMTP connection\n");#endif	      return CONNREF;  }  if( smtp_mail(stream,"MAIL",msg,body) ) {#ifdef DEBUG    printf( _("Sendmsg: Sending message done\n") ) ;#endif	    }  else  {#ifdef DEBUG    printf( "[Failed] Sending message to parent: %s\n", stream -> reply ) ;#endif	      /* Send the text back to the parent */    pipe_parent_stat_put( EMESSAGE, stream -> reply, strlen(stream -> reply)+1 ) ;    return 0 ;  }  #ifdef DMALLOC  dmalloc_verify( 0 ) ;#endif  //Cleanup of memory  if(stream) smtp_close(stream);  /*   * Leak alert!!!  This is leaking every structure member that was allocated   * and assigned to this structure.   */#if 1  if( message ) free( message ) ;#else  if( message ) freeMessage( message ) ;#endif#if 0  /* It seems that c-client actually owns this memory! */  if(body) free(body);  if(msg) free (msg);#endif    if( hostlist[0] ) free( hostlist[0] ) ;  if( hostlist ) free( hostlist ) ;  //TIMESTAMP // MAILER // ORG#ifdef DMALLOC  dmalloc_verify( 0 ) ;#endif    return 0;}void new_smtpdisconnect (int id) {#ifdef DMALLOC  dmalloc_verify( 0 ) ;#endif  return;}char *popsmtp_error (int err) {  return pop_errors [abs (err)];}/* POP3 session */int new_pop3_login (MAILSTREAM **retStream, int id) {

⌨️ 快捷键说明

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