#include #include #include #include #include "framework.h" #include "tlmpmail.h" #include "tlmpmail.m" #include #include static HELP_FILE help_attach ("tlmpmail","viewattach"); using namespace std; struct MAIL_VIEW_PRIVATE{ FOLDER_VIEW *newfolder; MAIL_MESSAGE *newmsg; bool active; bool replace; PRIVATE_MESSAGE wakeup_replace; // Wakeup the thread having the focus // and replace its message PRIVATE_MESSAGE wakeup; // Wakeup and display a new document _F_MAIL_VIEW *c; }; void _F_MAIL_VIEW::reply (EMAILADDRS &, MAIL_MESSAGE &) { xconf_notice ("Reply functionality not implemented"); } void _F_MAIL_VIEW::newmsg (EMAILADDRS &) { xconf_notice ("Newmsg functionality not implemented"); } void _F_MAIL_VIEW::reply_pick (MAIL_MESSAGE &) { xconf_notice ("Reply/pick functionality not implemented"); } void _F_MAIL_VIEW::forward (MAIL_MESSAGE &) { xconf_notice ("Forward functionality not implemented"); } /* Insert new fields and button in the composition dialog Return the MENUBUT_xxx mask of the added buttons. */ void * _F_MAIL_VIEW::codialog_setup (DIALOG &, int &, MAIL_MESSAGE_FULL &) { return NULL; } /* Process the buttons and the messages added by codialog */ void _F_MAIL_VIEW::codialog_buttons ( void *, DIALOG &, MENU_STATUS, MAIL_MESSAGE &, MAIL_MESSAGE_FULL &) { } /* Tell the codialog to clean up */ void _F_MAIL_VIEW::codialog_end (void *) { } /* Validate the extra fields entered by codialog Return -1 if any error, set the field number to point on the offending field. */ int _F_MAIL_VIEW::codialog_validate ( void *, DIALOG &, int &, MAIL_MESSAGE &, MAIL_MESSAGE_FULL &) { return 0; } PUBLIC MAIL_VIEW::MAIL_VIEW(_F_MAIL_VIEW &_c) : c(_c) { priv = new MAIL_VIEW_PRIVATE; priv->active = false; priv->newmsg = NULL; priv->c = &c; } static void view_addrs ( EMAILADDRS &addrs, const char *list, _F_MAIL_VIEW *c, MAIL_MESSAGE &msg) { if (addrs.size() == 0){ xconf_notice (MSG_U(N_NOADDRS,"%s list is empty"),list); }else{ glocal _F_MAIL_VIEW *c = c; glocal MAIL_MESSAGE *msg = &msg; glocal EMAILADDRS *addrs = &addrs; glocal set selected; SSTRING title; title.setfromf (MSG_U(T_ADDRESSES,"%s address list"),list); (title.get() ,MSG_U(I_ADDRESSES ,"Click with the left mouse button to reply.\n" "Click with the middle mouse button to compose a new message.\n" "Shift/click to select/unselect an address") ,help_nil); newf_head (MSG_U(H_ADDRESS,"Name\tAddress")); settype (DIATYPE_POPUP); sortable(); sortpolicy ("aa"); setbutinfo (MENU_USR1,MSG_R(B_REPLY),""); setbutinfo (MENU_USR2,MSG_U(B_NEWMSG,"New msg"),""); setbutinfo (MENU_USR3,MSG_R(B_ALL),""); setbutinfo (MENU_USR4,MSG_U(B_NONE,"None"),""); for (int i=0; isize(); i++){ SSTRING name,addr; glocal.addrs->get (i,name,addr); mime_translate (name); mime_translate (addr); if (glocal.selected.count(i)>0) setnexttagged(); new_menuitemf (name.get(),"%s",addr.get()); } if (uistate.shiftkey){ if (glocal.selected.count(no)>0){ glocal.selected.erase(no); }else{ glocal.selected.insert (no); } }else{ EMAILADDRS tmp; glocal.addrs->copy (no,tmp); if (uistate.leftb){ glocal.c->reply (tmp,*glocal.msg); }else if (uistate.middleb){ glocal.c->newmsg (tmp); } } if (code == MENU_USR3){ glocal.selected.clear(); for (int i=0; isize(); i++){ glocal.selected.insert (i); } }else if (code == MENU_USR4){ glocal.selected.clear(); }else if (glocal.selected.size()==0){ xconf_error (MSG_U(E_NOTHINGSEL,"No recipient selected")); }else{ EMAILADDRS tmp; for (set::iterator it = glocal.selected.begin(); it != glocal.selected.end(); it++){ glocal.addrs->copy (*it,tmp); } if (code == MENU_USR1){ glocal.c->reply (tmp,*glocal.msg); }else if (code == MENU_USR2){ glocal.c->newmsg (tmp); } } } } PUBLIC void MAIL_VIEW::manage() { glocal MAIL_VIEW_PRIVATE *priv = priv; if (!priv->active){ priv->active = true; (MSG_U(T_MSGVIEWER,"Message viewer"),priv->wakeup); newdocument(); glocal MAIL_MESSAGE *msg = glocal.priv->newmsg; glocal MAIL_MESSAGE_FULL full; glocal DIALOG dia; glocal SSTRING first; glocal int nbattach; glocal SSTRING nbattachstr; glocal SSTRING boundary; glocal SSTRING from,to,cc; glocal SSTRING datestr; glocal.dia.waitfor (glocal.priv->wakeup_replace); info.msgs.waitfor (glocal.dia); FOLDER_VIEW *folder = glocal.priv->newfolder; glocal.msg->incrusage(); glocal.msg->set_viewed (true); // Subroutine to scan a mail and program the attachement field // It also prepares some field. (); glocal.msg->loadmsg (glocal.full); glocal.full.from.format (glocal.from); mime_translate (glocal.from); glocal.from.truncate (65); glocal.full.to.format (glocal.to); mime_translate (glocal.to); glocal.to.truncate (65); glocal.full.cc.format (glocal.cc); mime_translate (glocal.cc); glocal.cc.truncate (65); mime_translate (glocal.full.subject); char datestr[20]; glocal.msg->formatdate (datestr,false); glocal.datestr.setfrom (datestr); glocal.nbattach = 0; (glocal.full,true,true); glocal.first.setfrom (info.body); glocal.nbattach++; #if 0 SSTRING tmp; tmp.setfromf ("%s %s %s %s",type,encoding,description,disposition); tmp.strip_end(); glocal.dia.newf_info ("part",tmp.get()); glocal.dia.newline(); #endif glocal.nbattachstr.setfromf ("%d",glocal.nbattach); sub.exec(); glocal.dia.gui_group (""); glocal.dia.newf_str (MSG_U(F_FROM,"From"),glocal.from,65); glocal.dia.set_lastreadonly(); glocal.dia.newline(); glocal.dia.newf_str (MSG_R(F_TO),glocal.to,65); glocal.dia.set_lastreadonly(); PRIVATE_MESSAGE to_message,cc_message; glocal.dia.set_helpdia (to_message); glocal.dia.newline(); glocal.dia.newf_str (MSG_R(F_CC),glocal.cc,65); glocal.dia.set_lastreadonly(); glocal.dia.set_helpdia (cc_message); glocal.dia.newline(); glocal.dia.newf_str (MSG_R(F_SUBJECT),glocal.full.subject,65); glocal.dia.set_lastreadonly(); glocal.dia.newline(); glocal.dia.newf_str (MSG_U(F_DATE,"Date"),glocal.datestr); glocal.dia.set_lastreadonly(); glocal.dia.newline(); glocal.dia.newf_str (MSG_U(F_NBATTACH,"Attachments"),glocal.nbattachstr); glocal.dia.set_lastreadonly(); glocal.dia.gui_end(); glocal.dia.newline(); glocal.dia.gui_form (); PRIVATE_MESSAGE details; glocal.dia.new_button (MSG_U(B_DETAILS,"Details"),"",details); PRIVATE_MESSAGE attach_message; glocal.dia.new_button (MSG_U(B_ATTACH,"Attachments"),"",attach_message); int butmask = 0; void *codata = glocal.priv->c->codialog_setup (glocal.dia,butmask,glocal.full); glocal.dia.gui_end(); glocal.dia.newline(); int nof = glocal.dia.getnb(); glocal.dia.newf_textarea (NULL,glocal.first,80,20); glocal.dia.setbutinfo (MENU_USR1,MSG_U(B_REPLY,"Reply"),MSG_R(B_REPLY)); glocal.dia.setbutinfo (MENU_USR2,MSG_U(B_REPLY_PICK,"Reply/Pick"),MSG_R(B_REPLY_PICK)); glocal.dia.setbutinfo (MENU_USR3,MSG_U(B_FORWARD,"Forward"),MSG_R(B_FORWARD)); glocal.dia.setbutinfo (MENU_USR4,MSG_U(B_PREC,"Prec"),MSG_R(B_PREC)); glocal.dia.setbutinfo (MENU_USR5,MSG_U(B_NEXT,"Next"),MSG_R(B_NEXT)); while(1){ MENU_STATUS code = glocal.dia.edit (glocal.msg->get_from(),"" ,help_nil,nof ,MENUBUT_CANCEL |MENUBUT_USR1|MENUBUT_USR2|MENUBUT_USR3|MENUBUT_USR4 |MENUBUT_USR5 |butmask); if (code == MENU_MESSAGE){ if (must_end (info.msgs)){ break; }else if (dialog_testmessage(details)){ xconf_notice ("%s",glocal.full.header.get()); }else if (dialog_testmessage(to_message)){ view_addrs (glocal.full.to,MSG_R(I_TO),glocal.priv->c,*glocal.msg); }else if (dialog_testmessage(cc_message)){ view_addrs (glocal.full.cc,MSG_R(I_CC),glocal.priv->c,*glocal.msg); }else if (dialog_testmessage(attach_message)){ if (glocal.nbattach == 0){ xconf_notice (MSG_U(N_NOATTACH,"No attachment with this message")); }else if (glocal.nbattach == 1){ mime_doattach (glocal.full); }else{ glocal DIALOG pop; glocal bool tbatt[1000]; glocal int no=0; glocal.tbatt[0] = false; (glocal.full,false,false); if (no > 0){ glocal.tbatt[no] = false; glocal.pop.newf_chk (info.description.get() ,glocal.tbatt[no],info.encoding.get()); } glocal.pop.settype (DIATYPE_POPUP); glocal.pop.setbutinfo (MENU_USR1,MSG_R(B_ALL),MSG_R(B_ALL)); glocal.pop.setbutinfo (MENU_USR2,MSG_R(B_NONE),MSG_R(B_NONE)); while (1){ MENU_STATUS code = glocal.pop.edit ("" ,"",help_attach,glocal.no ,MENUBUT_CANCEL|MENUBUT_ACCEPT |MENUBUT_USR1|MENUBUT_USR2); if (code == MENU_CANCEL || code == MENU_ESCAPE){ break; }else if (code == MENU_ACCEPT){ mime_doattach (glocal.full,glocal.tbatt,glocal.nbattach); break; }else if (code == MENU_USR1 || code == MENU_USR2){ memset (glocal.tbatt,code == MENU_USR1,sizeof(glocal.tbatt)); glocal.pop.reload(); } } } }else if (dialog_testmessage(glocal.priv->wakeup_replace)){ if (info.has_focus){ glocal.msg->decrusage(); folder->decrusage(); folders_free(); glocal.msg = glocal.priv->newmsg; folder = glocal.priv->newfolder; glocal.msg->incrusage(); folder->incrusage(); sub.exec(); glocal.dia.reload(); } }else{ glocal.priv->c->codialog_buttons (codata,glocal.dia,code,*glocal.msg,glocal.full); } }else if (code == MENU_USR1){ EMAILADDRS *addrs = &glocal.msg->reply; if (addrs->size()==0) addrs = &glocal.msg->from; glocal.priv->c->reply (*addrs,*glocal.msg); }else if (code == MENU_USR2){ glocal.priv->c->reply_pick (*glocal.msg); }else if (code == MENU_USR3){ glocal.priv->c->forward (*glocal.msg); }else if (code == MENU_USR4){ dialog_sendmessage (folder->jump2prec); }else if (code == MENU_USR5){ dialog_sendmessage (folder->jump2next); }else if (code == MENU_CANCEL || code == MENU_ESCAPE){ break; }else{ glocal.dia.save(); glocal.priv->c->codialog_buttons (codata,glocal.dia,code,*glocal.msg,glocal.full); } } glocal.priv->c->codialog_end (codata); glocal.msg->decrusage(); folders_free(); end = true; frame.newdocument(); frame.loop(); priv->active = false; }else if (priv->replace){ dialog_sendmessage (priv->wakeup_replace); }else{ dialog_sendmessage (priv->wakeup); } } static void f_mail_view(void *p) { MAIL_VIEW *v = (MAIL_VIEW*)p; v->manage(); } PUBLIC void MAIL_VIEW::view( FOLDER_VIEW *folder, MAIL_MESSAGE &msg, // Display a message bool replace) // Replace the first message displayed // by the framework { priv->newfolder = folder; priv->newmsg = &msg; priv->replace = replace; uithread (f_mail_view,this); }