]>
diplodocus.org Git - nmh/blob - uip/inc.c
3 * inc.c -- incorporate messages from a maildrop into a folder
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
12 * Thu Feb 12 21:00 CST 2015 Marcin Cieslak <saper@saper.info>
13 * Replaced setgid() calls with setegid() so that it works with dot
14 * locking on FreeBSD. setegid() should be supported on modern POSIX
17 * Revised: Sat Apr 14 17:08:17 PDT 1990 (marvit@hplabs)
18 * Added hpux hacks to set and reset gid to be "mail" as needed. The reset
19 * is necessary so inc'ed mail is the group of the inc'er, rather than
20 * "mail". We setgid to egid only when [un]locking the mail file. This
21 * is also a major security precaution which will not be explained here.
23 * Fri Feb 7 16:04:57 PST 1992 John Romine <bug-mh@ics.uci.edu>
24 * NB: I'm not 100% sure that this setgid stuff is secure even now.
26 * See the *GROUPPRIVS() macros later. I'm reasonably happy with the setgid
27 * attribute. Running setuid root is probably not a terribly good idea, though.
28 * -- Peter Maydell <pmaydell@chiark.greenend.org.uk>, 04/1998
30 * Peter Maydell's patch slightly modified for nmh 0.28-pre2.
31 * Ruud de Rooij <ruud@debian.org> Wed, 22 Jul 1998 13:24:22 +0200
38 #include <h/dropsbr.h>
40 #include <h/fmt_scan.h>
41 #include <h/scansbr.h>
42 #include <h/signals.h>
47 # define TLSminc(a) (a)
52 #define INC_SWITCHES \
53 X("audit audit-file", 0, AUDSW) \
54 X("noaudit", 0, NAUDSW) \
55 X("changecur", 0, CHGSW) \
56 X("nochangecur", 0, NCHGSW) \
57 X("file name", 0, FILESW) \
58 X("form formatfile", 0, FORMSW) \
59 X("format string", 5, FMTSW) \
60 X("host hostname", 0, HOSTSW) \
61 X("user username", 0, USERSW) \
62 X("pack file", 0, PACKSW) \
63 X("nopack", 0, NPACKSW) \
64 X("port name/number", 0, PORTSW) \
65 X("silent", 0, SILSW) \
66 X("nosilent", 0, NSILSW) \
67 X("truncate", 0, TRNCSW) \
68 X("notruncate", 0, NTRNCSW) \
69 X("width columns", 0, WIDTHSW) \
70 X("version", 0, VERSIONSW) \
71 X("help", 0, HELPSW) \
72 X("snoop", 0, SNOOPSW) \
73 X("sasl", 0, SASLSW) \
74 X("nosasl", 0, NOSASLSW) \
75 X("saslmech", 0, SASLMECHSW) \
76 X("initialtls", TLSminc(-10), INITTLSSW) \
77 X("notls", TLSminc(-5), NOTLSSW) \
78 X("certverify", TLSminc(-10), CERTVERSW) \
79 X("nocertverify", TLSminc(-12), NOCERTVERSW) \
80 X("authservice", 0, AUTHSERVICESW) \
81 X("proxy command", 0, PROXYSW) \
83 #define X(sw, minchars, id) id,
84 DEFINE_SWITCH_ENUM(INC
);
87 #define X(sw, minchars, id) { sw, minchars, id },
88 DEFINE_SWITCH_ARRAY(INC
, switches
);
92 * flags for the mail source
98 static struct Maildir_entry
{
102 static int num_maildir_entries
= 0;
103 static int snoop
= 0;
105 extern char response
[];
110 static int mbx_style
= MMDF_FORMAT
;
111 static int pd
= NOTOK
;
116 static char *packfile
= NULL
;
117 static FILE *pf
= NULL
;
119 /* This is an attempt to simplify things by putting all the
120 * privilege ops into macros.
121 * *GROUPPRIVS() is related to handling the setgid MAIL property,
122 * and only applies if MAILGROUP is defined.
123 * Basically, SAVEGROUPPRIVS() is called right at the top of main()
124 * to initialise things, and then DROPGROUPPRIVS() and GETGROUPPRIVS()
125 * do the obvious thing.
127 * There's probably a better implementation if we're allowed to use
128 * BSD-style setreuid() rather than using POSIX saved-ids.
129 * Anyway, if you're euid root it's a bit pointless to drop the group
132 * I'm pretty happy that the security is good provided we aren't setuid root.
133 * The only things we trust with group=mail privilege are lkfopen()
138 * For setting and returning to "mail" gid
141 static gid_t return_gid
;
142 #define TRYDROPGROUPPRIVS() DROPGROUPPRIVS()
143 #define DROPGROUPPRIVS() \
144 if (setegid(getgid()) != 0) { \
145 adios ("setegid", "unable to restore group to %ld", (long) getgid()); \
147 #define GETGROUPPRIVS() \
148 if (setegid(return_gid) != 0) { \
149 adios ("setegid", "unable to set group to %ld", (long) return_gid); \
151 #define SAVEGROUPPRIVS() return_gid = getegid()
153 /* define *GROUPPRIVS() as null; this avoids having lots of "#ifdef MAILGROUP"s */
154 #define TRYDROPGROUPPRIVS()
155 #define DROPGROUPPRIVS()
156 #define GETGROUPPRIVS()
157 #define SAVEGROUPPRIVS()
158 #endif /* not MAILGROUP */
160 /* these variables have to be globals so that done() can correctly clean up the lockfile */
161 static int locked
= 0;
162 static char *newmail
;
168 char *map_name(char *);
170 static void inc_done(int) NORETURN
;
171 static int pop_action(char *);
172 static int pop_pack(char *);
173 static int map_count(void);
176 maildir_srt(const void *va
, const void *vb
)
178 const struct Maildir_entry
*a
= va
, *b
= vb
;
179 if (a
->mtime
> b
->mtime
)
181 if (a
->mtime
< b
->mtime
)
187 main (int argc
, char **argv
)
189 int chgflag
= 1, trnflag
= 1;
190 int noisy
= 1, width
= -1;
191 int hghnum
= 0, msgnum
= 0;
192 int sasl
= 0, tls
= 0, noverify
= 1;
193 int incerr
= 0; /* <0 if inc hits an error which means it should not truncate mailspool */
194 char *cp
, *maildir
= NULL
, *folder
= NULL
;
195 char *format
= NULL
, *form
= NULL
;
196 char *host
= NULL
, *port
= NULL
, *user
= NULL
, *proxy
= NULL
;
197 char *audfile
= NULL
, *from
= NULL
, *saslmech
= NULL
, *auth_svc
= NULL
;
198 char buf
[BUFSIZ
], **argp
, *nfs
, **arguments
;
199 struct msgs
*mp
= NULL
;
202 char b
[PATH_MAX
+ 1];
203 char *maildir_copy
= NULL
; /* copy of mail directory because the static gets overwritten */
206 char *MAILHOST_env_variable
;
209 /* absolutely the first thing we do is save our privileges,
210 * and drop them if we can.
215 if (nmh_init(argv
[0], 1)) { return 1; }
218 arguments
= getarguments (invo_name
, argc
, argv
, 1);
223 * use MAILHOST environment variable if present,
225 * If that fails, use the default (if any)
226 * provided by mts.conf in mts_init()
228 if ((MAILHOST_env_variable
= getenv("MAILHOST")) != NULL
)
229 pophost
= MAILHOST_env_variable
;
231 * If there is a valid "pophost" entry in mts.conf,
232 * then use it as the default host.
234 if (pophost
&& *pophost
)
237 while ((cp
= *argp
++)) {
239 switch (smatch (++cp
, switches
)) {
241 ambigsw (cp
, switches
);
244 adios (NULL
, "-%s unknown", cp
);
247 snprintf (buf
, sizeof(buf
), "%s [+folder] [switches]", invo_name
);
248 print_help (buf
, switches
, 1);
251 print_version(invo_name
);
255 if (!(cp
= *argp
++) || *cp
== '-')
256 adios (NULL
, "missing argument to %s", argp
[-2]);
257 audfile
= getcpy (m_maildir (cp
));
271 * The flag `trnflag' has the value:
273 * 2 if -truncate is given
274 * 1 by default (truncating is default)
275 * 0 if -notruncate is given
285 if (!(cp
= *argp
++) || *cp
== '-')
286 adios (NULL
, "missing argument to %s", argp
[-2]);
287 from
= path (cp
, TFILE
);
290 * If the truncate file is in default state,
291 * change to not truncate.
305 if (!(form
= *argp
++) || *form
== '-')
306 adios (NULL
, "missing argument to %s", argp
[-2]);
310 if (!(format
= *argp
++) || *format
== '-')
311 adios (NULL
, "missing argument to %s", argp
[-2]);
316 if (!(cp
= *argp
++) || *cp
== '-')
317 adios (NULL
, "missing argument to %s", argp
[-2]);
322 if (!(host
= *argp
++) || *host
== '-')
323 adios (NULL
, "missing argument to %s", argp
[-2]);
327 if (!(port
= *argp
++) || *port
== '-')
328 adios (NULL
, "missing argument to %s", argp
[-2]);
332 if (!(user
= *argp
++) || *user
== '-')
333 adios (NULL
, "missing argument to %s", argp
[-2]);
337 if (!(packfile
= *argp
++) || *packfile
== '-')
338 adios (NULL
, "missing argument to %s", argp
[-2]);
356 if (!(saslmech
= *argp
++) || *saslmech
== '-')
357 adios (NULL
, "missing argument to %s", argp
[-2]);
378 if (!(auth_svc
= *argp
++) || *auth_svc
== '-')
379 adios (NULL
, "missing argument to %s", argp
[-2]);
381 adios (NULL
, "not built with OAuth support");
386 if (!(proxy
= *argp
++) || *proxy
== '-')
387 adios (NULL
, "missing argument to %s", argp
[-2]);
391 if (*cp
== '+' || *cp
== '@') {
393 adios (NULL
, "only one folder at a time!");
395 folder
= pluspath (cp
);
397 adios (NULL
, "usage: %s [+folder] [switches]", invo_name
);
401 /* NOTE: above this point you should use TRYDROPGROUPPRIVS(),
402 * not DROPGROUPPRIVS().
407 /* guarantee dropping group priveleges; we might not have done so earlier */
411 * Where are we getting the new mail?
421 * Are we getting the mail from
424 if (inc_type
== INC_POP
) {
427 if (auth_svc
== NULL
) {
428 if (saslmech
&& ! strcasecmp(saslmech
, "xoauth2")) {
429 adios (NULL
, "must specify -authservice with -saslmech xoauth2");
433 adios (NULL
, "must specify -user with -saslmech xoauth2");
438 tlsflag
|= P_INITTLS
;
441 tlsflag
|= P_NOVERIFY
;
444 * initialize POP connection
446 if (pop_init (host
, port
, user
, proxy
, snoop
, sasl
, saslmech
,
447 tlsflag
, auth_svc
) == NOTOK
)
448 adios (NULL
, "%s", response
);
450 /* Check if there are any messages */
451 if (pop_stat (&nmsgs
, &nbytes
) == NOTOK
)
452 adios (NULL
, "%s", response
);
456 adios (NULL
, "no mail to incorporate");
461 * We will get the mail from a file
462 * (typically the standard maildrop)
465 if (inc_type
== INC_FILE
) {
468 else if ((newmail
= getenv ("MAILDROP")) && *newmail
)
469 newmail
= m_mailpath (newmail
);
470 else if ((newmail
= context_find ("maildrop")) && *newmail
)
471 newmail
= m_mailpath (newmail
);
473 newmail
= concat (MAILDIR
, "/", MAILFIL
, NULL
);
475 if (stat (newmail
, &s1
) == NOTOK
|| s1
.st_size
== 0)
476 adios (NULL
, "no mail to incorporate");
477 if (s1
.st_mode
& S_IFDIR
) {
483 cp
= concat (newmail
, "/new", NULL
);
484 if ((md
= opendir(cp
)) == NULL
)
485 adios (NULL
, "unable to open %s", cp
);
486 while ((de
= readdir (md
)) != NULL
) {
487 if (de
->d_name
[0] == '.')
489 if (i
>= num_maildir_entries
) {
490 if ((Maildir
= realloc(Maildir
, sizeof(*Maildir
) * (2*i
+16))) == NULL
)
491 adios(NULL
, "not enough memory for %d messages", 2*i
+16);
492 num_maildir_entries
= 2*i
+16;
494 Maildir
[i
].filename
= concat (cp
, "/", de
->d_name
, NULL
);
495 if (stat(Maildir
[i
].filename
, &ms
) != 0)
496 adios (Maildir
[i
].filename
, "couldn't get delivery time");
497 Maildir
[i
].mtime
= ms
.st_mtime
;
502 cp
= concat (newmail
, "/cur", NULL
);
503 if ((md
= opendir(cp
)) == NULL
)
504 adios (NULL
, "unable to open %s", cp
);
505 while ((de
= readdir (md
)) != NULL
) {
506 if (de
->d_name
[0] == '.')
508 if (i
>= num_maildir_entries
) {
509 if ((Maildir
= realloc(Maildir
, sizeof(*Maildir
) * (2*i
+16))) == NULL
)
510 adios(NULL
, "not enough memory for %d messages", 2*i
+16);
511 num_maildir_entries
= 2*i
+16;
513 Maildir
[i
].filename
= concat (cp
, "/", de
->d_name
, NULL
);
514 if (stat(Maildir
[i
].filename
, &ms
) != 0)
515 adios (Maildir
[i
].filename
, "couldn't get delivery time");
516 Maildir
[i
].mtime
= ms
.st_mtime
;
522 adios (NULL
, "no mail to incorporate");
523 num_maildir_entries
= i
;
524 qsort (Maildir
, num_maildir_entries
, sizeof(*Maildir
), maildir_srt
);
527 if ((cp
= strdup(newmail
)) == NULL
)
528 adios (NULL
, "error allocating memory to copy newmail");
533 /* skip the folder setup */
534 if ((inc_type
== INC_POP
) && packfile
)
537 if (!context_find ("path"))
538 free (path ("./", TFOLDER
));
540 folder
= getfolder (0);
541 maildir
= m_maildir (folder
);
543 if ((maildir_copy
= strdup(maildir
)) == NULL
)
544 adios (maildir
, "error allocating memory to copy maildir");
546 if (!folder_exists(maildir
)) {
547 /* If the folder doesn't exist, and we're given the -silent flag,
551 create_folder(maildir
, 0, done
);
556 if (chdir (maildir
) == NOTOK
)
557 adios (maildir
, "unable to change directory to");
559 /* read folder and create message structure */
560 if (!(mp
= folder_read (folder
, 0)))
561 adios (NULL
, "unable to read folder %s", folder
);
565 if (inc_type
== INC_FILE
&& Maildir
== NULL
) {
566 if (access (newmail
, W_OK
) != NOTOK
) {
569 SIGNAL (SIGHUP
, SIG_IGN
);
570 SIGNAL (SIGINT
, SIG_IGN
);
571 SIGNAL (SIGQUIT
, SIG_IGN
);
572 SIGNAL (SIGTERM
, SIG_IGN
);
575 GETGROUPPRIVS(); /* Reset gid to lock mail file */
576 in
= lkfopenspool (newmail
, "r");
579 adios (NULL
, "unable to lock and fopen %s", newmail
);
580 fstat (fileno(in
), &s1
);
583 if ((in
= fopen (newmail
, "r")) == NULL
)
584 adios (newmail
, "unable to read");
588 /* This shouldn't be necessary but it can't hurt. */
593 if ((i
= stat (audfile
, &st
)) == NOTOK
)
594 advise (NULL
, "Creating Receive-Audit: %s", audfile
);
595 if ((aud
= fopen (audfile
, "a")) == NULL
)
596 adios (audfile
, "unable to append to");
598 chmod (audfile
, m_gmprot ());
601 fprintf (aud
, "<<inc>> %s -ms %s\n", dtimenow(0), from
);
604 fprintf (aud
, "<<inc>> %s -host %s -user %s\n", dtimenow(0),
607 fprintf (aud
, "<<inc>> %s\n", dtimenow (0));
611 /* Get new format string */
612 nfs
= new_fs (form
, format
, FORMAT
);
615 printf ("Incorporating new mail into %s...\n\n", folder
);
621 * Get the mail from a POP server
623 if (inc_type
== INC_POP
) {
626 packfile
= path (packfile
, TFILE
);
627 if (stat (packfile
, &st
) == NOTOK
) {
629 adios (packfile
, "error on file");
630 cp
= concat ("Create file \"", packfile
, "\"? ", NULL
);
631 if (noisy
&& !read_yes_or_no_if_tty (cp
))
635 msgnum
= map_count ();
636 if ((pd
= mbx_open (packfile
, mbx_style
, getuid(), getgid(), m_gmprot()))
638 adios (packfile
, "unable to open");
639 if ((pf
= fdopen (pd
, "w+")) == NULL
)
640 adios (NULL
, "unable to fdopen %s", packfile
);
642 hghnum
= msgnum
= mp
->hghmsg
;
645 for (i
= 1; i
<= nmsgs
; i
++) {
646 charstring_t scanl
= NULL
;
652 fseek (pf
, 0L, SEEK_CUR
);
655 len
= strlen(mmdlm1
);
656 if (fwrite(mmdlm1
, 1, len
, pf
) < len
)
657 advise (mmdlm1
, "fwrite");
660 if (pop_retr (i
, pop_pack
) == NOTOK
)
661 adios (NULL
, "%s", response
);
663 fseek (pf
, 0L, SEEK_CUR
);
666 adios (packfile
, "write error on");
667 fseek (pf
, start
, SEEK_SET
);
669 cp
= mh_xstrdup(m_name (msgnum
));
670 if ((pf
= fopen (cp
, "w+")) == NULL
)
671 adios (cp
, "unable to write");
672 chmod (cp
, m_gmprot ());
675 if (pop_retr (i
, pop_action
) == NOTOK
)
676 adios (NULL
, "%s", response
);
679 adios (cp
, "write error on");
680 fseek (pf
, 0L, SEEK_SET
);
682 switch (incerr
= scan (pf
, msgnum
, 0, nfs
, width
,
683 packfile
? 0 : msgnum
== mp
->hghmsg
+ 1 && chgflag
,
684 1, NULL
, stop
- start
, noisy
, &scanl
)) {
686 printf ("%*d empty\n", DMAXFOLDER
, msgnum
);
692 /* advise (cp, "unable to read"); already advised */
703 fputs (charstring_buffer (scanl
), aud
);
708 charstring_free (scanl
);
713 fseek (pf
, stop
, SEEK_SET
);
714 len
= strlen(mmdlm2
);
715 if (fwrite(mmdlm2
, 1, len
, pf
) < len
)
716 advise (mmdlm2
, "fwrite");
717 if (fflush (pf
) || ferror (pf
)) {
721 adios (packfile
, "write error on");
723 map_write (packfile
, pd
, 0, 0L, start
, stop
, pos
, size
, noisy
);
725 if (ferror(pf
) || fclose (pf
)) {
727 (void) m_unlink (cp
);
730 adios (cp
, "write error on");
735 if (trnflag
&& pop_dele (i
) == NOTOK
)
736 adios (NULL
, "%s", response
);
741 if (pop_quit () == NOTOK
)
742 adios (NULL
, "%s", response
);
744 mbx_close (packfile
, pd
);
750 * Get the mail from file (usually mail spool)
752 if (inc_type
== INC_FILE
&& Maildir
== NULL
) {
753 scan_detect_mbox_style (in
); /* the MAGIC invocation... */
754 hghnum
= msgnum
= mp
->hghmsg
;
756 charstring_t scanl
= NULL
;
758 /* create scanline for new message */
759 switch (incerr
= scan (in
, msgnum
+ 1, msgnum
+ 1, nfs
, width
,
760 msgnum
== hghnum
&& chgflag
, 1, NULL
, 0L, noisy
,
768 fputs ("inc aborted!\n", aud
);
769 advise (NULL
, "aborted!"); /* doesn't clean up locks! */
773 advise (NULL
, "BUG in %s, number out of range", invo_name
);
777 advise (NULL
, "BUG in %s, scan() botch (%d)", invo_name
, incerr
);
783 * Run the external program hook on the message.
786 (void)snprintf(b
, sizeof (b
), "%s/%d", maildir_copy
, msgnum
+ 1);
787 (void)ext_hook("add-hook", b
, NULL
);
790 fputs (charstring_buffer (scanl
), aud
);
797 charstring_free (scanl
);
799 /* If we get here there was some sort of error from scan(),
800 * so stop processing anything more from the spool.
804 } else if (inc_type
== INC_FILE
) { /* Maildir inbox to process */
809 hghnum
= msgnum
= mp
->hghmsg
;
810 for (i
= 0; i
< num_maildir_entries
; i
++) {
811 charstring_t scanl
= NULL
;
815 sp
= Maildir
[i
].filename
;
816 cp
= mh_xstrdup(m_name (msgnum
));
818 if (!trnflag
|| link(sp
, cp
) == -1) {
819 static char buf
[65536];
822 if ((sf
= fopen (sp
, "r")) == NULL
)
823 adios (sp
, "unable to read for copy");
824 if ((pf
= fopen (cp
, "w+")) == NULL
)
825 adios (cp
, "unable to write for copy");
826 while ((nrd
= fread(buf
, 1, sizeof(buf
), sf
)) > 0)
827 if (fwrite(buf
, 1, nrd
, pf
) != nrd
)
829 if (ferror(sf
) || fflush(pf
) || ferror(pf
)) {
831 fclose(pf
); fclose(sf
); (void) m_unlink(cp
);
833 adios(cp
, "copy error %s -> %s", sp
, cp
);
838 if (pf
== NULL
&& (pf
= fopen (cp
, "r")) == NULL
)
839 adios (cp
, "not available");
840 chmod (cp
, m_gmprot ());
842 fseek (pf
, 0L, SEEK_SET
);
843 switch (incerr
= scan (pf
, msgnum
, 0, nfs
, width
,
844 msgnum
== mp
->hghmsg
+ 1 && chgflag
,
845 1, NULL
, stop
- start
, noisy
, &scanl
)) {
847 printf ("%*d empty\n", DMAXFOLDER
, msgnum
);
853 /* advise (cp, "unable to read"); already advised */
864 * Run the external program hook on the message.
867 (void)snprintf(b
, sizeof (b
), "%s/%d", maildir_copy
, msgnum
+ 1);
868 (void)ext_hook("add-hook", b
, NULL
);
871 fputs (charstring_buffer (scanl
), aud
);
876 charstring_free (scanl
);
878 if (ferror(pf
) || fclose (pf
)) {
880 (void) m_unlink (cp
);
882 adios (cp
, "write error on");
887 if (trnflag
&& m_unlink (sp
) == NOTOK
)
888 adios (sp
, "couldn't unlink");
889 free (sp
); /* Free Maildir[i]->filename */
893 free (Maildir
); /* From now on Maildir is just a flag - don't dref! */
898 if (incerr
< 0) { /* error */
900 GETGROUPPRIVS(); /* Be sure we can unlock mail file */
901 (void) lkfclosespool (in
, newmail
); in
= NULL
;
902 DROPGROUPPRIVS(); /* And then return us to normal privileges */
904 fclose (in
); in
= NULL
;
906 adios (NULL
, "failed");
915 if ((inc_type
== INC_POP
) && packfile
)
919 * truncate file we are incorporating from
921 if (inc_type
== INC_FILE
&& Maildir
== NULL
) {
923 if (stat (newmail
, &st
) != NOTOK
&& s1
.st_mtime
!= st
.st_mtime
)
924 advise (NULL
, "new messages have arrived!\007");
927 if ((newfd
= creat (newmail
, 0600)) != NOTOK
)
930 admonish (newmail
, "error zero'ing");
931 (void) m_unlink(map_name(newmail
));
935 printf ("%s not zero'd\n", newmail
);
939 if (msgnum
== hghnum
) {
940 admonish (NULL
, "no messages incorporated");
943 * Lock the sequence file now, and loop to set the right flags
944 * in the folder structure
950 context_replace (pfolder
, folder
); /* update current folder */
952 if ((mp2
= folder_read(folder
, 1)) == NULL
) {
953 admonish(NULL
, "Unable to reread folder %s", folder
);
958 * Shouldn't happen, but just in case ...
961 if (msgnum
>= mp2
->hghoff
962 && !(mp2
= folder_realloc (mp2
, mp2
->lowoff
, msgnum
+ 1))) {
963 advise (NULL
, "unable to reallocate folder storage");
968 mp2
->curmsg
= hghnum
+ 1;
969 mp2
->hghmsg
= msgnum
;
971 if (mp2
->lowmsg
== 0)
973 if (chgflag
) /* sigh... */
974 seq_setcur (mp2
, mp2
->curmsg
);
976 for (i
= hghnum
+ 1; i
<= msgnum
; i
++) {
977 clear_msg_flags (mp2
, i
);
981 mp2
->msgflags
|= SEQMOD
;
982 seq_setunseen(mp2
, 0); /* Set the Unseen-Sequence */
983 seq_save(mp2
); /* Save the sequence file */
989 * unlock the mail spool
991 if (inc_type
== INC_FILE
&& Maildir
== NULL
) {
993 GETGROUPPRIVS(); /* Be sure we can unlock mail file */
994 (void) lkfclosespool (in
, newmail
); in
= NULL
;
995 DROPGROUPPRIVS(); /* And then return us to normal privileges */
997 fclose (in
); in
= NULL
;
1001 context_save (); /* save the context file */
1008 inc_done (int status
)
1011 if (packfile
&& pd
!= NOTOK
)
1012 mbx_close (packfile
, pd
);
1016 lkfclosespool(in
, newmail
);
1023 pop_action (char *s
)
1025 fprintf (pf
, "%s\n", s
);
1026 stop
+= strlen (s
) + 1;
1027 return 0; /* Is return value used? This was missing before 1999-07-15. */
1034 char buffer
[BUFSIZ
];
1036 snprintf (buffer
, sizeof(buffer
), "%s\n", s
);
1037 for ( ; (j
= stringdex (mmdlm1
, buffer
)) >= 0; buffer
[j
]++)
1039 for ( ; (j
= stringdex (mmdlm2
, buffer
)) >= 0; buffer
[j
]++)
1042 size
+= strlen (buffer
) + 1;
1043 return 0; /* Is return value used? This was missing before 1999-07-15. */
1054 if (stat (packfile
, &st
) == NOTOK
)
1056 if ((md
= open (cp
= map_name (packfile
), O_RDONLY
)) == NOTOK
1057 || map_chk (cp
, md
, &d
, (long) st
.st_size
, 1)) {