#include #include #include #include "mailconf.h" #include "mailconf.m" #include "internal.h" #include #include #include #include #include #include static MAILCONF_HELP_FILE help_mailq("mailq"); class MAILQ_ENTRY: public ARRAY_OBJ{ public: char id[20]; int size; SSTRING date; SSTRING sender; SSTRING status; SSTRINGS dests; /*~PROTOBEG~ MAILQ_ENTRY */ public: MAILQ_ENTRY (const char *_id, int _size, const char *_date, const char *_sender); int edit (void); /*~PROTOEND~ MAILQ_ENTRY */ }; PUBLIC MAILQ_ENTRY::MAILQ_ENTRY( const char *_id, int _size, const char *_date, const char *_sender) { strncpy (id,_id,sizeof(id)-1); id[sizeof(id)-1] = '\0'; sender.setfrom (_sender); date.setfrom (_date); size = _size; } /* Delete all files related to one message ID */ static void mailq_delid (const char *id) { SSTRINGS tb; const char *mqueue = configf_lookuppath ("/var/spool/mqueue"); int n = dir_getlist (mqueue,tb); for (int i=0; iget(); if (strcmp(s+2,id)==0){ char path[PATH_MAX]; sprintf (path,"%s/%s",mqueue,s); unlink (path); } } } /* Present the entry and return 1 if it was deleted */ PUBLIC int MAILQ_ENTRY::edit() { int ret = 0; DIALOG dia; dia.newf_info (MSG_U(F_ID,"Message ID"),id); dia.newf_info (MSG_U(F_DATE,"Date sent"),date.get()); dia.newf_info (MSG_U(F_SENDER,"Sender"),sender.get()); dia.newf_num (MSG_U(F_SIZE,"Size"),size); dia.set_lastreadonly(); dia.newf_info (MSG_U(F_STATUS,"Status"),status.get()); for (int i=0; iget()); } int nof = 0; if (dia.edit (MSG_U(T_ONEMESSAGE,"One message status") ,MSG_U(I_ONEMESSAGE ,"This message is currently in sendmail queue.\n" "You can delete from the queue if you want.\n" "*** Are you really sure ? ***") ,help_mailq ,nof,MENUBUT_CANCEL|MENUBUT_DEL) == MENU_DEL){ if (perm_rootaccess(MSG_U(P_DELMESSAGE ,"to delete queued email messages"))){ ret = 1; net_introlog (NETINTRO_MISC); net_prtlog (NETLOG_VERB,MSG_U(N_DELMESSAGE ,"Deleting mail message %s: size %d from %s\n") ,id,size,sender.get()); net_prtlog (NETLOG_VERB,MSG_U(N_MESSAGESENT,"Sent on %s\n") ,date.get()); for (int i=0; iget()); } mailq_delid (id); } } return ret; } class MAILQ_ENTRIES: public ARRAY{ /*~PROTOBEG~ MAILQ_ENTRIES */ public: MAILQ_ENTRY *getitem (int no)const; /*~PROTOEND~ MAILQ_ENTRIES */ }; PUBLIC MAILQ_ENTRY *MAILQ_ENTRIES::getitem (int no) const { return (MAILQ_ENTRY*)ARRAY::getitem(no); } void mailq_edit() { MAILQ_ENTRIES entries; SSTRINGS tagged; bool noreload; glocal.noreload = false; (MSG_U(T_MAILQ,"Mail queue") ,MSG_U(I_MAILQ,"This is the list in the queue.\n" "You can review their status and erase them if need\n" "right click on message to tag/untag it") ,help_mailq); newf_head (MSG_U(H_MAILQ,"Id\tSender\tRecipients\tDate\tSize")); sortable(); sortpolicy ("aaan"); sethdispo ("llllr"); setbutinfo (MENU_USR1,MSG_U(B_DELTAGGED,"Delete tagged") ,MSG_R(B_DELTAGGED)); if (!glocal.noreload){ glocal.entries.remove_all(); MAILQ_ENTRY *last; bool seen_dash; glocal.last = NULL; glocal.seen_dash = false; ("mailq",10); if (line[0] == '-'){ glocal.seen_dash = true; }else if (line[0] > ' ' && glocal.seen_dash){ char id[20]; char *pt = str_copyword (id,line,sizeof(id)-1); { // Remove status char from the end if there int lastid = strlen(id) - 1; if (lastid > 0 && (id[lastid] == '-' || id[lastid] == '*')){ id[lastid] = '\0'; } } pt = str_skip(pt); int size = atoi(pt); // skip number and negative sign if there if (pt[0] == '-') pt++; pt = str_skipdig(pt); pt = str_skip(pt); char *date = pt; // Jump to the end and step back to the start // of the word char *sender = date + strlen(date); while (sender > date && sender[-1] > ' ') sender--; sender[-1] = '\0'; glocal.last = new MAILQ_ENTRY (id,size,date,sender); glocal.entries.add (glocal.last); }else if (glocal.last != NULL && (line[0] == ' ' || line[0] == '\t')){ char *pt = str_skip (line); if (pt[0] == '('){ // Remove the () pt++; pt[strlen(pt)-1] = '\0'; glocal.last->status.setfrom (pt); }else{ glocal.last->dests.add (new SSTRING(pt)); } } return 0; }else{ glocal.noreload = false; } for (int i=0; idests.getnb() > 0){ to.setfrom(ent->dests.getitem(0)->get()); if (ent->dests.getnb() > 1){ to.append (" ..."); } } if (glocal.tagged.lookup(ent->id)!=-1) setnexttagged(); new_menuitemf (ent->id,"%s\t%s\t%s\t%d" ,ent->sender.get(),to.get(),ent->date.get(),ent->size); } MAILQ_ENTRY *ent = glocal.entries.getitem(no); if (uistate.rightb){ const char *id = ent->id; int lk = glocal.tagged.lookup(id); if (lk != -1){ glocal.tagged.remove_del (lk); }else{ glocal.tagged.add (new SSTRING(id)); } glocal.noreload = true; }else{ ent->edit(); } if (code == MENU_USR1){ for (int i=0; iid); if (lk != -1){ mailq_delid (ent->id); glocal.tagged.remove_del (lk); } } } }