#include #include #include #include #include #include #include #include #include "tlmpmail.h" #include "tlmpmail.m" #include "../framework/framework.h" #include "keys.h" struct FOLDER_EDIT_PRIVATE{ int no; MAIL_MESSAGE *msg; FOLDER_VIEW *folder; MAIL_MESSAGES tb; FOLDER_EDIT_PRIVATE(){ } }; void _F_folder_edit::popup(int, MAIL_MESSAGE &, FOLDER_VIEW *, const UISTATE &) { } void _F_folder_edit::msg_reply (int no) { } void _F_folder_edit::msg_forward (int no) { } void _F_folder_edit::event (int no, MAIL_MESSAGE &msg) { } void _F_folder_edit::notice (const char *line) { } void _F_folder_edit::present (int no, MAIL_MESSAGE &msg, SSTRING &) { } void _F_folder_edit::stats (int , int , int , int, int) { } void _F_folder_edit::message (bool &, FOLDER_VIEW *, MAIL_MESSAGE &msg) { } void _F_folder_edit::msg_delete (int no) { MAIL_MESSAGE *msg = priv->tb.getitem(no); msg->set_deleted(!msg->deleted); } void _F_folder_edit::msg_tag (int no, bool set, const char *tag) { } static void f_showmsg (void *p) { _F_folder_edit *c = (_F_folder_edit*)p; c->priv->msg->incrusage(); c->showmsg (c->priv->no,*c->priv->msg,c->priv->folder); c->priv->msg->decrusage(); } void _F_folder_edit::clickhead (int , FOLDER_VIEW *) { } void _F_folder_edit::docpopup(FOLDER_VIEW *, const UISTATE &, bool &) { } static int cmp_status (const ARRAY_OBJ *o1, const ARRAY_OBJ *o2) { // MAIL_MESSAGE *m1 = (MAIL_MESSAGE*)o1; // MAIL_MESSAGE *m2 = (MAIL_MESSAGE*)o2; int ret = 0; return ret; } static int cmp_from (const ARRAY_OBJ *o1, const ARRAY_OBJ *o2) { MAIL_MESSAGE *m1 = (MAIL_MESSAGE*)o1; MAIL_MESSAGE *m2 = (MAIL_MESSAGE*)o2; SSTRING f1,f2; mime_translate (m1->getauthor(),f1); mime_translate (m2->getauthor(),f2); return f1.icmp(f2); } static int cmp_subject (const ARRAY_OBJ *o1, const ARRAY_OBJ *o2) { MAIL_MESSAGE *m1 = (MAIL_MESSAGE*)o1; MAIL_MESSAGE *m2 = (MAIL_MESSAGE*)o2; SSTRING s1,s2; mime_translate (m1->subject,s1); mime_translate (m2->subject,s2); return s1.icmp(s2); } static int cmp_date (const ARRAY_OBJ *o1, const ARRAY_OBJ *o2) { MAIL_MESSAGE *m1 = (MAIL_MESSAGE*)o1; MAIL_MESSAGE *m2 = (MAIL_MESSAGE*)o2; int ret = 0; if (m1->date < m2->date){ ret = -1; }else if (m1->date > m2->date){ ret = 1; } return ret; } static int cmp_size (const ARRAY_OBJ *o1, const ARRAY_OBJ *o2) { MAIL_MESSAGE *m1 = (MAIL_MESSAGE*)o1; MAIL_MESSAGE *m2 = (MAIL_MESSAGE*)o2; return m1->size - m2->size; } static int cmp_to (const ARRAY_OBJ *o1, const ARRAY_OBJ *o2) { MAIL_MESSAGE *m1 = (MAIL_MESSAGE*)o1; MAIL_MESSAGE *m2 = (MAIL_MESSAGE*)o2; SSTRING s1,s2; mime_translate (m1->getdest(),s1); mime_translate (m2->getdest(),s2); return s1.icmp(s2); } static int cmp_flag (const ARRAY_OBJ *o1, const ARRAY_OBJ *o2, const char *key) { MAIL_MESSAGE *m1 = (MAIL_MESSAGE*)o1; MAIL_MESSAGE *m2 = (MAIL_MESSAGE*)o2; const char *mt1 = m1->getflag(key); const char *mt2 = m2->getflag(key); return strcasecmp(mt1,mt2); } static int cmp_type (const ARRAY_OBJ *o1, const ARRAY_OBJ *o2) { return cmp_flag (o1,o2,K_MSGTYPE); } static int cmp_remind (const ARRAY_OBJ *o1, const ARRAY_OBJ *o2) { return cmp_flag (o1,o2,K_REMIND); } /* Compare by project and type */ static int cmp_project (const ARRAY_OBJ *o1, const ARRAY_OBJ *o2) { int ret = cmp_flag (o1,o2,K_PROJECT); if (ret == 0) ret = cmp_type (o1,o2); return ret; } static void folder_copymsg (const MAIL_MESSAGES &src, MAIL_MESSAGES &dst) { int n = src.getnb(); for (int i=0; iviewed) nbnew++; if (m->deleted) nbdel++; if (m->tagged) nbtag++; } c->stats (lastmsg,nb,nbnew,nbdel,nbtag); } void folder_edit( _F_folder_edit &c, FOLDER_VIEW *folder, const char *title, FRAMEWORK_INFO &info, _F_FRAMEWORK *fram, bool invert_fromto) // Present the to field before the from // Used to present sent-mail folders { glocal _F_folder_edit *c = &c; glocal FOLDER_EDIT_PRIVATE priv; glocal MAIL_MESSAGES sorted; glocal FRAMEWORK_INFO *info = &info; glocal _F_FRAMEWORK *fram = fram; glocal int lastmsg = 0; glocal int revision=-1; // revision of the message list to know // if we are out of sync (loadindex) glocal bool invert_fromto = invert_fromto; glocal.priv.folder = folder; c.priv = &glocal.priv; c.loadindex (folder,glocal.priv.tb,glocal.revision); glocal.priv.tb.incrusage(); folder->incrusage(); glocal.sorted.neverdelete(); (title,"",help_nil); sortable(); if (glocal.priv.folder->is_postponed()){ newf_head (MSG_U(H_FOLDERPOST,"No.\tTo\tSubject\tDate\tSize")); sethdispo ("rlllr"); }else if (glocal.invert_fromto){ newf_head (MSG_U(H_FOLDERTO,"No.\tStatus\tTo\tSubject\tDate\tSize\tFrom\tProject\tType\tRemind")); sethdispo ("rllllr"); }else{ newf_head (MSG_U(H_FOLDER,"No.\tStatus\tFrom\tSubject\tDate\tSize\tTo\tProject\tType\tRemind")); sethdispo ("rllllr"); } PRIVATE_MESSAGES upds; upds.neverdelete(); glocal.priv.folder->getupdmsgs(upds); for (int i=0; igetmsgs(msgs); for (int i=0; imsgs.ending); waitfor (glocal.info->msgs.mayend); waitfor (glocal.info->docmsgs.focus); waitfor (glocal.info->docmsgs.taskbar); waitfor (glocal.info->docmsgs.menubar); waitfor (glocal.priv.folder->jump2prec); waitfor (glocal.priv.folder->jump2next); int nb = glocal.priv.tb.getnb(); if (nb > 0) setcursor (nb-1); nobutton(); const char *fbold = guiid_setfont (10,GFONT_ID_DEFAULT,GFONT_STYLE_DEFAULT,GFONT_WEIGHT_BOLD,false); const char *dcb = guiid_setdc (fbold,NULL,NULL); const char *dc = guiid_setdc (NULL,NULL,NULL); bool post = glocal.priv.folder->is_postponed(); glocal.sorted.remove_all(); folder_copymsg (glocal.priv.tb,glocal.sorted); if (order != SORT_NONE){ if (column != 0){ // The first column is the message number static int (*tbfct_from[])(const ARRAY_OBJ*,const ARRAY_OBJ*)={ cmp_status, cmp_from, cmp_subject, cmp_date, cmp_size, cmp_to, cmp_project, cmp_type, cmp_remind }; static int (*tbfct_to[])(const ARRAY_OBJ*,const ARRAY_OBJ*)={ cmp_status, cmp_to, cmp_subject, cmp_date, cmp_size, cmp_from, cmp_project, cmp_type, cmp_remind }; glocal.sorted.sort (glocal.invert_fromto ? tbfct_to[column-1] : tbfct_from[column-1]); } if (order == SORT_DESC){ glocal.sorted.invert(); } } for (int i=0; igetflag(K_MSGTYPE); const char *mproject = m->getflag(K_PROJECT); const char *remind = m->getflag(K_REMIND); if (!post){ if (m->replied) strcat (status,MSG_U(I_LETTER_REPLIED,"A")); if (m->comment.is_filled()) strcat (status,MSG_U(I_LETTER_COMMENT,"C")); if (m->deleted) strcat (status,MSG_U(I_LETTER_DELETED,"D")); if (!m->viewed) strcat (status,MSG_U(I_LETTER_NEW,"N")); if (remind[0] != '\0'){ strcat (status,MSG_U(I_LETTER_REMIND,"R")); } if (mtype[0] != '\0' || mproject[0] != '\0'){ strcat (status,MSG_U(I_LETTER_CLASSIFIED,"Q")); } if (m->tagged) strcat (status,MSG_U(I_LETTER_TAGGED,"T")); } char num[10]; sprintf (num,"%d",i+1); if (glocal.lastmsg == i){ setnextdcs (dcb); }else{ SSTRING dcs(dc); glocal.c->present (i,*m,dcs); setnextdcs (dcs.get()); } SSTRING fromm,subjectm,tom; mime_translate (m->getauthor(),fromm); mime_translate (m->subject,subjectm); mime_translate (m->getdest(),tom); char datestr[20]; m->formatdate (datestr,true); char sizestr[10]; if (m->size < 100000){ sprintf (sizestr,"%d",m->size); }else{ sprintf (sizestr,"%dK",(m->size+512)/1024); } if (post){ new_menuitemf (num,"%-20.20s\t%-40.40s\t%s\t%s" ,tom.get(),subjectm.get(),datestr,sizestr); }else if (glocal.invert_fromto){ new_menuitemf (num,"%s\t%-20.20s\t%-40.40s\t%s\t%s\t%-20.20s\t%s\t%s\t%s" ,status,tom.get(),subjectm.get(),datestr,sizestr,fromm.get() ,mproject,mtype,remind); }else{ new_menuitemf (num,"%s\t%-20.20s\t%-40.40s\t%s\t%s\t%-20.20s\t%s\t%s\t%s" ,status,fromm.get(),subjectm.get(),datestr,sizestr,tom.get() ,mproject,mtype,remind); } } glocal.lastmsg = no; message(); glocal.priv.msg = glocal.sorted.getitem(no); int real_no = no; for (int i=0; ipopup (real_no,*glocal.priv.msg,glocal.priv.folder,uistate); }else if (uistate.middleb){ glocal.c->msg_delete(real_no); }else{ glocal.priv.no = real_no; uithread (f_showmsg,glocal.c); } update_stats(glocal.c,glocal.priv.tb,glocal.lastmsg); #if 0 // All message trigger a refresh of the interface glocal.priv.tb.decrusage(); glocal.c->loadindex (glocal.priv.folder,glocal.priv.tb,glocal.revision); glocal.priv.tb.incrusage(); #endif if (dialog_testmessage(glocal.info->msgs.mayend)){ glocal.fram->endok(); }else if (dialog_testmessage(glocal.info->msgs.ending)){ endedit(); }else if (dialog_testmessage(glocal.info->docmsgs.focus)){ UISTATE state; diajava_lastmousestate (state); if (state.middleb){ endedit(); }else if (state.rightb){ bool end = false; glocal.c->docpopup(glocal.priv.folder,state,end); if (end) endedit(); } }else if (dialog_testmessage(glocal.priv.folder->jump2prec)){ if (glocal.lastmsg == 0){ xconf_error (MSG_U(E_STARTFOLDER,"Already at the top of folder")); }else{ glocal.lastmsg--; glocal.priv.msg = glocal.sorted.getitem(glocal.lastmsg); glocal.priv.no = glocal.lastmsg; uithread (f_showmsg,glocal.c); } }else if (dialog_testmessage(glocal.priv.folder->jump2next)){ if (glocal.lastmsg >= glocal.sorted.getnb()-1){ xconf_error (MSG_U(E_ENDFOLDER,"Already at the end of folder")); }else{ glocal.lastmsg++; glocal.priv.msg = glocal.sorted.getitem(glocal.lastmsg); glocal.priv.no = glocal.lastmsg; uithread (f_showmsg,glocal.c); } }else{ bool end = false; MAIL_MESSAGE *msg = glocal.sorted.getitem(glocal.lastmsg); glocal.c->message(end,glocal.priv.folder,*msg); if (end) endedit(); } // Maybe we must refresh our view again. Not sure if the // first one at the top is needed. glocal.priv.tb.decrusage(); glocal.c->loadindex (glocal.priv.folder,glocal.priv.tb,glocal.revision); glocal.priv.tb.incrusage(); update_stats(glocal.c,glocal.priv.tb,glocal.lastmsg); if (state.leftb){ selectsort(head); }else if (state.rightb){ glocal.c->clickhead (head,glocal.priv.folder); } glocal.c->notice (MSG_R(N_SYNCING)); folder->update(false); glocal.c->notice (MSG_R(N_SYNCINGDONE)); folder->decrusage(); glocal.priv.tb.decrusage(); folders_free(); } /* Select a folder in the standard mail directory */ int folder_pick (SSTRING &path) { SSTRINGS tb; SSTRING path; int len; SSTRING footer; SSTRING mail; folder_getmaildir (mail); glocal.len = mail.getlen()+1; // strip HOME/mail (mail.get()); glocal.tb.add (new SSTRING(path+glocal.len)); return true; folders_list (glocal.tb); glocal.tb.sort(); glocal.tb.insert (0,new SSTRING(MSG_U(I_INBOX,"INBOX"))); (MSG_U(T_FOLDERLIST,"Folder list") ,"",help_nil); newf_clist(); newline(); newf_str (NULL,glocal.footer); setbutinfo (MENU_USR1,MSG_U(B_ACCEPT,"Accept"),MSG_R(B_ACCEPT)); if (glocal.footer.is_empty()){ xconf_error (MSG_U(E_NOFOLDERSPEC,"No folder specified")); }else{ glocal.path = glocal.footer; endedit(); } newf_head (MSG_U(H_FOLDERFILE,"Folder files")); //setcursor (glocal.tb.getnb()-1); settype (DIATYPE_POPUP); for (int i=0; iget(),""); } glocal.path.setfrom (glocal.tb.getitem(no)->get()); path.setfrom (glocal.path); return path.is_empty() ? -1 : 0; }