📄 view_m~1.cpp
字号:
status=view_message_body(user_file, next_header, m_num, part_num, current_mh->cont_boundary); } if(next_header != NULL) free_mail_headers(next_header); } while(status == st_pending || status == st_found); if(status != st_error && boundary != NULL) return(find_next_border(user_file,boundary)); return(status);}/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////status_type view_body_ct_multipart_alt(FILE* user_file, struct mail_header* current_mh, int m_num, int* part_num, char* boundary){ struct cont_alternative { struct mail_header* next_mh; long int file_ptr; }; status_type status=st_pending; cont_alternative* cont_alt=NULL; int x=0; int y=0; int best_part=0; void* temp_ptr=NULL; if(current_mh == NULL) return(st_error); //sanity check status=find_next_border(user_file, current_mh->cont_boundary); if(status == st_error || status == st_done) { if(boundary != NULL) return(find_next_border(user_file, boundary)); return(st_error); }//find different types of alternate multiparts and save headers in structure do { x++; temp_ptr=realloc(cont_alt,sizeof(cont_alternative)*x); if(temp_ptr == NULL) { if(cont_alt != NULL) { for(y=0;y<x-1;y++) if(cont_alt[y].next_mh != NULL) free_mail_headers(cont_alt[y].next_mh); free(cont_alt); } return(st_error); } cont_alt=(cont_alternative*)temp_ptr; cont_alt[x-1].next_mh=fill_mail_h_struct(user_file,(*part_num)++); if(cont_alt[x-1].next_mh == NULL) status=st_error; cont_alt[x-1].file_ptr=ftell(user_file); status=find_next_border(user_file,current_mh->cont_boundary); } while(status== st_found || status==st_pending);//find best part for(y=x-1;y<0;y--) { if(cont_alt[y].next_mh != NULL) if(cont_alt[y].next_mh->cont_type == ct_text_plain) best_part=y; }//display best part if(cont_alt[best_part].file_ptr != -1) fseek(user_file,cont_alt[best_part].file_ptr,SEEK_SET); status=view_message_body(user_file,cont_alt[best_part].next_mh, m_num, part_num-x+best_part, current_mh->cont_boundary);//clean up and exit for(y=0;y<x;y++) if(cont_alt[y].next_mh != NULL) free_mail_headers(cont_alt[y].next_mh); free(cont_alt); if(status != st_error && boundary != NULL) return(find_next_border(user_file, boundary)); return(st_done);}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////status_type view_body_ct_message_rfc822(FILE* user_file, mail_header* current_header, int m_num, int* part_num, char* boundary){ mail_header* next_header=NULL; status_type status=st_pending; next_header=fill_mail_h_struct(user_file,(*part_num)++); if(next_header == NULL) return(st_error); status=view_message_body(user_file, next_header,m_num,part_num,boundary); free_mail_headers(next_header); return(status);}/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////status_type view_body_ct_text_plain(FILE* user_file, mail_header* mail_hd, char* boundary){ char* file_buff=NULL; size_t file_buff_size=0; ssize_t b_read=0; int nl=0; status_type status=st_pending; printf("\n\n<TR><TD BGCOLOR=\"#EEEEEE\">"); do { b_read=getline(&file_buff,&file_buff_size,user_file); if(b_read <= 0 || file_buff == NULL) { if(file_buff != NULL) { free(file_buff); file_buff=NULL; } status=st_error; } status=is_boundary(file_buff,boundary); if(status == st_pending || status == st_nl) { if(mail_hd != NULL && mail_hd->cont_type_enc == cte_quoted_printable) fix_quoted_to_text(file_buff); if(strchr(file_buff,'\n') != NULL) nl=-1; else nl=0; text_to_html(file_buff); if(nl) printf("<BR>"); } } while(status == st_pending || status == st_nl); if(file_buff != NULL) free(file_buff); printf("\n</TD></TR>"); return(status);}//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////status_type view_body_ct_image(FILE* user_file, mail_header* current_header, int m_num, int* part_num, char* boundary){ if(user_file == NULL || current_header == NULL) return(st_error); printf("\n\n<TR><TD BGCOLOR=\"#EEEEEE\" ALIGN=\"CENTER\"><BR>"); printf("\n<A HREF=\"%s/%s?action=view_attachment&sessionid=%s&m_num=%d&" "part_num=%d&disp=attachment\">\n", user_env.script_name, current_header->filename != NULL ? current_header->filename : "unknown", user_ses.sessionid, m_num, *part_num); printf("<IMG SRC=\"%s/%s?action=view_attachment&sessionid=%s&m_num=%d&" "part_num=%d&disp=inline\" BORDER=\"0\">\n</A>", user_env.script_name, current_header->filename != NULL ? current_header->filename : "unknown", user_ses.sessionid, m_num, *part_num); printf("\n<BR><BR></TD></TR>"); if(boundary != NULL) return(find_next_border(user_file,boundary)); return(st_error);}//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////status_type view_body_ct_attachment(FILE* user_file, struct mail_header* c_hd, int m_num, int* part_num, char* boundary){ if(user_file == NULL || c_hd == NULL) return(st_error); printf("\n\n<TR><TD BGCOLOR=\"#EEEEEE\">"); printf("\n<TABLE CELLSPACING=\"10\"><TR>\n<TD>"); printf("\n<A HREF=\"%s/%s?action=view_attachment&sessionid=%s&m_num=%d&" "part_num=%d&disp=", user_env.script_name, c_hd->filename != NULL ? c_hd->filename : "unknown", user_ses.sessionid, m_num, *part_num); if(c_hd->cont_type == ct_application_pdf || c_hd->cont_type == ct_application_zip || c_hd->cont_type == ct_application_msword || c_hd->cont_type == ct_application_msexcel || c_hd->cont_type == ct_audio_other || c_hd->cont_type == ct_video_other || c_hd->cont_type == ct_text_plain || c_hd->cont_type == ct_text_other || c_hd->cont_type == ct_text_html || c_hd->cont_type == ct_image_jpeg || c_hd->cont_type == ct_image_gif || c_hd->cont_type == ct_image_png || c_hd->cont_type == ct_image_other) { printf("inline\">\n"); } else printf("attachment\">\n");//Display icon printf("\n <IMG SRC=\"" NMHTTP "/icons/"); if(c_hd->cont_type == ct_application_pdf) printf("acroread.gif"); else if(c_hd->cont_type == ct_application_zip) printf("zip.gif"); else if(c_hd->cont_type == ct_application_msword) printf("word.gif"); else if(c_hd->cont_type == ct_application_msexcel) printf("excel.gif"); else if(c_hd->cont_type == ct_application_other) printf("application.gif"); else if(c_hd->cont_type == ct_audio_other) printf("audio.gif"); else if(c_hd->cont_type == ct_video_other) printf("video.gif"); else if(c_hd->cont_type == ct_image_other || c_hd->cont_type == ct_image_jpeg || c_hd->cont_type == ct_image_gif || c_hd->cont_type == ct_image_png) printf("image.gif"); else if(c_hd->cont_type == ct_text_plain || c_hd->cont_type == ct_text_html || c_hd->cont_type == ct_text_other) printf("text.gif"); else printf("unknown.gif"); printf("\" BORDER=\"0\"></A>\n");//Print content type / filename printf("</TD>\n<TD>\nType: %s<BR>", c_hd->cont_type_string == NULL ? "uknown" : c_hd->cont_type_string); printf("Filename: \n"); printf(" <A HREF=\"%s/%s?action=view_attachment&sessionid=%s&m_num=%d&" "part_num=%d&disp=attachment\">", user_env.script_name, c_hd->filename != NULL ? c_hd->filename : "unknown", user_ses.sessionid, m_num, *part_num); printf("%s</A>\n</TD></TR>\n</TABLE>", c_hd->filename == NULL ? "unknown" : c_hd->filename); printf("\n</TD></TR>"); if(boundary != NULL) return(find_next_border(user_file,boundary)); return(st_error);}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Will find next content border or next message// returns st_error if next message found "\nFrom "// returns st_found if boundary found// returns st_done if last boundary foundstatus_type find_next_border(FILE* user_file, char* boundary){ char* file_buff=NULL; size_t file_buff_size=0; ssize_t b_read=0; status_type status=st_pending; if(user_file == NULL) return(st_error); status=st_pending; do { b_read=getline(&file_buff,&file_buff_size,user_file); if(b_read < 0 || file_buff == NULL) status=st_error; status=is_boundary(file_buff,boundary); } while(status == st_pending || status == st_nl); if(file_buff != NULL) free(file_buff); return(status);}///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Checks if line in buff is boundary// returns st_error if new message is found "From "// returns st_found if boundary found// returns st_done if end boundary found// returns st_pending if no border found// returns st_nl if nl foundstatus_type is_boundary(char* buff, char* boundary){//enum status_type { st_pending, st_nl, st_done, st_error, st_found}; if(buff == NULL) return(st_error); if(*buff == '\n') return(st_nl); if(strncmp(buff,"From ",sizeof("From ")-1) == 0) return(st_error); if(boundary == NULL) return(st_pending); if(strlen(buff) >= 3 && strncmp(buff,"--",2) == 0) { if(strncmp(buff+2, boundary, strlen(boundary)) == 0) { if( strlen(buff) >= 4+strlen(boundary) && strncmp(buff+2+strlen(boundary),"--",2) == 0) return(st_done); else return(st_found); } } return(st_pending); }//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -