]>
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("authservice", 0, AUTHSERVICESW) \
79 X("proxy command", 0, PROXYSW) \
81 #define X(sw, minchars, id) id,
82 DEFINE_SWITCH_ENUM(INC
);
85 #define X(sw, minchars, id) { sw, minchars, id },
86 DEFINE_SWITCH_ARRAY(INC
, switches
);
90 * flags for the mail source
96 static struct Maildir_entry
{
100 static int num_maildir_entries
= 0;
101 static int snoop
= 0;
103 extern char response
[];
108 static int mbx_style
= MMDF_FORMAT
;
109 static int pd
= NOTOK
;
114 static char *packfile
= NULL
;
115 static FILE *pf
= NULL
;
117 /* This is an attempt to simplify things by putting all the
118 * privilege ops into macros.
119 * *GROUPPRIVS() is related to handling the setgid MAIL property,
120 * and only applies if MAILGROUP is defined.
121 * Basically, SAVEGROUPPRIVS() is called right at the top of main()
122 * to initialise things, and then DROPGROUPPRIVS() and GETGROUPPRIVS()
123 * do the obvious thing.
125 * There's probably a better implementation if we're allowed to use
126 * BSD-style setreuid() rather than using POSIX saved-ids.
127 * Anyway, if you're euid root it's a bit pointless to drop the group
130 * I'm pretty happy that the security is good provided we aren't setuid root.
131 * The only things we trust with group=mail privilege are lkfopen()
136 * For setting and returning to "mail" gid
139 static gid_t return_gid
;
140 #define TRYDROPGROUPPRIVS() DROPGROUPPRIVS()
141 #define DROPGROUPPRIVS() \
142 if (setegid(getgid()) != 0) { \
143 adios ("setegid", "unable to restore group to %ld", (long) getgid()); \
145 #define GETGROUPPRIVS() \
146 if (setegid(return_gid) != 0) { \
147 adios ("setegid", "unable to set group to %ld", (long) return_gid); \
149 #define SAVEGROUPPRIVS() return_gid = getegid()
151 /* define *GROUPPRIVS() as null; this avoids having lots of "#ifdef MAILGROUP"s */
152 #define TRYDROPGROUPPRIVS()
153 #define DROPGROUPPRIVS()
154 #define GETGROUPPRIVS()
155 #define SAVEGROUPPRIVS()
156 #endif /* not MAILGROUP */
158 /* these variables have to be globals so that done() can correctly clean up the lockfile */
159 static int locked
= 0;
160 static char *newmail
;
166 char *map_name(char *);
168 static void inc_done(int) NORETURN
;
169 static int pop_action(char *);
170 static int pop_pack(char *);
171 static int map_count(void);
174 maildir_srt(const void *va
, const void *vb
)
176 const struct Maildir_entry
*a
= va
, *b
= vb
;
177 if (a
->mtime
> b
->mtime
)
179 else if (a
->mtime
< b
->mtime
)
186 main (int argc
, char **argv
)
188 int chgflag
= 1, trnflag
= 1;
189 int noisy
= 1, width
= -1;
190 int hghnum
= 0, msgnum
= 0;
191 int sasl
= 0, tls
= 0;
192 int incerr
= 0; /* <0 if inc hits an error which means it should not truncate mailspool */
193 char *cp
, *maildir
= NULL
, *folder
= NULL
;
194 char *format
= NULL
, *form
= NULL
;
195 char *host
= NULL
, *port
= NULL
, *user
= NULL
, *proxy
= NULL
;
196 char *audfile
= NULL
, *from
= NULL
, *saslmech
= NULL
, *auth_svc
= NULL
;
197 char buf
[BUFSIZ
], **argp
, *nfs
, **arguments
;
198 struct msgs
*mp
= NULL
;
201 char b
[PATH_MAX
+ 1];
202 char *maildir_copy
= NULL
; /* copy of mail directory because the static gets overwritten */
205 char *MAILHOST_env_variable
;
208 /* absolutely the first thing we do is save our privileges,
209 * and drop them if we can.
214 if (nmh_init(argv
[0], 1)) { return 1; }
217 arguments
= getarguments (invo_name
, argc
, argv
, 1);
222 * use MAILHOST environment variable if present,
224 * If that fails, use the default (if any)
225 * provided by mts.conf in mts_init()
227 if ((MAILHOST_env_variable
= getenv("MAILHOST")) != NULL
)
228 pophost
= MAILHOST_env_variable
;
230 * If there is a valid "pophost" entry in mts.conf,
231 * then use it as the default host.
233 if (pophost
&& *pophost
)
236 while ((cp
= *argp
++)) {
238 switch (smatch (++cp
, switches
)) {
240 ambigsw (cp
, switches
);
243 adios (NULL
, "-%s unknown", cp
);
246 snprintf (buf
, sizeof(buf
), "%s [+folder] [switches]", invo_name
);
247 print_help (buf
, switches
, 1);
250 print_version(invo_name
);
254 if (!(cp
= *argp
++) || *cp
== '-')
255 adios (NULL
, "missing argument to %s", argp
[-2]);
256 audfile
= getcpy (m_maildir (cp
));
270 * The flag `trnflag' has the value:
272 * 2 if -truncate is given
273 * 1 by default (truncating is default)
274 * 0 if -notruncate is given
284 if (!(cp
= *argp
++) || *cp
== '-')
285 adios (NULL
, "missing argument to %s", argp
[-2]);
286 from
= path (cp
, TFILE
);
289 * If the truncate file is in default state,
290 * change to not truncate.
304 if (!(form
= *argp
++) || *form
== '-')
305 adios (NULL
, "missing argument to %s", argp
[-2]);
309 if (!(format
= *argp
++) || *format
== '-')
310 adios (NULL
, "missing argument to %s", argp
[-2]);
315 if (!(cp
= *argp
++) || *cp
== '-')
316 adios (NULL
, "missing argument to %s", argp
[-2]);
321 if (!(host
= *argp
++) || *host
== '-')
322 adios (NULL
, "missing argument to %s", argp
[-2]);
326 if (!(port
= *argp
++) || *port
== '-')
327 adios (NULL
, "missing argument to %s", argp
[-2]);
331 if (!(user
= *argp
++) || *user
== '-')
332 adios (NULL
, "missing argument to %s", argp
[-2]);
336 if (!(packfile
= *argp
++) || *packfile
== '-')
337 adios (NULL
, "missing argument to %s", argp
[-2]);
355 if (!(saslmech
= *argp
++) || *saslmech
== '-')
356 adios (NULL
, "missing argument to %s", argp
[-2]);
369 if (!(auth_svc
= *argp
++) || *auth_svc
== '-')
370 adios (NULL
, "missing argument to %s", argp
[-2]);
372 adios (NULL
, "not built with OAuth support");
377 if (!(proxy
= *argp
++) || *proxy
== '-')
378 adios (NULL
, "missing argument to %s", argp
[-2]);
382 if (*cp
== '+' || *cp
== '@') {
384 adios (NULL
, "only one folder at a time!");
386 folder
= pluspath (cp
);
388 adios (NULL
, "usage: %s [+folder] [switches]", invo_name
);
392 /* NOTE: above this point you should use TRYDROPGROUPPRIVS(),
393 * not DROPGROUPPRIVS().
398 /* guarantee dropping group priveleges; we might not have done so earlier */
402 * Where are we getting the new mail?
412 * Are we getting the mail from
415 if (inc_type
== INC_POP
) {
416 struct nmh_creds creds
= { 0, 0, 0 };
418 if (auth_svc
== NULL
) {
419 if (saslmech
&& ! strcasecmp(saslmech
, "xoauth2")) {
420 adios (NULL
, "must specify -authservice with -saslmech xoauth2");
422 nmh_get_credentials (host
, user
, sasl
, &creds
);
425 adios (NULL
, "must specify -user with -saslmech xoauth2");
431 * initialize POP connection
433 if (pop_init (host
, port
, creds
.user
, creds
.password
, proxy
, snoop
,
434 sasl
, saslmech
, tls
, auth_svc
) == NOTOK
)
435 adios (NULL
, "%s", response
);
437 /* Check if there are any messages */
438 if (pop_stat (&nmsgs
, &nbytes
) == NOTOK
)
439 adios (NULL
, "%s", response
);
443 adios (NULL
, "no mail to incorporate");
448 * We will get the mail from a file
449 * (typically the standard maildrop)
452 if (inc_type
== INC_FILE
) {
455 else if ((newmail
= getenv ("MAILDROP")) && *newmail
)
456 newmail
= m_mailpath (newmail
);
457 else if ((newmail
= context_find ("maildrop")) && *newmail
)
458 newmail
= m_mailpath (newmail
);
460 newmail
= concat (MAILDIR
, "/", MAILFIL
, NULL
);
462 if (stat (newmail
, &s1
) == NOTOK
|| s1
.st_size
== 0)
463 adios (NULL
, "no mail to incorporate");
464 if (s1
.st_mode
& S_IFDIR
) {
470 cp
= concat (newmail
, "/new", NULL
);
471 if ((md
= opendir(cp
)) == NULL
)
472 adios (NULL
, "unable to open %s", cp
);
473 while ((de
= readdir (md
)) != NULL
) {
474 if (de
->d_name
[0] == '.')
476 if (i
>= num_maildir_entries
) {
477 if ((Maildir
= realloc(Maildir
, sizeof(*Maildir
) * (2*i
+16))) == NULL
)
478 adios(NULL
, "not enough memory for %d messages", 2*i
+16);
479 num_maildir_entries
= 2*i
+16;
481 Maildir
[i
].filename
= concat (cp
, "/", de
->d_name
, NULL
);
482 if (stat(Maildir
[i
].filename
, &ms
) != 0)
483 adios (Maildir
[i
].filename
, "couldn't get delivery time");
484 Maildir
[i
].mtime
= ms
.st_mtime
;
489 cp
= concat (newmail
, "/cur", NULL
);
490 if ((md
= opendir(cp
)) == NULL
)
491 adios (NULL
, "unable to open %s", cp
);
492 while ((de
= readdir (md
)) != NULL
) {
493 if (de
->d_name
[0] == '.')
495 if (i
>= num_maildir_entries
) {
496 if ((Maildir
= realloc(Maildir
, sizeof(*Maildir
) * (2*i
+16))) == NULL
)
497 adios(NULL
, "not enough memory for %d messages", 2*i
+16);
498 num_maildir_entries
= 2*i
+16;
500 Maildir
[i
].filename
= concat (cp
, "/", de
->d_name
, NULL
);
501 if (stat(Maildir
[i
].filename
, &ms
) != 0)
502 adios (Maildir
[i
].filename
, "couldn't get delivery time");
503 Maildir
[i
].mtime
= ms
.st_mtime
;
509 adios (NULL
, "no mail to incorporate");
510 num_maildir_entries
= i
;
511 qsort (Maildir
, num_maildir_entries
, sizeof(*Maildir
), maildir_srt
);
514 if ((cp
= strdup(newmail
)) == (char *)0)
515 adios (NULL
, "error allocating memory to copy newmail");
520 /* skip the folder setup */
521 if ((inc_type
== INC_POP
) && packfile
)
524 if (!context_find ("path"))
525 free (path ("./", TFOLDER
));
527 folder
= getfolder (0);
528 maildir
= m_maildir (folder
);
530 if ((maildir_copy
= strdup(maildir
)) == (char *)0)
531 adios (maildir
, "error allocating memory to copy maildir");
533 if (!folder_exists(maildir
)) {
534 /* If the folder doesn't exist, and we're given the -silent flag,
538 create_folder(maildir
, 0, done
);
543 if (chdir (maildir
) == NOTOK
)
544 adios (maildir
, "unable to change directory to");
546 /* read folder and create message structure */
547 if (!(mp
= folder_read (folder
, 0)))
548 adios (NULL
, "unable to read folder %s", folder
);
552 if (inc_type
== INC_FILE
&& Maildir
== NULL
) {
553 if (access (newmail
, W_OK
) != NOTOK
) {
556 SIGNAL (SIGHUP
, SIG_IGN
);
557 SIGNAL (SIGINT
, SIG_IGN
);
558 SIGNAL (SIGQUIT
, SIG_IGN
);
559 SIGNAL (SIGTERM
, SIG_IGN
);
562 GETGROUPPRIVS(); /* Reset gid to lock mail file */
563 in
= lkfopenspool (newmail
, "r");
566 adios (NULL
, "unable to lock and fopen %s", newmail
);
567 fstat (fileno(in
), &s1
);
570 if ((in
= fopen (newmail
, "r")) == NULL
)
571 adios (newmail
, "unable to read");
575 /* This shouldn't be necessary but it can't hurt. */
580 if ((i
= stat (audfile
, &st
)) == NOTOK
)
581 advise (NULL
, "Creating Receive-Audit: %s", audfile
);
582 if ((aud
= fopen (audfile
, "a")) == NULL
)
583 adios (audfile
, "unable to append to");
585 chmod (audfile
, m_gmprot ());
588 fprintf (aud
, "<<inc>> %s -ms %s\n", dtimenow(0), from
);
591 fprintf (aud
, "<<inc>> %s -host %s -user %s\n", dtimenow(0),
594 fprintf (aud
, "<<inc>> %s\n", dtimenow (0));
598 /* Get new format string */
599 nfs
= new_fs (form
, format
, FORMAT
);
602 printf ("Incorporating new mail into %s...\n\n", folder
);
608 * Get the mail from a POP server
610 if (inc_type
== INC_POP
) {
613 packfile
= path (packfile
, TFILE
);
614 if (stat (packfile
, &st
) == NOTOK
) {
616 adios (packfile
, "error on file");
617 cp
= concat ("Create file \"", packfile
, "\"? ", NULL
);
618 if (noisy
&& !read_yes_or_no_if_tty (cp
))
622 msgnum
= map_count ();
623 if ((pd
= mbx_open (packfile
, mbx_style
, getuid(), getgid(), m_gmprot()))
625 adios (packfile
, "unable to open");
626 if ((pf
= fdopen (pd
, "w+")) == NULL
)
627 adios (NULL
, "unable to fdopen %s", packfile
);
629 hghnum
= msgnum
= mp
->hghmsg
;
632 for (i
= 1; i
<= nmsgs
; i
++) {
633 charstring_t scanl
= NULL
;
639 fseek (pf
, 0L, SEEK_CUR
);
642 len
= strlen(mmdlm1
);
643 if (fwrite(mmdlm1
, 1, len
, pf
) < len
)
644 advise (mmdlm1
, "fwrite");
647 if (pop_retr (i
, pop_pack
) == NOTOK
)
648 adios (NULL
, "%s", response
);
650 fseek (pf
, 0L, SEEK_CUR
);
653 adios (packfile
, "write error on");
654 fseek (pf
, start
, SEEK_SET
);
656 cp
= getcpy (m_name (msgnum
));
657 if ((pf
= fopen (cp
, "w+")) == NULL
)
658 adios (cp
, "unable to write");
659 chmod (cp
, m_gmprot ());
662 if (pop_retr (i
, pop_action
) == NOTOK
)
663 adios (NULL
, "%s", response
);
666 adios (cp
, "write error on");
667 fseek (pf
, 0L, SEEK_SET
);
669 switch (incerr
= scan (pf
, msgnum
, 0, nfs
, width
,
670 packfile
? 0 : msgnum
== mp
->hghmsg
+ 1 && chgflag
,
671 1, NULL
, stop
- start
, noisy
, &scanl
)) {
673 printf ("%*d empty\n", DMAXFOLDER
, msgnum
);
679 /* advise (cp, "unable to read"); already advised */
690 fputs (charstring_buffer (scanl
), aud
);
695 charstring_free (scanl
);
700 fseek (pf
, stop
, SEEK_SET
);
701 len
= strlen(mmdlm2
);
702 if (fwrite(mmdlm2
, 1, len
, pf
) < len
)
703 advise (mmdlm2
, "fwrite");
704 if (fflush (pf
) || ferror (pf
)) {
708 adios (packfile
, "write error on");
710 map_write (packfile
, pd
, 0, 0L, start
, stop
, pos
, size
, noisy
);
712 if (ferror(pf
) || fclose (pf
)) {
714 (void) m_unlink (cp
);
717 adios (cp
, "write error on");
722 if (trnflag
&& pop_dele (i
) == NOTOK
)
723 adios (NULL
, "%s", response
);
728 if (pop_quit () == NOTOK
)
729 adios (NULL
, "%s", response
);
731 mbx_close (packfile
, pd
);
737 * Get the mail from file (usually mail spool)
739 if (inc_type
== INC_FILE
&& Maildir
== NULL
) {
740 scan_detect_mbox_style (in
); /* the MAGIC invocation... */
741 hghnum
= msgnum
= mp
->hghmsg
;
743 charstring_t scanl
= NULL
;
745 /* create scanline for new message */
746 switch (incerr
= scan (in
, msgnum
+ 1, msgnum
+ 1, nfs
, width
,
747 msgnum
== hghnum
&& chgflag
, 1, NULL
, 0L, noisy
,
755 fputs ("inc aborted!\n", aud
);
756 advise (NULL
, "aborted!"); /* doesn't clean up locks! */
760 advise (NULL
, "BUG in %s, number out of range", invo_name
);
764 advise (NULL
, "BUG in %s, scan() botch (%d)", invo_name
, incerr
);
770 * Run the external program hook on the message.
773 (void)snprintf(b
, sizeof (b
), "%s/%d", maildir_copy
, msgnum
+ 1);
774 (void)ext_hook("add-hook", b
, (char *)0);
777 fputs (charstring_buffer (scanl
), aud
);
784 charstring_free (scanl
);
786 /* If we get here there was some sort of error from scan(),
787 * so stop processing anything more from the spool.
791 } else if (inc_type
== INC_FILE
) { /* Maildir inbox to process */
796 hghnum
= msgnum
= mp
->hghmsg
;
797 for (i
= 0; i
< num_maildir_entries
; i
++) {
798 charstring_t scanl
= NULL
;
802 sp
= Maildir
[i
].filename
;
803 cp
= getcpy (m_name (msgnum
));
805 if (!trnflag
|| link(sp
, cp
) == -1) {
806 static char buf
[65536];
809 if ((sf
= fopen (sp
, "r")) == NULL
)
810 adios (sp
, "unable to read for copy");
811 if ((pf
= fopen (cp
, "w+")) == NULL
)
812 adios (cp
, "unable to write for copy");
813 while ((nrd
= fread(buf
, 1, sizeof(buf
), sf
)) > 0)
814 if (fwrite(buf
, 1, nrd
, pf
) != nrd
)
816 if (ferror(sf
) || fflush(pf
) || ferror(pf
)) {
818 fclose(pf
); fclose(sf
); (void) m_unlink(cp
);
820 adios(cp
, "copy error %s -> %s", sp
, cp
);
825 if (pf
== NULL
&& (pf
= fopen (cp
, "r")) == NULL
)
826 adios (cp
, "not available");
827 chmod (cp
, m_gmprot ());
829 fseek (pf
, 0L, SEEK_SET
);
830 switch (incerr
= scan (pf
, msgnum
, 0, nfs
, width
,
831 msgnum
== mp
->hghmsg
+ 1 && chgflag
,
832 1, NULL
, stop
- start
, noisy
, &scanl
)) {
834 printf ("%*d empty\n", DMAXFOLDER
, msgnum
);
840 /* advise (cp, "unable to read"); already advised */
851 * Run the external program hook on the message.
854 (void)snprintf(b
, sizeof (b
), "%s/%d", maildir_copy
, msgnum
+ 1);
855 (void)ext_hook("add-hook", b
, (char *)0);
858 fputs (charstring_buffer (scanl
), aud
);
863 charstring_free (scanl
);
865 if (ferror(pf
) || fclose (pf
)) {
867 (void) m_unlink (cp
);
869 adios (cp
, "write error on");
874 if (trnflag
&& m_unlink (sp
) == NOTOK
)
875 adios (sp
, "couldn't unlink");
876 free (sp
); /* Free Maildir[i]->filename */
880 free (Maildir
); /* From now on Maildir is just a flag - don't dref! */
885 if (incerr
< 0) { /* error */
887 GETGROUPPRIVS(); /* Be sure we can unlock mail file */
888 (void) lkfclosespool (in
, newmail
); in
= NULL
;
889 DROPGROUPPRIVS(); /* And then return us to normal privileges */
891 fclose (in
); in
= NULL
;
893 adios (NULL
, "failed");
902 if ((inc_type
== INC_POP
) && packfile
)
906 * truncate file we are incorporating from
908 if (inc_type
== INC_FILE
&& Maildir
== NULL
) {
910 if (stat (newmail
, &st
) != NOTOK
&& s1
.st_mtime
!= st
.st_mtime
)
911 advise (NULL
, "new messages have arrived!\007");
914 if ((newfd
= creat (newmail
, 0600)) != NOTOK
)
917 admonish (newmail
, "error zero'ing");
918 (void) m_unlink(map_name(newmail
));
922 printf ("%s not zero'd\n", newmail
);
926 if (msgnum
== hghnum
) {
927 admonish (NULL
, "no messages incorporated");
930 * Lock the sequence file now, and loop to set the right flags
931 * in the folder structure
937 context_replace (pfolder
, folder
); /* update current folder */
939 if ((mp2
= folder_read(folder
, 1)) == NULL
) {
940 admonish(NULL
, "Unable to reread folder %s", folder
);
945 * Shouldn't happen, but just in case ...
948 if (msgnum
>= mp2
->hghoff
949 && !(mp2
= folder_realloc (mp2
, mp2
->lowoff
, msgnum
+ 1))) {
950 advise (NULL
, "unable to reallocate folder storage");
955 mp2
->curmsg
= hghnum
+ 1;
956 mp2
->hghmsg
= msgnum
;
958 if (mp2
->lowmsg
== 0)
960 if (chgflag
) /* sigh... */
961 seq_setcur (mp2
, mp2
->curmsg
);
963 for (i
= hghnum
+ 1; i
<= msgnum
; i
++) {
964 clear_msg_flags (mp2
, i
);
968 mp2
->msgflags
|= SEQMOD
;
969 seq_setunseen(mp2
, 0); /* Set the Unseen-Sequence */
970 seq_save(mp2
); /* Save the sequence file */
976 * unlock the mail spool
978 if (inc_type
== INC_FILE
&& Maildir
== NULL
) {
980 GETGROUPPRIVS(); /* Be sure we can unlock mail file */
981 (void) lkfclosespool (in
, newmail
); in
= NULL
;
982 DROPGROUPPRIVS(); /* And then return us to normal privileges */
984 fclose (in
); in
= NULL
;
988 context_save (); /* save the context file */
995 inc_done (int status
)
998 if (packfile
&& pd
!= NOTOK
)
999 mbx_close (packfile
, pd
);
1003 lkfclosespool(in
, newmail
);
1010 pop_action (char *s
)
1012 fprintf (pf
, "%s\n", s
);
1013 stop
+= strlen (s
) + 1;
1014 return 0; /* Is return value used? This was missing before 1999-07-15. */
1021 char buffer
[BUFSIZ
];
1023 snprintf (buffer
, sizeof(buffer
), "%s\n", s
);
1024 for ( ; (j
= stringdex (mmdlm1
, buffer
)) >= 0; buffer
[j
]++)
1026 for ( ; (j
= stringdex (mmdlm2
, buffer
)) >= 0; buffer
[j
]++)
1029 size
+= strlen (buffer
) + 1;
1030 return 0; /* Is return value used? This was missing before 1999-07-15. */
1041 if (stat (packfile
, &st
) == NOTOK
)
1043 if ((md
= open (cp
= map_name (packfile
), O_RDONLY
)) == NOTOK
1044 || map_chk (cp
, md
, &d
, (long) st
.st_size
, 1)) {