📄 pop.cc
字号:
ifs.getline(buffer,256,'\n'); if (ligne<finentete) ofst<<buffer; if (strstr(buffer,"quoted-printable")!=0) QUOTED = true; //Si quoted alors on decode if ((ligne>debutcorps) && (ligne<fincorps) && (QUOTED)) { //On decode le texte texte = buffer; dec_quotedP(texte); ofsb<< texte; } else if ((ligne>debutcorps) && (ligne<fincorps) &&(!QUOTED)) ofsb<<buffer; } ofst.close(); ofsb.close(); ifs.close(); //Retourne 1 pour html ou 2 pour txt -1 en cas d'erreur return typech; }//Permet de lire des mails avec deux contenus differents et de telecharger les pieces jointesint Multipart_Mixed_simple (mail m, char* directory, bool debug){ mime mi; bool QUOTED = false; string texte; char buffer[4096]; char bufferdir[50]; char buffertop[50]; char buffermime[256]; char bufferbody[256]; int ligne,entete,corps,fin,finentete,fincorps; finentete = NbLine_Top(m,debug); fincorps = m.lignebound[2]; //Chemins des fichiers sprintf(bufferdir,"buffer/mail%i.mail",m.Fichier); sprintf(buffertop,"%s/email%i.top",directory,m.Fichier); sprintf(bufferbody,"%s/email%i.txt",directory,m.Fichier); //Etape 1 - On sauvegarde l'entete et le corps du texte ofstream ofst(buffertop); ofstream ofsb(bufferbody); ifstream ifs; ifs.open(bufferdir); if (!ifs.is_open()) { printf("%s Error Fichier inexistant \n",bufferdir); return -1; } while(ifs.good()){ ligne++; ifs.getline(buffer,4096,'\n'); if (ligne<finentete) ofst<<buffer; if (strstr(buffer,"quoted-printable")!=0) QUOTED = true; if ((ligne>finentete) && (ligne<fincorps) && (QUOTED)) { texte = buffer; dec_quotedP(texte); ofsb<< texte; } else if ((ligne>finentete) && (ligne<fincorps) &&(!QUOTED)) ofsb<<buffer; } ofst.close(); ofsb.close(); ifs.close(); //Etape 2 - On regarde la ou les pieces jointes for (int i=2;i<m.nbbound-1;i++){ ligne=0; entete = m.lignebound[i]; corps = m.lignebound[i]+3; fin = m.lignebound[i+1]-1; ifstream ifs; ifs.open(bufferdir); if (!ifs.is_open()) { printf("%s Error Fichier inexistant \n",bufferdir); return -1; } while(ifs.good()){ ligne++; ifs.getline(buffer,4096,'\n'); //Recherche des informations sur la pieces jointes if ((ligne>entete)&&(ligne<corps)){ if (strstr(buffer,"Content-type:")!=0) { mi.set_Content_type(search_STR(buffer,"Content-type: ",";")); if (debug ) printf(" %i %s \n",ligne,mi.Content_type); } if (strstr(buffer,"Content-Type:")!=0) { mi.set_Content_type(search_STR(buffer,"Content-Type: ",";")); if (debug ) printf(" %i %s \n",ligne,mi.Content_type); } if (strstr(buffer,"name=")!=0) { mi.set_Name(search_STR(buffer,"name=\"","\"")); if (debug ) printf(" %i %s\n",ligne,mi.Name); } if (strstr(buffer,"Content-Transfer-Encoding:")!=0) { mi.set_Encoding(search_STR(buffer,"Content-Transfer-Encoding: ","\r")); if (debug ) printf(" %i %s \n",ligne,mi.Encoding); } if (strstr(buffer,"Content-Disposition:")!=0) { mi.set_Content_Disposition(search_STR(buffer,"Content-Disposition:",";")); if (debug ) printf(" %i %s \n",ligne,mi.Content_Disposition); } } } ifs.close(); //Etape 3 - On recupere toutes les pieces jointes une par une sprintf(bufferbody,"temp/%s",mi.Name); sprintf(buffermime,"%s%s",directory,mi.Name); ligne = 0; ofstream ofs(bufferbody); ifs.open(bufferdir); if (!ifs.is_open()) { printf("%s Error Fichier inexistant \n",bufferdir); return -1; } while(ifs.good()){ ligne++; ifs.getline(buffer,4096,'\n'); //Copie du corps de la pieces jointes if ((ligne>corps)&&(ligne<fin)) ofs<<buffer; } ifs.close(); ofs.close(); //Dans le cas ou elles sont encodees on la decode dans le repertoire de destination if (strstr(mi.Encoding,"64")!=NULL){ if (debug) PRINTSTATEMENT("Decodage de la piece jointe en cours"); FILE *bufferI; FILE *bufferO; bufferI = fopen(bufferbody, "rw" ); bufferO = fopen(buffermime, "wb" ); decode(bufferI,bufferO); if (debug) PRINTSTATEMENT("Decodage terminer"); fclose(bufferI); fclose(bufferO); //PRINTSTATEMENT("Copie de la pieces jointes terminee"); } if(debug) PRINTD("Fichier lu",bufferbody); if(debug) PRINTD("Fichier ecrit",buffermime); } return 0;}//Pour les Emails contenant deux boundaryint Multipart_Alternative_complex (mail m,char* directory,bool debug){ bool QUOTED = false; string texte; int typech; char res[4]; char* type; char buffer[256]; char bufferdir[50]; char buffertop[256]; char bufferbody[256]; char buffermime[256]; int ligne,finentete,debutcorps,fincorps,corps,fin,entete; PRINT("Deux formats pour l'affichage sont disponibles HTML / TEXT, quel est votre choix ?"); SCAN(res); //Si c'est le format HTML //On va dans la partie du mail contenant du HTML if ((strstr(res,"h")!=NULL)||(strstr(res,"H")!=NULL)){ finentete = m.lignebound[2]; debutcorps = m.lignebound[4]+3; fincorps = m.lignebound[5]; type = "html"; typech = 1; } else { //Sinon on va dans la partie du mail contenant du texte finentete = m.lignebound[1]; debutcorps = m.lignebound[4]+3; fincorps = m.lignebound[4]; type = "txt"; typech = 2; } ligne = 0; //Chemins des fichiers sprintf(bufferdir,"buffer/mail%i.mail",m.Fichier); sprintf(buffertop,"%s/email%i.top",directory,m.Fichier); sprintf(bufferbody,"%s/email%i.%s",directory,m.Fichier,type); ofstream ofst(buffertop); ofstream ofsb(bufferbody); ifstream ifs; ifs.open(bufferdir); if (!ifs.is_open()) { printf("%s Error Fichier inexistant \n",bufferdir); return -1; } while(ifs.good()){ //Toujours meme principe on sauvegarde l'entete puis le corps du texte ligne++; ifs.getline(buffer,256,'\n'); if (ligne<finentete) ofst<<buffer; if (strstr(buffer,"quoted-printable")!=0) QUOTED = true; if ((ligne>debutcorps) && (ligne<fincorps) && (QUOTED)) { texte = buffer; dec_quotedP(texte); ofsb<< texte; } else if ((ligne>debutcorps) && (ligne<fincorps) &&(!QUOTED)) ofsb<<buffer; } ofst.close(); ofsb.close(); ifs.close(); mime mi; //Cas eventuel de pieces jointes apres... for (int i=7;i<m.nbbound-1;i++){ entete = m.lignebound[i]; corps = m.lignebound[i]+3; fin = m.lignebound[i+1]-1; ifstream ifs; ifs.open(bufferdir); if (!ifs.is_open()) { printf("%s Error Fichier inexistant \n",bufferdir); return -1; } while(ifs.good()){ ligne++; ifs.getline(buffer,256,'\n'); //Rechercher du type du corps du texte if ((ligne>entete)&&(ligne<corps)){ if (strstr(buffer,"Content-type:")!=0) { mi.set_Content_type(search_STR(buffer,"Content-type: ",";")); if (debug ) printf(" %i %s \n",ligne,mi.Content_type); } if (strstr(buffer,"Content-Type:")!=0) { mi.set_Content_type(search_STR(buffer,"Content-Type: ",";")); if (debug ) printf(" %i %s \n",ligne,mi.Content_type); } if (strstr(buffer,"name=")!=0) { mi.set_Name(search_STR(buffer,"name=\"","\"")); if (debug ) printf(" %i %s\n",ligne,mi.Name); } if (strstr(buffer,"Content-Transfer-Encoding:")!=0) { mi.set_Encoding(search_STR(buffer,"Content-Transfer-Encoding: ","\r")); if (debug ) printf(" %i %s \n",ligne,mi.Encoding); } if (strstr(buffer,"Content-Disposition:")!=0) { mi.set_Content_Disposition(search_STR(buffer,"Content-Disposition:",";")); if (debug ) printf(" %i %s \n",ligne,mi.Content_Disposition); } } } ifs.close(); //Cas ou la piece jointe est en definitif du texte if ((strstr(mi.Content_type,"text/plain")!=0)&&!(strstr(mi.Content_Disposition,"attach")!=0)){ sprintf(bufferbody,"%s/email%i.html",directory,m.Fichier); } if ((strstr(mi.Content_type,"text/html")!=0)&&!(strstr(mi.Content_Disposition,"attach")!=0)){ sprintf(bufferbody,"%s/email%i.html",directory,m.Fichier); } else sprintf(bufferbody,"temp/%s",mi.Name); ligne = 0; //On copie la piece jointe ofstream ofs(bufferbody); ifs.open(bufferdir); if (!ifs.is_open()) { printf("%s Error Fichier inexistant \n",bufferdir); return -1; } while(ifs.good()){ ligne++; ifs.getline(buffer,256,'\n'); //Copie du corps de la pieces jointes if ((ligne>corps)&&(ligne<fin)) ofs<<buffer; } ifs.close(); ofs.close(); //On la decode if (strstr(mi.Encoding,"64")!=NULL){ PRINT("Des fichiers sont joints a cette Email"); PRINT("Voulez vous les enregistrer ? YES / NO"); SCAN(directory); if ((strstr(directory,"Y")!=NULL)||(strstr(directory,"y")!=NULL)){ PRINT("Entrez le repertoire de destination :"); SCAN(directory); sprintf(buffermime,"%s/%s",directory,mi.Name); if (debug) PRINTSTATEMENT("Decodage de la piece jointe en cours"); FILE *bufferI; FILE *bufferO; bufferI = fopen(bufferbody, "rw" ); bufferO = fopen(buffermime, "wb" ); decode(bufferI,bufferO); if (debug) PRINTSTATEMENT("Decodage terminer"); fclose(bufferI); fclose(bufferO); PRINTSTATEMENT("Copie de la pieces jointes terminee"); } } if(debug) PRINTD("Fichier lu",bufferbody); if(debug) PRINTD("Fichier ecrit",buffermime); } //Retourne 1 pour html ou 2 pour txt -1 en cas d'erreur return typech; }//Permet de lire un messageint READMSG (mail m, bool debug){ char bufferdir[256]; char com[50]; char command[256]; //Entete PRINT("KKMAIL V3.0.1"); PRINT("-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"); //Affichage des informations du mail m.affiche_info(); PRINT("-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"); //On ouvre le fichier ifstream ifs; ifs.open(bufferdir); //Cas des mails simples if (strstr(m.Content_type,"text/html")!=0) { if (!ifs.is_open()) Text(m,"html","maildir",debug); sprintf(bufferdir,"maildir/email%i.html",m.Fichier); sprintf(command,"firefox %s&",bufferdir); PRINT("MESSAGE HTML - Ouverture de Firefox"); PRINT("------------------------------------------------------------------"); system(command); } //Cas des mails avec pieces jointes else if ((strstr(m.Content_type,"multipart/mixed")!=0) && (m.nbpart < 2)){ PRINT("ACTIONS :"); PRINT("------------------------------------------------------------------"); PRINT("Des fichiers sont joints a cette Email"); PRINT("Voulez vous les enregistrer ? YES / NO"); SCAN(com); if ((strstr(com,"Y")!=NULL)||(strstr(com,"y")!=NULL)){ PRINT("Entrez le repertoire de destination :"); SCAN(com); Multipart_Mixed_simple(m, com,debug); } else Multipart_Mixed_simple(m,"maildir/",debug); sprintf(bufferdir,"maildir/email%i.txt",m.Fichier); PRINT("-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"); PRINT("LECTURE DU MAIL :"); PRINT("------------------------------------------------------------------"); Read_File(bufferdir,'\r'); } //Cas des mails avec plusieurs contenus else if ((strstr(m.Content_type,"multipart/alternative")!=0) && (m.nbpart = 1)){ int ers; if (!ifs.is_open()) ers = Multipart_Alternative_complex(m,"maildir", debug); if (ers==1) { sprintf(bufferdir,"maildir/email%i.html",m.Fichier); sprintf(command,"firefox %s&",bufferdir); PRINT("MESSAGE HTML - Ouverture de Firefox"); PRINT("------------------------------------------------------------------"); system(command); } else { sprintf(bufferdir,"maildir/email%i.txt",m.Fichier); PRINT("LECTURE DU MAIL :"); PRINT("------------------------------------------------------------------"); Read_File(bufferdir,'\r'); } } //Cas des mails plus compliques else if ((strstr(m.Content_type,"multipart/mixed")!=0) && (m.nbpart > 1)&& (m.nbpart < 3)){ int ers; if (!ifs.is_open()) ers = Multipart_Alternative_simple(m,"maildir", debug); if (ers==1) { sprintf(bufferdir,"maildir/email%i.html",m.Fichier); sprintf(command,"firefox %s&",bufferdir); PRINT("MESSAGE HTML - Ouverture de Firefox"); PRINT("------------------------------------------------------------------"); system(command); } else { sprintf(bufferdir,"maildir/email%i.txt",m.Fichier); PRINT("LECTURE DU MAIL :"); PRINT("------------------------------------------------------------------"); Read_File(bufferdir,'\r'); } } //Autres cas on affiche le texte tout simplement else{ if (!ifs.is_open()) Text(m,"txt","maildir",debug); sprintf(bufferdir,"maildir/email%i.txt",m.Fichier); PRINT("LECTURE DU MAIL :"); PRINT("------------------------------------------------------------------"); Read_File(bufferdir,'\r'); } return 0;}//Permet de sauvegarder un mail et ces pieces jointes a un endroit précisint SAVE (mail m,char* directory, bool debug){ char bufferdir[256]; ifstream ifs; ifs.open(bufferdir); //Cherche le type du mail et on sauve if (strstr(m.Content_type,"text/html")!=0) { if (!ifs.is_open()) Text(m,"html",directory,debug); } else if ((strstr(m.Content_type,"multipart/mixed")!=0) && (m.nbpart < 2)){ Multipart_Mixed_simple(m,directory,debug); } else if ((strstr(m.Content_type,"multipart/alternative")!=0) && (m.nbpart = 1)){ if (!ifs.is_open()) Multipart_Alternative_simple(m,directory,debug); } else if ((strstr(m.Content_type,"multipart/mixed")!=0) && (m.nbpart > 1)&& (m.nbpart < 3)){ Multipart_Alternative_complex(m,directory,debug); } else{ if (!ifs.is_open()) Text(m,"txt",directory,debug); } return 0;}//Telecharge l'integralite des mails avec leurs entetesint REFRESH (int descBr, int nb_message, bool debug){ //Telecharge l'integralite des mails de la boite for(int i=1; i<nb_message+1; i++){ char temptop[256]; char tempmail[256]; sprintf(temptop,"buffer/mail%i.top",i); if (debug) PRINT(temptop); //on telecharge les entetes SAVETOP(descBr,i,temptop,debug); sprintf(tempmail,"buffer/mail%i.mail",i); if (debug) PRINT(tempmail); //ensuite les mails complets SAVEMSG(descBr,i,tempmail,debug); } //puis on affiche le resultat //LISTMSG (nb_message,debug); return 0;}//Permet d'effacer un mailint DELETE(int descBr,int numero, bool debug){ char res[4]; char temp[2]; char buffer[256]; PRINT("Veuillez confirmer la suppression du message : Yes/No"); SCAN(res); if ((strstr(res,"y")!=NULL)||(strstr(res,"Y")!=NULL)){ sprintf( temp,"%i",numero); printf("NUMERO %s\n",temp); //on demande l'envoie du message sprintf(buffer,"DELE %i \r\n",numero); WRITE(descBr, buffer, strlen(buffer)); if(debug) PRINTS(buffer); PRINTSTATEMENT("Message supprime..."); return 0; } PRINTSTATEMENT("Suppression du message annulee."); return 1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -