From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from qmta08.westchester.pa.mail.comcast.net (qmta08.westchester.pa.mail.comcast.net [76.96.62.80]) by che.dreamhost.com (Postfix) with ESMTP id 2E08CFE9A for ; Mon, 4 Apr 2011 07:13:46 -0700 (PDT) Received: from omta23.westchester.pa.mail.comcast.net ([76.96.62.74]) by qmta08.westchester.pa.mail.comcast.net with comcast id TRF71g0061c6gX858RynxW; Mon, 04 Apr 2011 13:58:47 +0000 Received: from eklbox.hsd1.mi.comcast.net. ([71.238.29.179]) by omta23.westchester.pa.mail.comcast.net with comcast id TRyl1g04Z3rsRL73jRym7F; Mon, 04 Apr 2011 13:58:46 +0000 From: Karl Dahlke To: edbrowse-dev@lists.the-brannons.com Date: Mon, 4 Apr 2011 09:58:45 -0400 Message-Id: <1301925525-6098-1-git-send-email-eklhad@comcast.net> X-Mailer: git-send-email 1.7.4 Subject: [Edbrowse-dev] [PATCH] Remove zapmail feature, which is dangerous, silly, and undocumented. X-BeenThere: edbrowse-dev@lists.the-brannons.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Edbrowse Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Apr 2011 14:13:46 -0000 This is a big patch only because I reindented afterwords, and a big chunk of code is no longer inside if not zapmail { } so all that shifted to the left. In reality I only changed a few lines of code. Sometimes I hate indenting. --- src/eb.h | 1 - src/fetchmail.c | 565 +++++++++++++++++++++++++++---------------------------- src/main.c | 4 +- 3 files changed, 276 insertions(+), 294 deletions(-) diff --git a/src/eb.h b/src/eb.h index 5b28cd5..2497d02 100644 --- a/src/eb.h +++ b/src/eb.h @@ -195,7 +195,6 @@ extern bool ismc; /* Is the program running as a mail client? */ extern bool cons_utf8; /* does the console expect utf8? */ extern bool iuConvert; /* perform iso utf8 conversions automatically */ extern char type8859; /* 1 through 15 */ -extern bool zapMail; /* just get rid of the mail */ extern bool js_redirects; /* window.location = new_url */ extern uchar browseLocal; /* browsing a local file */ extern bool parsePage; /* parsing the html page, and any java therein */ diff --git a/src/fetchmail.c b/src/fetchmail.c index b0f6561..fe3ef0d 100644 --- a/src/fetchmail.c +++ b/src/fetchmail.c @@ -280,10 +280,8 @@ fetchMail(int account) const char *host = a->inurl; int nmsgs, m, j, k; - if(!isInteractive) { - if(!zapMail) - i_printfExit(MSG_FetchNotBackgnd); - } + if(!isInteractive) + i_printfExit(MSG_FetchNotBackgnd); if(!mailDir) i_printfExit(MSG_NoMailDir); @@ -319,15 +317,13 @@ fetchMail(int account) exit(0); } - if(!(zapMail | passMail)) { + if(!passMail) { /* We look up a lot of hosts; make a tcp connect */ sethostent(1); /* the conect will drop when the program exits */ } i_printf(MSG_MessagesX, nmsgs); - if(zapMail && nmsgs > 300) - nmsgs = 300; for(m = 1; m <= nmsgs; ++m) { const char *redirect = 0; /* send mail elsewhere */ @@ -340,262 +336,255 @@ fetchMail(int account) char *exactf = 0; /* utf8 formatted */ int displine; int stashNumber = -1; - - if(zapMail) - delflag = true; - else { /* read the next message */ - char retrbuf[5000]; - bool retr1; + char retrbuf[5000]; + bool retr1; /* We need to clear out the editor, from the last message, * then read in this one, in its entirety. * This is probably a waste, since the user might delete a megabyte message * after seeing only the first paragraph, or even the subject, * but as for programming, it's easier to read the whole thing in right now. */ - if(lastMailInfo) - freeMailInfo(lastMailInfo); - lastMailInfo = 0; - nzFree(lastMailText); - lastMailText = 0; - if(sessionList[1].lw) - cxQuit(1, 2); - cs = 0; - linesReset(); - cxSwitch(1, false); + if(lastMailInfo) + freeMailInfo(lastMailInfo); + lastMailInfo = 0; + nzFree(lastMailText); + lastMailText = 0; + if(sessionList[1].lw) + cxQuit(1, 2); + cs = 0; + linesReset(); + cxSwitch(1, false); /* Now grab the entire message */ - sprintf(serverLine, "retr %d%s", m, eol); - if(!mailPutLine(serverLine, false)) - showErrorAbort(); - retr1 = true; - while(true) { - int nr; - if(a->inssl) - nr = ssl_read(retrbuf, sizeof (retrbuf)); - else - nr = tcp_read(mssock, retrbuf, sizeof (retrbuf)); - if(nr <= 0) - i_printfExit(MSG_ErrorReadMess, errno); - if(retr1) { + sprintf(serverLine, "retr %d%s", m, eol); + if(!mailPutLine(serverLine, false)) + showErrorAbort(); + retr1 = true; + while(true) { + int nr; + if(a->inssl) + nr = ssl_read(retrbuf, sizeof (retrbuf)); + else + nr = tcp_read(mssock, retrbuf, sizeof (retrbuf)); + if(nr <= 0) + i_printfExit(MSG_ErrorReadMess, errno); + if(retr1) { /* add null, to make it easy to print the error message, if necessary */ - if(nr < sizeof (retrbuf)) - retrbuf[nr] = 0; - if(memcmp(retrbuf, "+OK", 3)) - i_printfExit(MSG_ErrorFetchMess, m, retrbuf); - j = 3; - while(retrbuf[j] != '\n') - ++j; + if(nr < sizeof (retrbuf)) + retrbuf[nr] = 0; + if(memcmp(retrbuf, "+OK", 3)) + i_printfExit(MSG_ErrorFetchMess, m, retrbuf); + j = 3; + while(retrbuf[j] != '\n') ++j; - nr -= j; - memmove(retrbuf, retrbuf + j, nr); - retr1 = false; - } - if(nr) - stringAndBytes(&exact, &exact_l, retrbuf, nr); + ++j; + nr -= j; + memmove(retrbuf, retrbuf + j, nr); + retr1 = false; + } + if(nr) + stringAndBytes(&exact, &exact_l, retrbuf, nr); /* . by itself on a line ends the transmission */ - j = exact_l - 1; - if(j < 0) - continue; - if(exact[j] != '\n') - continue; + j = exact_l - 1; + if(j < 0) + continue; + if(exact[j] != '\n') + continue; + --j; + if(j >= 0 && exact[j] == '\r') --j; - if(j >= 0 && exact[j] == '\r') - --j; - if(j < 0) - continue; - if(exact[j] != '.') - continue; - if(!j) - break; - if(exact[j - 1] == '\n') - break; - } - exact_l = j; + if(j < 0) + continue; + if(exact[j] != '.') + continue; + if(!j) + break; + if(exact[j - 1] == '\n') + break; + } + exact_l = j; /* get rid of the dos returns, and dot strip */ - for(j = k = 0; j < exact_l; ++j) { - if(!j && exact[j] == '.') - continue; - if(j && exact[j] == '.' && exact[j - 1] == '\n') - continue; - if(exact[j] == '\r' && j < exact_l - 1 && exact[j + 1] == '\n') - continue; - exact[k++] = exact[j]; - } - exact_l = k; - exact[k] = 0; + for(j = k = 0; j < exact_l; ++j) { + if(!j && exact[j] == '.') + continue; + if(j && exact[j] == '.' && exact[j - 1] == '\n') + continue; + if(exact[j] == '\r' && j < exact_l - 1 && exact[j + 1] == '\n') + continue; + exact[k++] = exact[j]; + } + exact_l = k; + exact[k] = 0; - iuReformat(exact, exact_l, &exactf, &exactf_l); + iuReformat(exact, exact_l, &exactf, &exactf_l); - if(exactf) { - if(!addTextToBuffer((pst) exactf, exactf_l, 0, false)) - showErrorAbort(); - } else { - if(!addTextToBuffer((pst) exact, exact_l, 0, false)) - showErrorAbort(); - } + if(exactf) { + if(!addTextToBuffer((pst) exactf, exactf_l, 0, false)) + showErrorAbort(); + } else { + if(!addTextToBuffer((pst) exact, exact_l, 0, false)) + showErrorAbort(); + } - if(!unformatMail) { - browseCurrentBuffer(); - if(!passMail) { - mailIsBlack = onBlacklist(); - redirect = mailRedirect(lastMailInfo->to, - lastMailInfo->from, lastMailInfo->reply, - lastMailInfo->subject); - } - if(redirect) { - key = 'w'; - if(*redirect == '-') - ++redirect, key = 'u'; - if(stringEqual(redirect, "x")) - i_puts(MSG_Junk); - else - printf("> %s\n", redirect); - } else if((mailIsSpam | mailIsBlack) && spamCan) { - redirect = spamCan; - key = 'u'; - i_printf(MSG_Spam); - if(lastMailInfo->from[0]) { - i_printf(MSG_From); - printf("%s", lastMailInfo->from); - } else if(lastMailInfo->reply[0]) { - i_printf(MSG_From); - printf("%s", lastMailInfo->reply); - } - nl(); - } else if(!nattach && /* drop empty mail message */ - cw->dol - - (strlen(lastMailInfo->subject) != 0) - - (strlen(lastMailInfo->from) != 0) - - (strlen(lastMailInfo->reply) != 0) <= 1) { - redirect = "x"; - i_puts(MSG_Empty); + if(!unformatMail) { + browseCurrentBuffer(); + if(!passMail) { + mailIsBlack = onBlacklist(); + redirect = mailRedirect(lastMailInfo->to, + lastMailInfo->from, lastMailInfo->reply, + lastMailInfo->subject); + } + if(redirect) { + key = 'w'; + if(*redirect == '-') + ++redirect, key = 'u'; + if(stringEqual(redirect, "x")) + i_puts(MSG_Junk); + else + printf("> %s\n", redirect); + } else if((mailIsSpam | mailIsBlack) && spamCan) { + redirect = spamCan; + key = 'u'; + i_printf(MSG_Spam); + if(lastMailInfo->from[0]) { + i_printf(MSG_From); + printf("%s", lastMailInfo->from); + } else if(lastMailInfo->reply[0]) { + i_printf(MSG_From); + printf("%s", lastMailInfo->reply); } + nl(); + } else if(!nattach && /* drop empty mail message */ + cw->dol - + (strlen(lastMailInfo->subject) != 0) - + (strlen(lastMailInfo->from) != 0) - + (strlen(lastMailInfo->reply) != 0) <= 1) { + redirect = "x"; + i_puts(MSG_Empty); } - if(redirect) - delflag = true; + } + if(redirect) + delflag = true; /* display the next page of mail and get a command from the keyboard */ - displine = 1; - while(true) { - if(!delflag) { /* show next page */ - nextpage: - if(displine <= cw->dol) { - for(j = 0; j < 20 && displine <= cw->dol; - ++j, ++displine) { - char *showline = (char *)fetchLine(displine, 1); - k = pstLength((pst) showline); - showline[--k] = 0; - printf("%s\n", showline); - nzFree(showline); - } + displine = 1; + while(true) { + if(!delflag) { /* show next page */ + nextpage: + if(displine <= cw->dol) { + for(j = 0; j < 20 && displine <= cw->dol; ++j, ++displine) { + char *showline = (char *)fetchLine(displine, 1); + k = pstLength((pst) showline); + showline[--k] = 0; + printf("%s\n", showline); + nzFree(showline); } } + } /* get key command */ - while(true) { - if(!delflag) { + while(true) { + if(!delflag) { /* interactive prompt depends on whether there is more text or not */ - printf("%c ", displine > cw->dol ? '?' : '*'); - fflush(stdout); - key = getLetter("qx? nwkudijJ"); - printf("\b\b\b"); - fflush(stdout); - - switch (key) { - case 'q': - i_puts(MSG_Quit); - mailClose(); - case 'x': - exit(0); - case 'n': - i_puts(MSG_Next); - goto afterinput; - case 'd': - i_puts(MSG_Delete); - delflag = true; - goto afterinput; - case 'i': - i_puts(MSG_IPDelete); - if(!cw->iplist || cw->iplist[0] == -1) { - if(passMail) - i_puts(MSG_POption); - else - i_puts(ipbFile ? MSG_None : - MSG_NoBlackList); - } else { - IP32bit addr; - for(k = 0; (addr = cw->iplist[k]) != NULL_IP; - ++k) { - puts(tcp_ip_dots(addr)); - if(nipblack == MAXIPBLACK) - continue; - ipblacklist[nipblack] = addr; - ipblackmask[nipblack] = 0xffffffff; - ipblackcomp[nipblack] = false; - ++nipblack; - } + printf("%c ", displine > cw->dol ? '?' : '*'); + fflush(stdout); + key = getLetter("qx? nwkudijJ"); + printf("\b\b\b"); + fflush(stdout); + + switch (key) { + case 'q': + i_puts(MSG_Quit); + mailClose(); + case 'x': + exit(0); + case 'n': + i_puts(MSG_Next); + goto afterinput; + case 'd': + i_puts(MSG_Delete); + delflag = true; + goto afterinput; + case 'i': + i_puts(MSG_IPDelete); + if(!cw->iplist || cw->iplist[0] == -1) { + if(passMail) + i_puts(MSG_POption); + else + i_puts(ipbFile ? MSG_None : MSG_NoBlackList); + } else { + IP32bit addr; + for(k = 0; (addr = cw->iplist[k]) != NULL_IP; ++k) { + puts(tcp_ip_dots(addr)); + if(nipblack == MAXIPBLACK) + continue; + ipblacklist[nipblack] = addr; + ipblackmask[nipblack] = 0xffffffff; + ipblackcomp[nipblack] = false; + ++nipblack; } - delflag = true; - goto afterinput; - case 'j': - case 'J': - i_puts(MSG_Junk); - if(!junkSubject(lastMailInfo->subject, key)) - continue; - delflag = true; - goto afterinput; - case ' ': - if(displine > cw->dol) - i_puts(MSG_EndMessage); - goto nextpage; - case '?': - i_puts(MSG_MailHelp); - continue; - case 'k': - case 'w': - case 'u': - break; - default: - i_puts(MSG_NYI); + } + delflag = true; + goto afterinput; + case 'j': + case 'J': + i_puts(MSG_Junk); + if(!junkSubject(lastMailInfo->subject, key)) continue; - } /* switch */ - } - - /* delflag or not */ - /* At this point we're saving the mail somewhere. */ - if(key != 'k') delflag = true; - atname = redirect; - savemail: - if(!atname) - atname = getFileName(0, false); - if(!stringEqual(atname, "x")) { - char exists = fileTypeByName(atname, false); - int fsize; /* file size */ - int fh = - open(atname, O_WRONLY | O_TEXT | O_CREAT | O_APPEND, - 0666); - if(fh < 0) { - i_printf(MSG_NoCreate, atname); + goto afterinput; + case ' ': + if(displine > cw->dol) + i_puts(MSG_EndMessage); + goto nextpage; + case '?': + i_puts(MSG_MailHelp); + continue; + case 'k': + case 'w': + case 'u': + break; + default: + i_puts(MSG_NYI); + continue; + } /* switch */ + } + + /* delflag or not */ + /* At this point we're saving the mail somewhere. */ + if(key != 'k') + delflag = true; + atname = redirect; + savemail: + if(!atname) + atname = getFileName(0, false); + if(!stringEqual(atname, "x")) { + char exists = fileTypeByName(atname, false); + int fsize; /* file size */ + int fh = + open(atname, O_WRONLY | O_TEXT | O_CREAT | O_APPEND, + 0666); + if(fh < 0) { + i_printf(MSG_NoCreate, atname); + goto savemail; + } + if(exists) + write(fh, + "======================================================================\n", + 71); + if(key == 'u' || unformatMail) { + if(write(fh, exact, exact_l) < exact_l) { + badsave: + i_printf(MSG_NoWrite, atname); + close(fh); goto savemail; } - if(exists) - write(fh, - "======================================================================\n", - 71); - if(key == 'u' || unformatMail) { - if(write(fh, exact, exact_l) < exact_l) { - badsave: - i_printf(MSG_NoWrite, atname); - close(fh); - goto savemail; - } - close(fh); - fsize = exact_l; - } else { + close(fh); + fsize = exact_l; + } else { - if(mailStash) { - char *rmf; /* raw mail file */ - int rmfh; /* file handle to same */ + if(mailStash) { + char *rmf; /* raw mail file */ + int rmfh; /* file handle to same */ /* I want a fairly easy filename, in case I want to go look at the original. * Not a 30 character message ID that I am forced to cut&paste. * 4 or 5 digits would be nice. @@ -606,69 +595,67 @@ fetchMail(int account) * It's good to have a cron job empty the trash early Sunday morning. */ - k = strlen(mailStash); - rmf = allocMem(k + 12); + k = strlen(mailStash); + rmf = allocMem(k + 12); /* Try 20 times, then give up. */ - for(j = 0; j < 20; ++j) { - int rn = rand() % 100000; /* random number */ - sprintf(rmf, "%s/%05d.eml", mailStash, rn); - if(fileTypeByName(rmf, false)) - continue; + for(j = 0; j < 20; ++j) { + int rn = rand() % 100000; /* random number */ + sprintf(rmf, "%s/%05d.eml", mailStash, rn); + if(fileTypeByName(rmf, false)) + continue; /* dump the original mail into the file */ - rmfh = - open(rmf, - O_WRONLY | O_TEXT | O_CREAT | O_APPEND, - 0666); - if(rmfh < 0) - break; - if(write(rmfh, exact, exact_l) < exact_l) { - close(rmfh); - unlink(rmf); - break; - } + rmfh = + open(rmf, + O_WRONLY | O_TEXT | O_CREAT | O_APPEND, + 0666); + if(rmfh < 0) + break; + if(write(rmfh, exact, exact_l) < exact_l) { close(rmfh); -/* written successfully, remember the stash number */ - stashNumber = rn; + unlink(rmf); break; } + close(rmfh); +/* written successfully, remember the stash number */ + stashNumber = rn; + break; } - /* stashing the original */ - fsize = 0; - for(j = 1; j <= cw->dol; ++j) { - char *showline = (char *)fetchLine(j, 1); - int len = pstLength((pst) showline); - if(write(fh, showline, len) < len) - goto badsave; - nzFree(showline); - fsize += len; - } /* loop over lines */ - - if(stashNumber >= 0) { - char addstash[60]; - sprintf(addstash, "\nOriginal %05d\n", - stashNumber); - k = strlen(addstash); - if(write(fh, addstash, k) < k) - goto badsave; - fsize += k; - } - - close(fh); - if(nattach) - writeAttachments(lastMailInfo); - } /* unformat or format */ - if(atname != spamCan) { - i_printf(MSG_MailSaved, fsize); - if(exists) - i_printf(MSG_Appended); - nl(); } - } /* saving to a real file */ - goto afterinput; + /* stashing the original */ + fsize = 0; + for(j = 1; j <= cw->dol; ++j) { + char *showline = (char *)fetchLine(j, 1); + int len = pstLength((pst) showline); + if(write(fh, showline, len) < len) + goto badsave; + nzFree(showline); + fsize += len; + } /* loop over lines */ + + if(stashNumber >= 0) { + char addstash[60]; + sprintf(addstash, "\nOriginal %05d\n", stashNumber); + k = strlen(addstash); + if(write(fh, addstash, k) < k) + goto badsave; + fsize += k; + } + + close(fh); + if(nattach) + writeAttachments(lastMailInfo); + } /* unformat or format */ + if(atname != spamCan) { + i_printf(MSG_MailSaved, fsize); + if(exists) + i_printf(MSG_Appended); + nl(); + } + } /* saving to a real file */ + goto afterinput; - } /* key commands */ - } /* paging through the message */ - } /* interactive or zap */ + } /* key commands */ + } /* paging through the message */ afterinput: if(delflag) { @@ -688,8 +675,6 @@ fetchMail(int account) nzFree(exactf); } /* loop over mail messages */ - if(zapMail) - printf("%d\n", nmsgs); mailClose(); exit(0); } /* fetchMail */ diff --git a/src/main.c b/src/main.c index 40215ee..43d46b5 100644 --- a/src/main.c +++ b/src/main.c @@ -19,7 +19,7 @@ const char eol[] = "\r\n"; char EMPTYSTRING[] = ""; int debugLevel = 1; int webTimeout = 20, mailTimeout = 0; -bool ismc, browseLocal, zapMail, unformatMail, passMail, errorExit; +bool ismc, browseLocal, unformatMail, passMail, errorExit; bool isInteractive, inInput, listNA; volatile bool intFlag; int fileSize, maxFileSize = 50000000; @@ -1109,8 +1109,6 @@ main(int argc, char **argv) ismc = true; /* running as a mail client */ allowJS = false; /* no javascript in mail client */ ++argv, --argc; /* we're going to break out */ - if(argc && stringEqual(argv[0], "-Zap")) - ++argv, --argc, zapMail = true; break; } } -- 1.7.4