From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from qmta07.westchester.pa.mail.comcast.net (qmta07.westchester.pa.mail.comcast.net [76.96.62.64]) by che.dreamhost.com (Postfix) with ESMTP id 97F3EFE98 for ; Tue, 5 Apr 2011 06:31:17 -0700 (PDT) Received: from omta15.westchester.pa.mail.comcast.net ([76.96.62.87]) by qmta07.westchester.pa.mail.comcast.net with comcast id Tnff1g0041swQuc57pGE5o; Tue, 05 Apr 2011 13:16:14 +0000 Received: from eklbox.hsd1.mi.comcast.net. ([71.238.29.179]) by omta15.westchester.pa.mail.comcast.net with comcast id TpGD1g0233rsRL73bpGEl6; Tue, 05 Apr 2011 13:16:14 +0000 From: Karl Dahlke To: edbrowse-dev@lists.the-brannons.com Date: Tue, 5 Apr 2011 09:16:13 -0400 Message-Id: <1302009373-8163-1-git-send-email-eklhad@comcast.net> X-Mailer: git-send-email 1.7.4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Edbrowse-dev] =?utf-8?q?=5BPATCH=5D_The_-f_option?= 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: Tue, 05 Apr 2011 13:31:18 -0000 edbrowse -f3 fetches mail from account 3, but does not read it. Filters are still in play. If not redirected by a filter, mail is saved unformatted in mbox/unread/ 1 2 3 4 5 etc. Clear these out once in a while, so we can go back to 1. Eventually another edbrowse command will read through these emails interactively and dispose of them, as though they were coming from the server, using the same interface we have today; but that command has not yet been written. --- src/eb.p | 2 +- src/fetchmail.c | 82 ++++++++++++++++++++++++++++++++++++++++++++----------- src/main.c | 13 +++++++-- src/messages.c | 6 ++-- 4 files changed, 80 insertions(+), 23 deletions(-) diff --git a/src/eb.p b/src/eb.p index d04093c..c23794a 100644 --- a/src/eb.p +++ b/src/eb.p @@ -109,7 +109,7 @@ bool sendMailCurrent(int sm_account, bool dosig) ; /* sourcefile=fetchmail.c */ void loadBlacklist(void) ; bool onBlacklist1(IP32bit tip) ; -void fetchMail(int account) ; +void fetchMail(int account, bool fetch) ; bool emailTest(void) ; void unpackUploadedFile(const char *post, const char *boundary, char **postb, int *postb_l) ; char * emailParse(char *buf) ; diff --git a/src/fetchmail.c b/src/fetchmail.c index fe3ef0d..9c1ea14 100644 --- a/src/fetchmail.c +++ b/src/fetchmail.c @@ -271,14 +271,35 @@ writeAttachments(struct MHINFO *w) } } /* writeAttachments */ +/* find the last mail in the unread directory */ +static int unreadNumber; +static void +lastUnread(void) +{ + const char *f; + int n; + + unreadNumber = 0; + + while(f = nextScanFile(mailUnread)) { + if(!stringIsNum(f)) + continue; + n = atoi(f); + if(n > unreadNumber) + unreadNumber = n; + } +} /* lastUnread */ + void -fetchMail(int account) +fetchMail(int account, bool fetch) { const struct MACCOUNT *a = accounts + account - 1; const char *login = a->login; const char *pass = a->password; const char *host = a->inurl; int nmsgs, m, j, k; + char *umf; /* unread mail file */ + char *umf_end; if(!isInteractive) i_printfExit(MSG_FetchNotBackgnd); @@ -295,26 +316,32 @@ fetchMail(int account) showErrorAbort(); if(!mailGetLine()) showErrorAbort(); - if(memcmp(serverLine, "+OK ", 4)) - i_printfExit(MSG_BadPopIntro, serverLine); + if(memcmp(serverLine, "+OK ", 4)) { + i_printf(MSG_BadPopIntro, serverLine); + return; + } sprintf(serverLine, "user %s%s", login, eol); mailPutGetError(serverLine); if(pass) { /* I think this is always required */ sprintf(serverLine, "pass %s%s", pass, eol); mailPutGetError(serverLine); } /* password */ - if(memcmp(serverLine, "+OK", 3)) - i_printfExit(MSG_PopNotComplete, serverLine); + if(memcmp(serverLine, "+OK", 3)) { + i_printf(MSG_PopNotComplete, serverLine); + return; + } /* How many mail messages? */ mailPutGetError("stat\r\n"); - if(memcmp(serverLine, "+OK ", 4)) - i_printfExit(MSG_NoStatusMailBox, serverLine); + if(memcmp(serverLine, "+OK ", 4)) { + i_printf(MSG_NoStatusMailBox, serverLine); + return; + } nmsgs = atoi(serverLine + 4); if(!nmsgs) { i_puts(MSG_NoMail); mailClose(); - exit(0); + return; } if(!passMail) { @@ -323,6 +350,12 @@ fetchMail(int account) /* the conect will drop when the program exits */ } + if(fetch) { + umf = allocMem(strlen(mailUnread) + 8); + sprintf(umf, "%s/", mailUnread); + umf_end = umf + strlen(umf); + lastUnread(); + } i_printf(MSG_MessagesX, nmsgs); for(m = 1; m <= nmsgs; ++m) { @@ -338,21 +371,25 @@ fetchMail(int account) int stashNumber = -1; 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); + /* Now grab the entire message */ sprintf(serverLine, "retr %d%s", m, eol); if(!mailPutLine(serverLine, false)) @@ -364,14 +401,18 @@ fetchMail(int account) nr = ssl_read(retrbuf, sizeof (retrbuf)); else nr = tcp_read(mssock, retrbuf, sizeof (retrbuf)); - if(nr <= 0) - i_printfExit(MSG_ErrorReadMess, errno); + if(nr <= 0) { + i_printf(MSG_ErrorReadMess, errno); + return; + } if(retr1) { -/* add null, to make it easy to print the error message, if necessary */ +/* 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); + if(memcmp(retrbuf, "+OK", 3)) { + i_printf(MSG_ErrorFetchMess, m, retrbuf); + return; + } j = 3; while(retrbuf[j] != '\n') ++j; @@ -462,8 +503,10 @@ fetchMail(int account) i_puts(MSG_Empty); } } - if(redirect) + + if(redirect || fetch) delflag = true; + key = 0; /* display the next page of mail and get a command from the keyboard */ displine = 1; @@ -549,11 +592,16 @@ fetchMail(int account) } /* switch */ } - /* delflag or not */ /* At this point we're saving the mail somewhere. */ if(key != 'k') delflag = true; atname = redirect; + if(!atname && fetch) { + sprintf(umf_end, "%d", unreadNumber + m); + atname = umf; + key = 'u'; /* save unformatted */ + } + savemail: if(!atname) atname = getFileName(0, false); @@ -645,7 +693,9 @@ fetchMail(int account) if(nattach) writeAttachments(lastMailInfo); } /* unformat or format */ - if(atname != spamCan) { + +/* print "mail saved" message */ + if(atname != spamCan && atname != umf) { i_printf(MSG_MailSaved, fsize); if(exists) i_printf(MSG_Appended); diff --git a/src/main.c b/src/main.c index 43d46b5..dc22e13 100644 --- a/src/main.c +++ b/src/main.c @@ -991,6 +991,7 @@ main(int argc, char **argv) { int cx, account; bool rc, doConfig = true; + bool fetchOnly = false; /* In case this is being piped over to a synthesizer, or whatever. */ if(fileTypeByHandle(fileno(stdout)) != 'f') @@ -1099,7 +1100,9 @@ main(int argc, char **argv) ++s, unformatMail = true; if(*s == 'p') ++s, passMail = true; - if(*s == 'm' && isdigitByte(s[1])) { + if((*s == 'm' || *s == 'f') && isdigitByte(s[1])) { + if(*s == 'f') + fetchOnly = true; if(!maxAccount) i_printfExit(MSG_NoMailAcc); account = strtol(s + 1, &s, 10); @@ -1137,8 +1140,12 @@ main(int argc, char **argv) char **reclist, **atlist; char *s, *body; int nat, nalt, nrec; - if(!argc) - fetchMail(account); + + if(!argc) { + fetchMail(account, fetchOnly); + exit(0); + } + if(argc == 1) i_printfExit(MSG_MinOneRec); /* I don't know that argv[argc] is 0, or that I can set it to 0, diff --git a/src/messages.c b/src/messages.c index b419b76..20b4089 100644 --- a/src/messages.c +++ b/src/messages.c @@ -571,7 +571,7 @@ static const char *englishMessages[] = { "%s is not a directory", "no mail accounts specified, please check your .ebrc config file", "invalid account number, please use 1 through %d", - "edbrowse -v (show version)\nedbrowse -h (this message)\nedbrowse -c (edit config file)\nedbrowse [-e] [-d?] -[u|p]m? (read your mail) \nedbrowse [-e] [-d?] -m? address1 address2 ... file [+attachments]\nedbrowse [-e] [-d?] file1 file2 ...", + "edbrowse -v (show version)\nedbrowse -h (this message)\nedbrowse -c (edit config file)\nedbrowse [-e] [-d#] -[u|p]m# (read your mail)\nedbrowse [-e] [-d#] -f# (fetch mail) \nedbrowse [-e] [-d#] -m# address1 address2 ... file [+attachments]\nedbrowse [-e] [-d#] file1 file2 ...", "please specify at least one recipient and the file to send", "please specify at least one recipient and the file to send, before your attachments", "too many files open simultaneously, limit %d", @@ -1230,7 +1230,7 @@ static const char *frenchMessages[] = { "%s n'est pas un répertoire", "Pas de comptes de courrier définis, vérifiez votre fichier .ebrc", "Numéro de compte de courrier invalide, utilisez svp de 1 à %d", - "edbrowse -v (montre version)\nedbrowse -h (ce message)\nedbrowse -c (edit fichier config)\nedbrowse [-e] [-d?] -[u|p]m? (lecture courrier \nedbrowse [-e] [-d?] -m? adresse1 adresse2 ... fichier [+pièces jointes]\nedbrowse [-e] [-d?] fichier1 fichier2 ...", + "edbrowse -v (montre version)\nedbrowse -h (ce message)\nedbrowse -c (edit fichier config)\nedbrowse [-e] [-d#] -[u|p]m# (lecture courrier \nedbrowse [-e] [-d#] -m# adresse1 adresse2 ... fichier [+pièces jointes]\nedbrowse [-e] [-d#] fichier1 fichier2 ...", "Définissez s'il vous plaît au moins un destinataire et le fichier à envoyer", "Définissez s'il vous plaît au moins un destinataire et le fichier à envoyer, avant vos pièces jointes", "Trop de fichiers ouverts, la limite est de %d", @@ -1889,7 +1889,7 @@ static const char *brazilianPortugueseMessages[] = { "%s não é um diretório", "nenhuma conta de e-mail especificada; confira por favor o arquivo de configuração .ebrc", "número de conta inválido; por favor use 1 até %d", - "edbrowse -v (mostra versão)\nedbrowse -h (esta mensagem)\nedbrowse -c (edita arquivo de configuração)\nedbrowse [-e] [-d?] -[u|p]m? (lê e-mail) \nedbrowse [-e] [-d?] -m? endereco1 endereco2 ... arquivo [+anexos]\nedbrowse [-e] [-d?] arquivo1 arquivo2 ...", + "edbrowse -v (mostra versão)\nedbrowse -h (esta mensagem)\nedbrowse -c (edita arquivo de configuração)\nedbrowse [-e] [-d#] -[u|p]m# (lê e-mail) \nedbrowse [-e] [-d#] -m# endereco1 endereco2 ... arquivo [+anexos]\nedbrowse [-e] [-d#] arquivo1 arquivo2 ...", "por favor especifique ao menos um destinatário e o arquivo a enviar", "por favor especifique ao menos um destinatário e o arquivo a enviar, antes dos anexos", "demais arquivos abertos ao mesmo tempo; o limite é %d", -- 1.7.4