📄 mime.c
字号:
tmp2+=bsize; tmp1=tmp2; switch (mime_enc_type (tmphinfo->content_t_e)) { case ENC_BASE64: retbody=mime_dec_base64 (tmps, &slen); break; case ENC_QP: retbody=mime_dec_qp (tmps, &slen); break; case ENC_NONE: retbody=strdup (tmps); slen=strlen (tmps); break; } free (tmps); } } /* apparently we don't know how to handle this content type ... so let's ask * the user what to do */ else {#ifdef DMALLOC dmalloc_verify( 0 ) ;#endif tmpatt=(Attachment *)calloc(1, sizeof(Attachment)); tmpatt->offset=(tmp1-body)+hsize; if (digest==FALSE) { tmpatt->name=get_name (tmphinfo->content_type); tmpatt->fname=get_filename (tmphinfo->content_d); tmpatt->mtype=cut_string (tmphinfo->content_type, ';', 1, 1); } else { if (tmphinfo->from) tmpatt->name=strdup (tmphinfo->from); else tmpatt->name=strdup (""); if (tmphinfo->subject) tmpatt->fname=strdup (tmphinfo->subject); else tmphinfo->subject=strdup (""); tmpatt->mtype=cut_string (tmphinfo->content_type, ';', 1, 1); } if (tmpatt->mtype[0]=='\0') { free (tmpatt->mtype); tmpatt->mtype=strdup (tmphinfo->content_type); } tmp3l=strstr (tmp1, boundary); if(tmp3l) { for (;*tmp3l!='\n'; tmp3l--) {} tmpatt->length=tmp3l-tmp1; attseek->next=((void *)tmpatt); attseek=((Attachment *)attseek->next); tmp2=tmp1; tmp1=strstr (tmp2, boundary); tmp1+=bsize; } } destroy_hinfo (tmphinfo); tmphinfo=NULL; if (digest==FALSE) { if ((*tmp1=='\n')||(*tmp1=='\r')) tmp1++; if ((*tmp1=='\n')||(*tmp1=='\r')) tmp1++; } else { for (;((*tmp1=='\n') || (*tmp1=='\r'));tmp1++) {} } while ( (tmp1!=NULL) && (strncmp (tmp1, "--", 2)!=0) ) {#ifdef DMALLOC dmalloc_verify( 0 ) ;#endif tmplen=message_hsize (tmp1); tmphead=(char *)calloc(tmplen+2, sizeof(char)); memmove (tmphead, tmp1, tmplen); tmphinfo=parse_header (tmphead); if (tmphead) free (tmphead); tmpatt=(Attachment *)calloc(1, sizeof(Attachment)); tmpatt->offset=(tmp1-body)+hsize; if (digest==FALSE) { tmpatt->name=get_name (tmphinfo->content_type); tmpatt->fname=get_filename (tmphinfo->content_d); tmpatt->mtype=cut_string (tmphinfo->content_type, ';', 1, 1); } else { if (tmphinfo->from) tmpatt->name=strdup (tmphinfo->from); else tmpatt->name=strdup (""); if (tmphinfo->subject) tmpatt->fname=strdup (tmphinfo->subject); else tmphinfo->subject = strdup (""); tmpatt->mtype=cut_string (tmphinfo->content_type, ';', 1, 1); } if (tmpatt->mtype[0]=='\0') { free (tmpatt->mtype); tmpatt->mtype=strdup (tmphinfo->content_type); } tmp3l=strstr (tmp1, boundary); if (tmp3l) { for (;*tmp3l!='\n'; tmp3l--) {} } else { tmp3l=tmp1+strlen (tmp1); } tmpatt->length=tmp3l-tmp1; attseek->next=((void *)tmpatt); attseek=((Attachment *)attseek->next); destroy_hinfo (tmphinfo); tmphinfo=NULL; tmp2=tmp1; tmp1=strstr (tmp2, boundary); if (tmp1) { tmp1+=bsize; if (digest==FALSE) { if ((*tmp1=='\n')||(*tmp1=='\r')) tmp1++; if ((*tmp1=='\n')||(*tmp1=='\r')) tmp1++; } else { for (;((*tmp1=='\n') || (*tmp1=='\r'));tmp1++) {} } } else { tmp1=NULL; } } free (boundary); free (body); if (!retbody) retbody=strdup (_("Message is only encoded attachments")); if (rethead) { ret=(char *)calloc(strlen (retbody)+strlen (rethead)+4, sizeof(char)); memmove (ret, rethead, strlen (rethead)); memmove (ret+strlen (rethead), retbody, strlen (retbody)); free (rethead); } else { ret=(char *)calloc(strlen (retbody)+4, sizeof(char)); memmove (ret, retbody, strlen (retbody)); }#if DEBUG > 9 gettimeofday (&tv2, NULL); tf1=(tv1.tv_sec&0x000000ff)+((float)tv1.tv_usec/(float)1000000); tf2=(tv2.tv_sec&0x000000ff)+((float)tv2.tv_usec/(float)1000000); printf ("takes %f seconds for mime_process\n", (tf2-tf1));#endif destroy_hinfo (hinfo); free (retbody); free (head); return ret; } else { tmps=cut_string (hinfo->content_type, ';', 1, 1); if (tmps[0]=='\0') { free (tmps); tmps=strdup(hinfo->content_type); } mtype=mime_type_search_type (tmps); switch (mime_handle (tmps)) { case MIMEHANDLE_SAVE: if (ret==NULL) { free (rethead); rethead=(char *)calloc (2, sizeof(char)); retbody=(char *)calloc (2, sizeof(char)); } // msg=strdup(message);#ifdef DMALLOC dmalloc_verify( 0 ) ;#endif if (popup) { yesno=create_yesno (_("Save to disk"), _("Would you like to save this message to disk?"), GTK_SIGNAL_FUNC (message_save_body), ((gpointer)strdup(message))); gtk_widget_show (yesno); } break; case MIMEHANDLE_NONE: case MIMEHANDLE_PROMPT: if (popup) { mime_attachment_unknown (strdup(message)); } retbody=(char *)calloc (2, sizeof(char)); if (rethead) free (rethead); rethead=(char *)calloc (2, sizeof(char)); break; case MIMEHANDLE_INT: if (strncasecmp (tmps, "message/rfc822", 14)==0) { message_window_new_stream (strdup (message+hsize)); if (rethead) free (rethead); rethead=(char *)calloc(2, sizeof(char)); retbody=(char *)calloc(2, sizeof(char)); } else { tmp3l=(char *)calloc(strlen(message)+2, sizeof(char)); if(*(message+hsize)=='\n') memmove (tmp3l, message+hsize+1, strlen(message)-hsize-1); else memmove (tmp3l, message+hsize, strlen(message)-hsize); switch (mime_enc_type (hinfo->content_t_e)) { case ENC_BASE64: retbody=mime_dec_base64 (tmp3l, &slen); break; case ENC_QP: retbody=mime_dec_qp (tmp3l, &slen); break; case ENC_NONE: retbody=strdup (tmp3l); slen=strlen (tmp3l); break; } free (tmp3l); } break; case MIMEHANDLE_EXT: retbody=(char *)calloc (2, sizeof(char)); if (rethead) free (rethead); rethead=(char *)calloc (2, sizeof(char)); if (popup) { msg=strdup(message); yesno=create_yesno (_("Use external program"), _("Would you like to view this message with the program selected?"), GTK_SIGNAL_FUNC (message_use_ext_prog), ((gpointer)msg)); gtk_widget_show (yesno); } break; } if (tmps) free (tmps); if (rethead) { ret=(char *)calloc(strlen (retbody)+strlen (rethead)+4, sizeof(char)); if (rethead[0]!='\0') memmove (ret, rethead, strlen (rethead)); if (retbody[0]!='\0') memmove (ret+strlen (rethead), retbody, strlen (retbody)); free (rethead); } else { ret=(char *)calloc(strlen (retbody)+2, sizeof(char)); if (retbody[0]!='\0') memmove (ret, retbody, strlen (retbody)); }#if DEBUG > 9 gettimeofday (&tv2, NULL); tf1=(tv1.tv_sec&0x000000ff)+((float)tv1.tv_usec/(float)1000000); tf2=(tv2.tv_sec&0x000000ff)+((float)tv2.tv_usec/(float)1000000); printf ("takes %f seconds for mime_process\n", (tf2-tf1));#endif#ifdef DMALLOC dmalloc_verify( 0 ) ;#endif destroy_hinfo (hinfo); free (retbody); free (head); return ret; }#ifdef DMALLOC dmalloc_verify( 0 ) ;#endif destroy_hinfo (hinfo); free (retbody); free (head); if (tmps) free (tmps);#ifdef DMALLOC dmalloc_verify( 0 ) ;#endif return NULL;}char *mime_get_attachment (char *message, Attachment *att) { char *ret;#ifdef DMALLOC dmalloc_verify( 0 ) ;#endif if (message) { if (att) { ret=(char *)calloc (att->length+2, sizeof(char)); message+=att->offset; memmove (ret, message, att->length);#ifdef DMALLOC dmalloc_verify( 0 ) ;#endif return ret; } }#ifdef DMALLOC dmalloc_verify( 0 ) ;#endif return NULL;}MailMessage *new_mime_encode (char *from, char *replyto, char *org, char *to, char *cc, char *bcc, char *subject, char *timestamp, Llist *atlst, int returnreceipt, char *priority, char *sensitivity, char *keyword, char *expire, char *replyby, char *messageflag ) { AFS *tmpat=NULL; MimeType *mtype; int attachnr; int seekCntr ; MailMessage *mmessage=NULL; FILE *fd; Llist *lseek=NULL; struct stat *st; int atmemb=llist_length (atlst);//size; char tmp[1024] ; char *tmps2,*tmps3; int hdrCnt, hdrCntr ; int numPriority ; char *textPriority ; char *osInfo ; hdrCnt = hdrCntr = seekCntr = 0 ; mmessage=(MailMessage *)calloc(1, sizeof(MailMessage));#ifdef DEBUG printf ("new_mime_encode: Assembling the header\n");#endif#if DEBUG > 4 printf( "from = %s.\n", from ) ;#endif if(from) { mmessage->from=(char *)calloc(strlen(from)+1, sizeof(char)); memmove(mmessage->from,from,strlen(from)); if( !replyto ) mmessage->replyto = strdup( from ) ; }#if DEBUG > 4 printf( "from = %s.\n", from ) ;#endif if(replyto) { mmessage->replyto=(char *)calloc(strlen(replyto)+1, sizeof(char)); memmove(mmessage->replyto,replyto,strlen(replyto)); } if(subject) { mmessage->subject=(char *)calloc(strlen(subject)+1, sizeof(char)); memmove(mmessage->subject,subject,strlen(subject)); } if(to) { mmessage->to=(char *)calloc(strlen(to)+1, sizeof(char)); memmove(mmessage->to,to,strlen(to)); } if(cc) { mmessage->cc=(char *)calloc(strlen(cc)+1, sizeof(char)); memmove(mmessage->cc,cc,strlen(cc)); } if(bcc) { mmessage->bcc=(char *)calloc(strlen(bcc)+1, sizeof(char)); memmove(mmessage->bcc,bcc,strlen(bcc)); } if(org) { mmessage->organization=(char *)calloc(strlen(org)+1, sizeof(char)); memmove(mmessage->organization,org,strlen(org)); hdrCnt++ ; } if(timestamp) { mmessage->timestamp=(char *)calloc(strlen(timestamp)+1, sizeof(char)); memmove(mmessage->timestamp,timestamp,strlen(timestamp)); } /* * Take care of the return receipt flag. This * way, we always have room for it. */ hdrCnt++ ; mmessage -> rr = returnreceipt ;#if DEBUG > 6 printf( "MSG: mmessage has rr turned '%s'.\n", returnreceipt?"ON":"OFF" ) ;#endif /* * Add in extra header lines for needed items. * This gives us, x-mailer, 3-priority lines, plus hdrCnt, plus NULL, * plus language, plus sensitivity, plus keywords, plus reply by, * plus expire on, plus x-message-flags, for a total of hdrCnt + 11 ; */ hdrCnt += 11 ; mmessage -> extraHeader = (char **)calloc( hdrCnt, sizeof(char *) ) ; mmessage -> extraValue = (char **)calloc( hdrCnt, sizeof(char *) ) ; /* Organization */ if( org ) { mmessage -> extraHeader[hdrCntr] = strdup( "Organization" ) ; mmessage -> extraValue[hdrCntr] = strdup( org ) ; hdrCntr++ ; } mmessage -> extraHeader[hdrCntr] = strdup( "X-Mailer" ) ; snprintf( tmp, 1022, "TradeClient %s [%s] %s", VERSION, lang_getlang(), (osInfo = generate_os_info()) ) ; mmessage -> extraValue[hdrCntr] = strdup( tmp ) ; free( osInfo ) ; hdrCntr++ ; /* Now, parse out the priority needed below */ textPriority = malloc( strlen(priority) ) ; sscanf( priority, "%d (%s)", &numPriority, textPriority ) ; if( textPriority[strlen(textPriority)-1] == ')' ) textPriority[strlen(textPriority)-1] = (char)0x00 ; /* Priority 1 simply reads as * ( "n (verbage)" string where n = 1 - 5 and text is the below strings */ if( priority ) { mmessage -> extraHeader[hdrCntr] = strdup( "X-Priority" ) ; mmessage -> extraValue[hdrCntr] = strdup( priority ) ; hdrCntr++ ; } /* Priority 2 * (Should read as Lowest, Low, Normal, High, Highest; same as importance) */ if( priority ) { mmessage -> extraHeader[hdrCntr] = strdup( "X-MSMail-Priority" ) ; mmessage -> extraValue[hdrCntr] = strdup( textPriority ) ; hdrCntr++ ; } /* * Priority 3 (Importance should read as Lowest, Low, Normal, High, Highest). */ if( priority ) { mmessage -> extraHeader[hdrCntr] = strdup( "Importance" ) ; mmessage -> extraValue[hdrCntr] = strdup( textPriority ) ; hdrCntr++ ; } /* Free the parsed priority string as it is no longer needed. */ free( textPriority ) ; /* Language of choice */ mmessage -> extraHeader[hdrCntr] = strdup( "X-Accept-Language" ) ; mmessage -> extraValue[hdrCntr] = strdup( lang_getlang() ) ; hdrCntr++ ; /* * Now, process the following header values: sensitivity, expire on, * keywords (categories), message flags, and reply by. */ if( sensitivity ) { mmessage -> extraHeader[hdrCntr] = strdup( "Sensitivity" ) ; mmessage -> extraValue[hdrCntr] = strdup( sensitivity ) ; hdrCntr++ ; } if( keyword ) { mmessage -> extraHeader[hdrCntr] = strdup( "Keywords" ) ; mmessage -> extraValue[hdrCntr] = strdup( keyword ) ; hdrCntr++ ; } if( expire ) { mmessage -> extraHeader[hdrCntr] = strdup( "Expiry-Date" ) ; mmessage -> extraValue[hdrCntr] = strdup( expire ) ; hdrCntr++ ; } if( replyby ) { mmessage -> extraHeader[hdrCntr] = strdup( "Reply-By" ) ; mmessage -> extraValue[hdrCntr] = strdup( replyby ) ; hdrCntr++ ; } if( messageflag ) { mmessage -> extraHeader[hdrCntr] = strdup( "X-Message-Flag" ) ; mmessage -> extraValue[hdrCntr] = strdup( messageflag ) ; hdrCntr++ ; } /* Terminate our key/value sequence */ mmessage -> extraHeader[hdrCntr] = (char *)NULL ; mmessage -> extraValue[hdrCntr] = (char *)NULL ; if (atmemb<2) {#ifdef DEBUG printf ("new_mime_encode: Found only one attachment (probably the message body)\n");#endif } else {#ifdef DEBUG printf ("mime_encode: Found %d attachments\n", atmemb);#endif mmessage->attach_count=atmemb; lseek=atlst; attachnr=0; while (lseek) { tmpat=((AFS *)lseek->data); if (tmpat->filename) { st=(struct stat *)calloc (1, sizeof(struct stat)); stat (tmpat->filename, st); fd=fopen (tmpat->filename, "r") ; if(fd!=0){ mmessage->attach[attachnr]=(char *)calloc (st->st_size, sizeof(char)); tmps2=(char *)calloc(strlen(tmpat->filename),sizeof(char)); tmps2=strrchr (tmpat->filename,'.'); if (tmps2) { tmps2++; mtype=mime_type_search_ext (tmps2); if(mtype) { mmessage->attachtype[attachnr]=(char *)calloc (1024, sizeof(char));#if DEBUG > 6 printf("encoding attachment as type '%s'.\n",mtype->type);#endif snprintf(mmessage->attachtype[attachnr],1024,"%s",mtype->type); } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -