--- maildir.patch.orig 2021-12-26 09:30:07.154987000 +0000 +++ maildir.patch 2021-12-26 09:25:34.891181000 +0000 @@ -264,8 +264,8 @@ } diff -rc alpine-2.25/imap/src/osdep/unix/maildir.c alpine-2.25.maildir/imap/src/osdep/unix/maildir.c -*** alpine-2.25/imap/src/osdep/unix/maildir.c 2021-10-15 18:50:01.961799044 -0600 ---- alpine-2.25.maildir/imap/src/osdep/unix/maildir.c 2021-10-15 11:36:09.226819037 -0600 +*** alpine-2.25/imap/src/osdep/unix/maildir.c 2021-11-21 09:34:15.523895231 -0700 +--- alpine-2.25.maildir/imap/src/osdep/unix/maildir.c 2021-11-21 09:33:32.403623631 -0700 *************** *** 0 **** --- 1,2865 ---- @@ -273,7 +273,7 @@ + * Maildir driver for Alpine 2.25 + * + * Written by Eduardo Chappa -+ * Last Update: October 15, 2021. ++ * Last Update: October 16, 2021. + * + */ + @@ -918,26 +918,31 @@ + MM_CRITICAL(stream); + + maildir_scandir (LOCAL->path[New], &namesnew, &nfilesnew, &scan_err, CCLIENT); -+ if (scan_err < 0) ++ if (scan_err < 0){ ++ if(namesnew){ ++ for(i = 0L; i < nfilesnew; i++) ++ fs_give((void **)&namesnew[i]); ++ fs_give((void **) &namesnew); ++ } + maildir_abort(stream); ++ } + + /* Scan old messages first, escoba! */ -+ if(stream->rdonly || -+ (LOCAL && ((maildir_initial_check(stream, Cur) == 0) -+ || nfilesnew > 0L))){ ++ if(stream->rdonly ++ || (LOCAL && ((maildir_initial_check(stream, Cur) == 0) ++ || nfilesnew > 0L))){ + LOCAL->scantime = maildir_scandir (LOCAL->path[Cur], &namescur, &nfilescur, + &scan_err, CCLIENT); + if (scan_err < 0){ -+ if(namesnew){ -+ for(i = 0L; i < nfilesnew; i++) -+ fs_give((void **)&namesnew[i]); -+ fs_give((void **) &namesnew); ++ if(namescur){ ++ for(i = 0L; i < nfilescur; i++) ++ fs_give((void **)&namescur[i]); ++ fs_give((void **) &namescur); + } + maildir_abort(stream); + } + } -+ if(LOCAL && (maildir_initial_check(stream, New) == 0) -+ && (nfilescur > 0L)){ ++ if(LOCAL && (maildir_initial_check(stream, New) == 0) && (nfilescur > 0L)){ + while(LOCAL && loop < 10){ + if(nfilesnew == 0L) + maildir_scandir (LOCAL->path[New], &namesnew, &nfilesnew, &scan_err, CCLIENT); @@ -1240,6 +1245,7 @@ + } + + MSGPATH(tmp, LOCAL->dir, MDFILE(elt), MDLOC(elt)); ++ + if (LOCAL->fd < 0) /* if file closed ? */ + LOCAL->fd = open(tmp,O_RDONLY,NIL); + @@ -1267,13 +1273,10 @@ + LOCAL->buf[0] = '\0'; + + MSGPATH(tmp, LOCAL->dir, MDFILE(elt), MDLOC(elt)); -+ if (LOCAL->fd < 0) /* if file closed ? */ -+ LOCAL->fd = open(tmp,O_RDONLY,NIL); -+ -+ if (LOCAL->fd < 0) /* flag change? */ -+ return maildir_update_elt_maildirp(stream, msgno) > 0 -+ ? maildir_text_work(stream, mail_elt(stream, msgno),length, flags) -+ : NULL; ++ if (LOCAL->fd < 0 && ((LOCAL->fd = open (tmp,O_RDONLY,NIL)) < 0)) ++ return maildir_update_elt_maildirp(stream, msgno) > 0 ++ ? maildir_text_work(stream, mail_elt(stream, msgno),length, flags) ++ : NULL; + + lseek (LOCAL->fd, elt->private.msg.text.offset,L_SET); + @@ -1373,7 +1376,7 @@ + + in_list = nfiles > 0L + ? maildir_message_in_list(MDFILE(elt), names, 0L, nfiles - 1L, &pos) -+ : NIL; ++ : 0; + + if (in_list && pos >= 0L && pos < nfiles + && strcmp(MDFILE(elt), names[pos]->d_name)){ @@ -1401,7 +1404,7 @@ + char *maildir_header (MAILSTREAM *stream,unsigned long msgno, + unsigned long *length, long flags) + { -+ char tmp[MAILTMPLEN], *s; ++ char tmp[MAILTMPLEN], *s = NULL; + MESSAGECACHE *elt; + + if (length) *length = 0; @@ -1411,19 +1414,14 @@ + maildir_parse_message(stream, msgno, MDLOC(elt)); + + MSGPATH(tmp, LOCAL->dir, MDFILE(elt), MDLOC(elt)); -+ if (LOCAL->fd < 0) -+ LOCAL->fd = open (tmp,O_RDONLY,NIL); -+ -+ if (LOCAL->fd < 0 && errno == EACCES){ -+ mm_log ("Message exists but can not be read. Envelope and body lost!",ERROR); -+ return NULL; ++ if (LOCAL->fd < 0 && ((LOCAL->fd = open (tmp,O_RDONLY,NIL)) < 0)){ ++ if(errno == EACCES) ++ mm_log ("Message exists but can not be read. Envelope and body lost!",ERROR); ++ return maildir_update_elt_maildirp(stream, msgno) > 0 ++ ? maildir_header(stream, msgno, length, flags) ++ : NULL; + } + -+ if (LOCAL->fd < 0) /* flag change? */ -+ return maildir_update_elt_maildirp(stream, msgno) > 0 -+ ? maildir_header(stream, msgno, length, flags) -+ : NULL; -+ + if (flags & FT_INTERNAL){ + if(elt->private.msg.header.text.size > LOCAL->buflen){ + fs_give ((void **) &LOCAL->buf); @@ -1515,9 +1513,9 @@ + ret = (void *) myMdInboxDir; + break; + case SET_COURIERSTYLE: -+ CourierStyle = (long) value; ++ CourierStyle = * (long *) value; /* fix by Chris Caputo */ + case GET_COURIERSTYLE: -+ ret = (void *) CourierStyle; ++ ret = (void *) &CourierStyle; /* fix by Chris Caputo */ + break; + case GET_DIRFMTTEST: + ret = (void *) maildir_dirfmttest; @@ -1853,10 +1851,10 @@ + + f = mail_parse_flags (stream,flags,&uf); + do { -+ /* build file name we will use */ ++ /* build file name we will use, fix by Chris Caputo */ + snprintf (file, sizeof(file), "%lu.%d_%09u.%.*s%.*s%.*s%.*s%.*s%.*s", + ti, mypid, transact++, -+ (int)(sizeof(file) - 50), mdlocaldomain, 1, (f ? MDSEP(2) : ""), ++ (int)(sizeof(file) - 50), mdlocaldomain, (int) strlen(MDSEP(2)), (f ? MDSEP(2) : ""), + 1, MDFLAG(Draft, f&fDRAFT), 1, MDFLAG(Flagged, f&fFLAGGED), + 1, MDFLAG(Replied, f&fANSWERED), 1, MDFLAG(Seen, f&fSEEN)); + /* build tmp file name */ @@ -2438,6 +2436,7 @@ + char tmp[MAILTMPLEN], *b; + int offset = 0; + int tmpd, tmpf, tmpr, tmps, tmpt; ++ int done = 0; /* fix by Chris Caputo */ + + if(d) *d = 0; + if(f) *f = 0; @@ -2447,7 +2446,7 @@ + + tmpd = tmpf = tmpr = tmps = tmpt = NIL; /* no flags set by default */ + strcpy(tmp,name); -+ while ((b = strrchr(tmp+offset, FLAGSEP)) != NULL){ ++ while (!done && (b = strrchr(tmp+offset, FLAGSEP)) != NULL){ /* fix by Chris Caputo */ + char flag,last; + int k; + if (!++b) break; @@ -2468,7 +2467,8 @@ + b[k] = last; + b += k; + break; -+ default: break; /* Should we crash?... Nahhh */ ++ default: done++; /* fix by Chris Caputo */ ++ break; + } + offset++; + for (; tmp[offset] && tmp[offset] != FLAGSEP; offset++); @@ -3135,7 +3135,7 @@ + } + } diff -rc alpine-2.25/imap/src/osdep/unix/maildir.h alpine-2.25.maildir/imap/src/osdep/unix/maildir.h -*** alpine-2.25/imap/src/osdep/unix/maildir.h 2021-10-15 18:50:01.965799027 -0600 +*** alpine-2.25/imap/src/osdep/unix/maildir.h 2021-11-21 09:34:15.527895256 -0700 --- alpine-2.25.maildir/imap/src/osdep/unix/maildir.h 2021-10-14 12:23:32.311836182 -0600 *************** *** 0 **** @@ -3794,7 +3794,7 @@ /* * The mbox is relative to the home directory. diff -rc alpine-2.25/README.maildir alpine-2.25.maildir/README.maildir -*** alpine-2.25/README.maildir 2021-10-15 18:50:01.969799009 -0600 +*** alpine-2.25/README.maildir 2021-11-21 09:34:15.527895256 -0700 --- alpine-2.25.maildir/README.maildir 2021-10-14 12:23:32.579836182 -0600 *************** *** 0 ****