📄 parse_~2.cpp
字号:
if(time_struct.tm_mon == -1) return(0); time_struct.tm_isdst=-1; conv_time=mktime(&time_struct); return(conv_time); }////////////////////////////////////////////////////////////////////////This will sort an array of mail_header structures used to order messages// during the inbox pageint sort_mh(struct mail_header* mh_data,struct mail_header*** sorted_headers){ int num_messages=0; int x=0; int y=0; struct mail_header* mh_ptr=NULL; char* in_x=NULL; char* in_y=NULL; if(mh_data == NULL) return(0); //no messages to sort mh_ptr=mh_data; while(mh_ptr != NULL) { num_messages++; mh_ptr=mh_ptr->next_header; } *sorted_headers=(struct mail_header**) malloc( sizeof(struct mail_header*) * num_messages ); if(*sorted_headers == NULL) { syslog(LOG_MAIL | LOG_ERR,"Out of memory"); return(-1); } mh_ptr=mh_data; for(x=0;x<num_messages;x++) { (*sorted_headers)[x]=mh_ptr; mh_ptr=mh_ptr->next_header; } if(num_messages <= 1) return(num_messages); switch (mail_sort) { case ms_subj_a: for(x=0; x < num_messages-1; x++) for(y=x+1; y < num_messages; y++) if(strcasecmp( (*sorted_headers)[x]->subject, (*sorted_headers)[y]->subject) < 0) { mh_ptr=(*sorted_headers)[x]; (*sorted_headers)[x]=(*sorted_headers)[y]; (*sorted_headers)[y]=mh_ptr; } break; case ms_subj_d: for(x=0; x < num_messages-1; x++) for(y=x+1; y < num_messages; y++) if(strcasecmp( (*sorted_headers)[x]->subject, (*sorted_headers)[y]->subject) > 0) { mh_ptr=(*sorted_headers)[x]; (*sorted_headers)[x]=(*sorted_headers)[y]; (*sorted_headers)[y]=mh_ptr; } break; case ms_sender_a: for(x=0; x < num_messages-1; x++) for(y=x+1; y < num_messages; y++) { if( (*sorted_headers)[x]->from[0].name != NULL) in_x=(*sorted_headers)[x]->from[0].name; else if( (*sorted_headers)[x]->from[0].email != NULL) in_x=(*sorted_headers)[x]->from[0].email; else in_x=NULL; if( (*sorted_headers)[y]->from[0].name != NULL) in_y=(*sorted_headers)[y]->from[0].name; else if( (*sorted_headers)[y]->from[0].email != NULL) in_y=(*sorted_headers)[y]->from[0].email; else in_y=NULL; if( in_x != NULL && in_y != NULL) { if(strcasecmp(in_x,in_y) < 0) { mh_ptr=(*sorted_headers)[x]; (*sorted_headers)[x]=(*sorted_headers)[y]; (*sorted_headers)[y]=mh_ptr; } } else if( in_x == NULL) { mh_ptr=(*sorted_headers)[x]; (*sorted_headers)[x]=(*sorted_headers)[y]; (*sorted_headers)[y]=mh_ptr; } } break; case ms_sender_d: for(x=0; x < num_messages-1; x++) for(y=x+1; y < num_messages; y++) { if( (*sorted_headers)[x]->from[0].name != NULL) in_x=(*sorted_headers)[x]->from[0].name; else if( (*sorted_headers)[x]->from[0].email != NULL) in_x=(*sorted_headers)[x]->from[0].email; else in_x=NULL; if( (*sorted_headers)[y]->from[0].name != NULL) in_y=(*sorted_headers)[y]->from[0].name; else if( (*sorted_headers)[y]->from[0].email != NULL) in_y=(*sorted_headers)[y]->from[0].email; else in_y=NULL; if( in_x != NULL && in_y != NULL) { if(strcasecmp(in_x,in_y) > 0) { mh_ptr=(*sorted_headers)[x]; (*sorted_headers)[x]=(*sorted_headers)[y]; (*sorted_headers)[y]=mh_ptr; } } else if( in_y == NULL) { mh_ptr=(*sorted_headers)[x]; (*sorted_headers)[x]=(*sorted_headers)[y]; (*sorted_headers)[y]=mh_ptr; } } break; case ms_size_a: for(x=0; x < num_messages-1; x++) for(y=x+1; y < num_messages; y++) if( (*sorted_headers)[x]->size_of_message > (*sorted_headers)[y]->size_of_message) { mh_ptr=(*sorted_headers)[x]; (*sorted_headers)[x]=(*sorted_headers)[y]; (*sorted_headers)[y]=mh_ptr; } break; case ms_size_d: for(x=0; x < num_messages-1; x++) for(y=x+1; y < num_messages; y++) if( (*sorted_headers)[x]->size_of_message < (*sorted_headers)[y]->size_of_message) { mh_ptr=(*sorted_headers)[x]; (*sorted_headers)[x]=(*sorted_headers)[y]; (*sorted_headers)[y]=mh_ptr; } break; case ms_date_a: for(x=0; x < num_messages-1; x++) for(y=x+1; y < num_messages; y++) if( (*sorted_headers)[x]->date_received > (*sorted_headers)[y]->date_received) { mh_ptr=(*sorted_headers)[x]; (*sorted_headers)[x]=(*sorted_headers)[y]; (*sorted_headers)[y]=mh_ptr; } break; case ms_date_d: default: for(x=0; x < num_messages-1; x++) for(y=x+1; y < num_messages; y++) if( (*sorted_headers)[x]->date_received < (*sorted_headers)[y]->date_received) { mh_ptr=(*sorted_headers)[x]; (*sorted_headers)[x]=(*sorted_headers)[y]; (*sorted_headers)[y]=mh_ptr; } break; } return(num_messages);}////////////////////////////////////////////////////////////////////////This will determine content type//// first char of string passed should be first char of content typecontent_type determine_content_type(char* char_buff){ char x=0; struct content_type_labels { char* label; content_type ct_type; }; const content_type_labels ct_labels[]={ { "text/plain", ct_text_plain }, { "text/html", ct_text_html }, { "text/", ct_text_other }, { "multipart/mixed", ct_multipart_mixed }, { "multipart/alternative", ct_multipart_alternative }, { "multipart/parallel", ct_multipart_parallel }, { "multipart/digest", ct_multipart_digest }, { "multipart/", ct_multipart_other }, { "message/rfc822", ct_message_rfc822 }, { "message/partial", ct_message_partial }, { "message/external-body", ct_message_externalbody }, { "message/", ct_message_other }, { "application/pdf", ct_application_pdf }, { "application/zip", ct_application_zip }, { "application/x-zip-compressed", ct_application_zip }, { "application/msword", ct_application_msword }, { "application/vnd.ms-excel", ct_application_msexcel }, { "application/msexcel", ct_application_msexcel }, { "application/", ct_application_other }, { "image/jpeg", ct_image_jpeg }, { "image/gif", ct_image_gif }, { "image/png", ct_image_png }, { "image/", ct_image_other }, { "audio/", ct_audio_other }, { "video/", ct_video_other }, { NULL, ct_other } }; if(char_buff == NULL) return(ct_none); //sanity check for(x=0; ct_labels[x].label; x++) { if( ct_labels[x].label == NULL ) return(ct_other); if( strncasecmp(ct_labels[x].label, char_buff,strlen(ct_labels[x].label)-1) == 0) return(ct_labels[x].ct_type); } return(ct_other);}////////////////////////////////////////////////////////////////////////This will determine the content type encoding//// string passed should point to first char of encoding typecontent_type_encoding determine_content_type_enc(char* char_buff){ char x=0; struct content_type_enc_labels { char* label; content_type_encoding ct_encoding; }; content_type_enc_labels cte_labels[]= { { "7bit", cte_7bit }, { "quoted-printable", cte_quoted_printable }, { "base64", cte_base64 }, { "8bit", cte_8bit }, { "binary", cte_binary }, { NULL, cte_none } }; if(char_buff == NULL) return(cte_none); for(x=0; cte_labels[x].label; x++) { if( strncasecmp(cte_labels[x].label, char_buff,strlen(cte_labels[x].label)) == 0) return(cte_labels[x].ct_encoding); } return(cte_none);}////////////////////////////////////////////////////////////////////////This function will return a newly allocated string that is the // content type text// pass pointer to Content-Type value// get_head_data should automatically point to string since it// gets rid of LWSPchar* get_ct_string(char* buff){ char* new_buff=NULL; size_t new_size=0; if(buff == NULL) { syslog(LOG_MAIL | LOG_ERR,"get_ct_string passed null pointer."); return(NULL); }//get size of content type string value new_size=strcspn(buff," \t;\n");//allocate new string new_buff=(char*)malloc(new_size + 1); if(new_buff == NULL) { syslog(LOG_MAIL | LOG_ERR,"Out of memory."); return(NULL); }//copy string strncpy(new_buff,buff,new_size);//terminate string *(new_buff + new_size)='\0'; return(new_buff);}////////////////////////////////////////////////////////////////////////Returns the parameter value// pass buffer and parameter name of value you want to findchar* get_parameter_value(char* buff,char* parameter_name){ char* char_ptr=NULL; char* new_buff=NULL; size_t new_buff_size=0; status_type status=st_pending; if(buff == NULL || parameter_name == NULL) return(NULL); char_ptr=buff; do { char_ptr=strchr(char_ptr,';'); //all parameternames follow ';' if(char_ptr == NULL) return(NULL); char_ptr++; //skip any initial LWSP char_ptr=strpcbrk(char_ptr," \t"); if(strncasecmp(char_ptr,parameter_name,strlen(parameter_name)) == 0) { status=st_found; char_ptr+=strlen(parameter_name); } } while(status==st_pending); if(status != st_found || char_ptr == NULL) return(NULL); char_ptr=strchr(char_ptr,'='); //find '=' if(char_ptr == NULL) return(NULL); char_ptr++; char_ptr=strpcbrk(char_ptr," \t\""); //skip any LWSP after '=' if(char_ptr == NULL) return(NULL); //compute remaing string size new_buff_size=strcspn(char_ptr,";\"\n"); //allocate new string new_buff=(char*) malloc(new_buff_size + 1); if(new_buff == NULL) return(NULL);//copy and return string strncpy(new_buff,char_ptr,new_buff_size); *(new_buff+new_buff_size)='\0'; return(new_buff);}//////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -