]>
diplodocus.org Git - nmh/blob - uip/inc.c
1 /* inc.c -- incorporate messages from a maildrop into a folder
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
10 * Thu Feb 12 21:00 CST 2015 Marcin Cieslak <saper@saper.info>
11 * Replaced setgid() calls with setegid() so that it works with dot
12 * locking on FreeBSD. setegid() should be supported on modern POSIX
15 * Revised: Sat Apr 14 17:08:17 PDT 1990 (marvit@hplabs)
16 * Added hpux hacks to set and reset gid to be "mail" as needed. The reset
17 * is necessary so inc'ed mail is the group of the inc'er, rather than
18 * "mail". We setgid to egid only when [un]locking the mail file. This
19 * is also a major security precaution which will not be explained here.
21 * Fri Feb 7 16:04:57 PST 1992 John Romine <bug-mh@ics.uci.edu>
22 * NB: I'm not 100% sure that this setgid stuff is secure even now.
24 * See the *GROUPPRIVS() macros later. I'm reasonably happy with the setgid
25 * attribute. Running setuid root is probably not a terribly good idea, though.
26 * -- Peter Maydell <pmaydell@chiark.greenend.org.uk>, 04/1998
28 * Peter Maydell's patch slightly modified for nmh 0.28-pre2.
29 * Ruud de Rooij <ruud@debian.org> Wed, 22 Jul 1998 13:24:22 +0200
36 #include <h/dropsbr.h>
38 #include <h/fmt_scan.h>
39 #include <h/scansbr.h>
40 #include <h/signals.h>
45 # define TLSminc(a) (a)
50 #define INC_SWITCHES \
51 X("audit audit-file", 0, AUDSW) \
52 X("noaudit", 0, NAUDSW) \
53 X("changecur", 0, CHGSW) \
54 X("nochangecur", 0, NCHGSW) \
55 X("file name", 0, FILESW) \
56 X("form formatfile", 0, FORMSW) \
57 X("format string", 5, FMTSW) \
58 X("host hostname", 0, HOSTSW) \
59 X("user username", 0, USERSW) \
60 X("pack file", 0, PACKSW) \
61 X("nopack", 0, NPACKSW) \
62 X("port name/number", 0, PORTSW) \
63 X("silent", 0, SILSW) \
64 X("nosilent", 0, NSILSW) \
65 X("truncate", 0, TRNCSW) \
66 X("notruncate", 0, NTRNCSW) \
67 X("width columns", 0, WIDTHSW) \
68 X("version", 0, VERSIONSW) \
69 X("help", 0, HELPSW) \
70 X("snoop", 0, SNOOPSW) \
71 X("sasl", 0, SASLSW) \
72 X("nosasl", 0, NOSASLSW) \
73 X("saslmech", 0, SASLMECHSW) \
74 X("initialtls", TLSminc(-10), INITTLSSW) \
75 X("notls", TLSminc(-5), NOTLSSW) \
76 X("certverify", TLSminc(-10), CERTVERSW) \
77 X("nocertverify", TLSminc(-12), NOCERTVERSW) \
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 if (a
->mtime
< b
->mtime
)
185 main (int argc
, char **argv
)
191 int hghnum
= 0, msgnum
= 0;
192 bool sasl
, tls
, noverify
;
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
)
238 chgflag
= noisy
= noverify
= true;
239 while ((cp
= *argp
++)) {
241 switch (smatch (++cp
, switches
)) {
243 ambigsw (cp
, switches
);
246 adios (NULL
, "-%s unknown", cp
);
249 snprintf (buf
, sizeof(buf
), "%s [+folder] [switches]", invo_name
);
250 print_help (buf
, switches
, 1);
253 print_version(invo_name
);
257 if (!(cp
= *argp
++) || *cp
== '-')
258 adios (NULL
, "missing argument to %s", argp
[-2]);
259 audfile
= getcpy (m_maildir (cp
));
273 * The flag `trnflag' has the value:
275 * 2 if -truncate is given
276 * 1 by default (truncating is default)
277 * 0 if -notruncate is given
287 if (!(cp
= *argp
++) || *cp
== '-')
288 adios (NULL
, "missing argument to %s", argp
[-2]);
289 from
= path (cp
, TFILE
);
292 * If the truncate file is in default state,
293 * change to not truncate.
307 if (!(form
= *argp
++) || *form
== '-')
308 adios (NULL
, "missing argument to %s", argp
[-2]);
312 if (!(format
= *argp
++) || *format
== '-')
313 adios (NULL
, "missing argument to %s", argp
[-2]);
318 if (!(cp
= *argp
++) || *cp
== '-')
319 adios (NULL
, "missing argument to %s", argp
[-2]);
324 if (!(host
= *argp
++) || *host
== '-')
325 adios (NULL
, "missing argument to %s", argp
[-2]);
329 if (!(port
= *argp
++) || *port
== '-')
330 adios (NULL
, "missing argument to %s", argp
[-2]);
334 if (!(user
= *argp
++) || *user
== '-')
335 adios (NULL
, "missing argument to %s", argp
[-2]);
339 if (!(packfile
= *argp
++) || *packfile
== '-')
340 adios (NULL
, "missing argument to %s", argp
[-2]);
358 if (!(saslmech
= *argp
++) || *saslmech
== '-')
359 adios (NULL
, "missing argument to %s", argp
[-2]);
380 if (!(auth_svc
= *argp
++) || *auth_svc
== '-')
381 adios (NULL
, "missing argument to %s", argp
[-2]);
383 adios (NULL
, "not built with OAuth support");
388 if (!(proxy
= *argp
++) || *proxy
== '-')
389 adios (NULL
, "missing argument to %s", argp
[-2]);
393 if (*cp
== '+' || *cp
== '@') {
395 adios (NULL
, "only one folder at a time!");
397 folder
= pluspath (cp
);
399 adios (NULL
, "usage: %s [+folder] [switches]", invo_name
);
403 /* NOTE: above this point you should use TRYDROPGROUPPRIVS(),
404 * not DROPGROUPPRIVS().
409 /* guarantee dropping group privileges; we might not have done so earlier */
413 * Where are we getting the new mail?
423 * Are we getting the mail from
426 if (inc_type
== INC_POP
) {
429 if (auth_svc
== NULL
) {
430 if (saslmech
&& ! strcasecmp(saslmech
, "xoauth2")) {
431 adios (NULL
, "must specify -authservice with -saslmech xoauth2");
435 adios (NULL
, "must specify -user with -saslmech xoauth2");
440 tlsflag
|= P_INITTLS
;
443 tlsflag
|= P_NOVERIFY
;
446 * initialize POP connection
448 if (pop_init (host
, port
, user
, proxy
, snoop
, sasl
, saslmech
,
449 tlsflag
, auth_svc
) == NOTOK
)
450 adios (NULL
, "%s", response
);
452 /* Check if there are any messages */
453 if (pop_stat (&nmsgs
, &nbytes
) == NOTOK
)
454 adios (NULL
, "%s", response
);
458 adios (NULL
, "no mail to incorporate");
463 * We will get the mail from a file
464 * (typically the standard maildrop)
467 if (inc_type
== INC_FILE
) {
470 else if ((newmail
= getenv ("MAILDROP")) && *newmail
)
471 newmail
= m_mailpath (newmail
);
472 else if ((newmail
= context_find ("maildrop")) && *newmail
)
473 newmail
= m_mailpath (newmail
);
475 newmail
= concat (MAILDIR
, "/", MAILFIL
, NULL
);
477 if (stat (newmail
, &s1
) == NOTOK
|| s1
.st_size
== 0)
478 adios (NULL
, "no mail to incorporate");
479 if (s1
.st_mode
& S_IFDIR
) {
485 cp
= concat (newmail
, "/new", NULL
);
486 if ((md
= opendir(cp
)) == NULL
)
487 adios (NULL
, "unable to open %s", cp
);
488 while ((de
= readdir (md
)) != NULL
) {
489 if (de
->d_name
[0] == '.')
491 if (i
>= num_maildir_entries
) {
492 if ((Maildir
= realloc(Maildir
, sizeof(*Maildir
) * (2*i
+16))) == NULL
)
493 adios(NULL
, "not enough memory for %d messages", 2*i
+16);
494 num_maildir_entries
= 2*i
+16;
496 Maildir
[i
].filename
= concat (cp
, "/", de
->d_name
, NULL
);
497 if (stat(Maildir
[i
].filename
, &ms
) != 0)
498 adios (Maildir
[i
].filename
, "couldn't get delivery time");
499 Maildir
[i
].mtime
= ms
.st_mtime
;
504 cp
= concat (newmail
, "/cur", NULL
);
505 if ((md
= opendir(cp
)) == NULL
)
506 adios (NULL
, "unable to open %s", cp
);
507 while ((de
= readdir (md
)) != NULL
) {
508 if (de
->d_name
[0] == '.')
510 if (i
>= num_maildir_entries
) {
511 if ((Maildir
= realloc(Maildir
, sizeof(*Maildir
) * (2*i
+16))) == NULL
)
512 adios(NULL
, "not enough memory for %d messages", 2*i
+16);
513 num_maildir_entries
= 2*i
+16;
515 Maildir
[i
].filename
= concat (cp
, "/", de
->d_name
, NULL
);
516 if (stat(Maildir
[i
].filename
, &ms
) != 0)
517 adios (Maildir
[i
].filename
, "couldn't get delivery time");
518 Maildir
[i
].mtime
= ms
.st_mtime
;
524 adios (NULL
, "no mail to incorporate");
525 num_maildir_entries
= i
;
526 qsort (Maildir
, num_maildir_entries
, sizeof(*Maildir
), maildir_srt
);
529 cp
= mh_xstrdup(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
);
542 maildir_copy
= mh_xstrdup(maildir
);
544 if (!folder_exists(maildir
)) {
545 /* If the folder doesn't exist, and we're given the -silent flag,
549 create_folder(maildir
, 0, done
);
554 if (chdir (maildir
) == NOTOK
)
555 adios (maildir
, "unable to change directory to");
557 /* read folder and create message structure */
558 if (!(mp
= folder_read (folder
, 0)))
559 adios (NULL
, "unable to read folder %s", folder
);
563 if (inc_type
== INC_FILE
&& Maildir
== NULL
) {
564 if (access (newmail
, W_OK
) != NOTOK
) {
567 SIGNAL (SIGHUP
, SIG_IGN
);
568 SIGNAL (SIGINT
, SIG_IGN
);
569 SIGNAL (SIGQUIT
, SIG_IGN
);
570 SIGNAL (SIGTERM
, SIG_IGN
);
573 GETGROUPPRIVS(); /* Reset gid to lock mail file */
574 in
= lkfopenspool (newmail
, "r");
577 adios (NULL
, "unable to lock and fopen %s", newmail
);
578 fstat (fileno(in
), &s1
);
581 if ((in
= fopen (newmail
, "r")) == NULL
)
582 adios (newmail
, "unable to read");
586 /* This shouldn't be necessary but it can't hurt. */
591 if ((i
= stat (audfile
, &st
)) == NOTOK
)
592 inform("Creating Receive-Audit: %s", audfile
);
593 if ((aud
= fopen (audfile
, "a")) == NULL
)
594 adios (audfile
, "unable to append to");
596 chmod (audfile
, m_gmprot ());
599 fprintf (aud
, "<<inc>> %s -ms %s\n", dtimenow(0), from
);
602 fprintf (aud
, "<<inc>> %s -host %s -user %s\n", dtimenow(0),
605 fprintf (aud
, "<<inc>> %s\n", dtimenow (0));
609 /* Get new format string */
610 nfs
= new_fs (form
, format
, FORMAT
);
613 printf ("Incorporating new mail into %s...\n\n", folder
);
619 * Get the mail from a POP server
621 if (inc_type
== INC_POP
) {
624 packfile
= path (packfile
, TFILE
);
625 if (stat (packfile
, &st
) == NOTOK
) {
627 adios (packfile
, "error on file");
628 cp
= concat ("Create file \"", packfile
, "\"? ", NULL
);
629 if (noisy
&& !read_yes_or_no_if_tty (cp
))
633 msgnum
= map_count ();
634 if ((pd
= mbx_open (packfile
, mbx_style
, getuid(), getgid(), m_gmprot()))
636 adios (packfile
, "unable to open");
637 if ((pf
= fdopen (pd
, "w+")) == NULL
)
638 adios (NULL
, "unable to fdopen %s", packfile
);
640 hghnum
= msgnum
= mp
->hghmsg
;
643 for (i
= 1; i
<= nmsgs
; i
++) {
644 charstring_t scanl
= NULL
;
650 fseek (pf
, 0L, SEEK_CUR
);
653 len
= strlen(mmdlm1
);
654 if (fwrite(mmdlm1
, 1, len
, pf
) < len
)
655 advise (mmdlm1
, "fwrite");
658 if (pop_retr (i
, pop_pack
) == NOTOK
)
659 adios (NULL
, "%s", response
);
661 fseek (pf
, 0L, SEEK_CUR
);
664 adios (packfile
, "write error on");
665 fseek (pf
, start
, SEEK_SET
);
667 cp
= mh_xstrdup(m_name (msgnum
));
668 if ((pf
= fopen (cp
, "w+")) == NULL
)
669 adios (cp
, "unable to write");
670 chmod (cp
, m_gmprot ());
673 if (pop_retr (i
, pop_action
) == NOTOK
)
674 adios (NULL
, "%s", response
);
677 adios (cp
, "write error on");
678 fseek (pf
, 0L, SEEK_SET
);
680 switch (incerr
= scan (pf
, msgnum
, 0, nfs
, width
,
681 packfile
? 0 : msgnum
== mp
->hghmsg
+ 1 && chgflag
,
682 1, NULL
, stop
- start
, noisy
, &scanl
)) {
684 printf ("%*d empty\n", DMAXFOLDER
, msgnum
);
690 /* advise (cp, "unable to read"); already advised */
701 fputs (charstring_buffer (scanl
), aud
);
706 charstring_free (scanl
);
711 fseek (pf
, stop
, SEEK_SET
);
712 len
= strlen(mmdlm2
);
713 if (fwrite(mmdlm2
, 1, len
, pf
) < len
)
714 advise (mmdlm2
, "fwrite");
715 if (fflush (pf
) || ferror (pf
)) {
719 adios (packfile
, "write error on");
721 map_write (packfile
, pd
, 0, 0L, start
, stop
, pos
, size
, noisy
);
723 if (ferror(pf
) || fclose (pf
)) {
725 (void) m_unlink (cp
);
728 adios (cp
, "write error on");
733 if (trnflag
&& pop_dele (i
) == NOTOK
)
734 adios (NULL
, "%s", response
);
739 if (pop_quit () == NOTOK
)
740 adios (NULL
, "%s", response
);
742 mbx_close (packfile
, pd
);
748 * Get the mail from file (usually mail spool)
750 if (inc_type
== INC_FILE
&& Maildir
== NULL
) {
751 scan_detect_mbox_style (in
); /* the MAGIC invocation... */
752 hghnum
= msgnum
= mp
->hghmsg
;
754 charstring_t scanl
= NULL
;
756 /* create scanline for new message */
757 switch (incerr
= scan (in
, msgnum
+ 1, msgnum
+ 1, nfs
, width
,
758 msgnum
== hghnum
&& chgflag
, 1, NULL
, 0L, noisy
,
766 fputs ("inc aborted!\n", aud
);
767 inform("aborted!"); /* doesn't clean up locks! */
771 inform("BUG in %s, number out of range", invo_name
);
775 inform("BUG in %s, scan() botch (%d)", invo_name
, incerr
);
781 * Run the external program hook on the message.
784 (void)snprintf(b
, sizeof (b
), "%s/%d", maildir_copy
, msgnum
+ 1);
785 (void)ext_hook("add-hook", b
, NULL
);
788 fputs (charstring_buffer (scanl
), aud
);
795 charstring_free (scanl
);
797 /* If we get here there was some sort of error from scan(),
798 * so stop processing anything more from the spool.
802 } else if (inc_type
== INC_FILE
) { /* Maildir inbox to process */
807 hghnum
= msgnum
= mp
->hghmsg
;
808 for (i
= 0; i
< num_maildir_entries
; i
++) {
809 charstring_t scanl
= NULL
;
813 sp
= Maildir
[i
].filename
;
814 cp
= mh_xstrdup(m_name (msgnum
));
816 if (!trnflag
|| link(sp
, cp
) == -1) {
817 static char buf
[65536];
820 if ((sf
= fopen (sp
, "r")) == NULL
)
821 adios (sp
, "unable to read for copy");
822 if ((pf
= fopen (cp
, "w+")) == NULL
)
823 adios (cp
, "unable to write for copy");
824 while ((nrd
= fread(buf
, 1, sizeof(buf
), sf
)) > 0)
825 if (fwrite(buf
, 1, nrd
, pf
) != nrd
)
827 if (ferror(sf
) || fflush(pf
) || ferror(pf
)) {
829 fclose(pf
); fclose(sf
); (void) m_unlink(cp
);
831 adios(cp
, "copy error %s -> %s", sp
, cp
);
836 if (pf
== NULL
&& (pf
= fopen (cp
, "r")) == NULL
)
837 adios (cp
, "not available");
838 chmod (cp
, m_gmprot ());
840 fseek (pf
, 0L, SEEK_SET
);
841 switch (incerr
= scan (pf
, msgnum
, 0, nfs
, width
,
842 msgnum
== mp
->hghmsg
+ 1 && chgflag
,
843 1, NULL
, stop
- start
, noisy
, &scanl
)) {
845 printf ("%*d empty\n", DMAXFOLDER
, msgnum
);
851 /* advise (cp, "unable to read"); already advised */
862 * Run the external program hook on the message.
865 (void)snprintf(b
, sizeof (b
), "%s/%d", maildir_copy
, msgnum
+ 1);
866 (void)ext_hook("add-hook", b
, NULL
);
869 fputs (charstring_buffer (scanl
), aud
);
874 charstring_free (scanl
);
876 if (ferror(pf
) || fclose (pf
)) {
878 (void) m_unlink (cp
);
880 adios (cp
, "write error on");
885 if (trnflag
&& m_unlink (sp
) == NOTOK
)
886 adios (sp
, "couldn't unlink");
887 free (sp
); /* Free Maildir[i]->filename */
891 free (Maildir
); /* From now on Maildir is just a flag - don't dref! */
896 if (incerr
< 0) { /* error */
898 GETGROUPPRIVS(); /* Be sure we can unlock mail file */
899 (void) lkfclosespool (in
, newmail
); in
= NULL
;
900 DROPGROUPPRIVS(); /* And then return us to normal privileges */
902 fclose (in
); in
= NULL
;
904 adios (NULL
, "failed");
913 if ((inc_type
== INC_POP
) && packfile
)
917 * truncate file we are incorporating from
919 if (inc_type
== INC_FILE
&& Maildir
== NULL
) {
921 if (stat (newmail
, &st
) != NOTOK
&& s1
.st_mtime
!= st
.st_mtime
)
922 inform("new messages have arrived!\007");
925 if ((newfd
= creat (newmail
, 0600)) != NOTOK
)
928 admonish (newmail
, "error zero'ing");
929 (void) m_unlink(map_name(newmail
));
933 printf ("%s not zero'd\n", newmail
);
937 if (msgnum
== hghnum
) {
938 inform("no messages incorporated, continuing...");
941 * Lock the sequence file now, and loop to set the right flags
942 * in the folder structure
948 context_replace (pfolder
, folder
); /* update current folder */
950 if ((mp2
= folder_read(folder
, 1)) == NULL
) {
951 inform("Unable to reread folder %s, continuing...", folder
);
956 * Shouldn't happen, but just in case ...
959 if (msgnum
>= mp2
->hghoff
960 && !(mp2
= folder_realloc (mp2
, mp2
->lowoff
, msgnum
+ 1))) {
961 inform("unable to reallocate folder storage");
966 mp2
->curmsg
= hghnum
+ 1;
967 mp2
->hghmsg
= msgnum
;
969 if (mp2
->lowmsg
== 0)
971 if (chgflag
) /* sigh... */
972 seq_setcur (mp2
, mp2
->curmsg
);
974 for (i
= hghnum
+ 1; i
<= msgnum
; i
++) {
975 clear_msg_flags (mp2
, i
);
979 mp2
->msgflags
|= SEQMOD
;
980 seq_setunseen(mp2
, 0); /* Set the Unseen-Sequence */
981 seq_save(mp2
); /* Save the sequence file */
987 * unlock the mail spool
989 if (inc_type
== INC_FILE
&& Maildir
== NULL
) {
991 GETGROUPPRIVS(); /* Be sure we can unlock mail file */
992 (void) lkfclosespool (in
, newmail
); in
= NULL
;
993 DROPGROUPPRIVS(); /* And then return us to normal privileges */
995 fclose (in
); in
= NULL
;
999 context_save (); /* save the context file */
1006 inc_done (int status
)
1009 if (packfile
&& pd
!= NOTOK
)
1010 mbx_close (packfile
, pd
);
1014 lkfclosespool(in
, newmail
);
1021 pop_action (char *s
)
1023 fprintf (pf
, "%s\n", s
);
1024 stop
+= strlen (s
) + 1;
1025 return 0; /* Is return value used? This was missing before 1999-07-15. */
1032 char buffer
[BUFSIZ
];
1034 snprintf (buffer
, sizeof(buffer
), "%s\n", s
);
1035 for ( ; (j
= stringdex (mmdlm1
, buffer
)) >= 0; buffer
[j
]++)
1037 for ( ; (j
= stringdex (mmdlm2
, buffer
)) >= 0; buffer
[j
]++)
1040 size
+= strlen (buffer
) + 1;
1041 return 0; /* Is return value used? This was missing before 1999-07-15. */
1052 if (stat (packfile
, &st
) == NOTOK
)
1054 if ((md
= open (cp
= map_name (packfile
), O_RDONLY
)) == NOTOK
1055 || map_chk (cp
, md
, &d
, (long) st
.st_size
, 1)) {