]>
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 if (a
->mtime
< b
->mtime
)
185 main (int argc
, char **argv
)
187 int chgflag
= 1, trnflag
= 1;
188 int noisy
= 1, width
= -1;
189 int hghnum
= 0, msgnum
= 0;
190 int sasl
= 0, tls
= 0;
191 int incerr
= 0; /* <0 if inc hits an error which means it should not truncate mailspool */
192 char *cp
, *maildir
= NULL
, *folder
= NULL
;
193 char *format
= NULL
, *form
= NULL
;
194 char *host
= NULL
, *port
= NULL
, *user
= NULL
, *proxy
= NULL
;
195 char *audfile
= NULL
, *from
= NULL
, *saslmech
= NULL
, *auth_svc
= NULL
;
196 char buf
[BUFSIZ
], **argp
, *nfs
, **arguments
;
197 struct msgs
*mp
= NULL
;
200 char b
[PATH_MAX
+ 1];
201 char *maildir_copy
= NULL
; /* copy of mail directory because the static gets overwritten */
204 char *MAILHOST_env_variable
;
207 /* absolutely the first thing we do is save our privileges,
208 * and drop them if we can.
213 if (nmh_init(argv
[0], 1)) { return 1; }
216 arguments
= getarguments (invo_name
, argc
, argv
, 1);
221 * use MAILHOST environment variable if present,
223 * If that fails, use the default (if any)
224 * provided by mts.conf in mts_init()
226 if ((MAILHOST_env_variable
= getenv("MAILHOST")) != NULL
)
227 pophost
= MAILHOST_env_variable
;
229 * If there is a valid "pophost" entry in mts.conf,
230 * then use it as the default host.
232 if (pophost
&& *pophost
)
235 while ((cp
= *argp
++)) {
237 switch (smatch (++cp
, switches
)) {
239 ambigsw (cp
, switches
);
242 adios (NULL
, "-%s unknown", cp
);
245 snprintf (buf
, sizeof(buf
), "%s [+folder] [switches]", invo_name
);
246 print_help (buf
, switches
, 1);
249 print_version(invo_name
);
253 if (!(cp
= *argp
++) || *cp
== '-')
254 adios (NULL
, "missing argument to %s", argp
[-2]);
255 audfile
= getcpy (m_maildir (cp
));
269 * The flag `trnflag' has the value:
271 * 2 if -truncate is given
272 * 1 by default (truncating is default)
273 * 0 if -notruncate is given
283 if (!(cp
= *argp
++) || *cp
== '-')
284 adios (NULL
, "missing argument to %s", argp
[-2]);
285 from
= path (cp
, TFILE
);
288 * If the truncate file is in default state,
289 * change to not truncate.
303 if (!(form
= *argp
++) || *form
== '-')
304 adios (NULL
, "missing argument to %s", argp
[-2]);
308 if (!(format
= *argp
++) || *format
== '-')
309 adios (NULL
, "missing argument to %s", argp
[-2]);
314 if (!(cp
= *argp
++) || *cp
== '-')
315 adios (NULL
, "missing argument to %s", argp
[-2]);
320 if (!(host
= *argp
++) || *host
== '-')
321 adios (NULL
, "missing argument to %s", argp
[-2]);
325 if (!(port
= *argp
++) || *port
== '-')
326 adios (NULL
, "missing argument to %s", argp
[-2]);
330 if (!(user
= *argp
++) || *user
== '-')
331 adios (NULL
, "missing argument to %s", argp
[-2]);
335 if (!(packfile
= *argp
++) || *packfile
== '-')
336 adios (NULL
, "missing argument to %s", argp
[-2]);
354 if (!(saslmech
= *argp
++) || *saslmech
== '-')
355 adios (NULL
, "missing argument to %s", argp
[-2]);
368 if (!(auth_svc
= *argp
++) || *auth_svc
== '-')
369 adios (NULL
, "missing argument to %s", argp
[-2]);
371 adios (NULL
, "not built with OAuth support");
376 if (!(proxy
= *argp
++) || *proxy
== '-')
377 adios (NULL
, "missing argument to %s", argp
[-2]);
381 if (*cp
== '+' || *cp
== '@') {
383 adios (NULL
, "only one folder at a time!");
385 folder
= pluspath (cp
);
387 adios (NULL
, "usage: %s [+folder] [switches]", invo_name
);
391 /* NOTE: above this point you should use TRYDROPGROUPPRIVS(),
392 * not DROPGROUPPRIVS().
397 /* guarantee dropping group priveleges; we might not have done so earlier */
401 * Where are we getting the new mail?
411 * Are we getting the mail from
414 if (inc_type
== INC_POP
) {
415 if (auth_svc
== NULL
) {
416 if (saslmech
&& ! strcasecmp(saslmech
, "xoauth2")) {
417 adios (NULL
, "must specify -authservice with -saslmech xoauth2");
421 adios (NULL
, "must specify -user with -saslmech xoauth2");
426 * initialize POP connection
428 if (pop_init (host
, port
, user
, proxy
, snoop
, sasl
, saslmech
,
429 tls
, auth_svc
) == NOTOK
)
430 adios (NULL
, "%s", response
);
432 /* Check if there are any messages */
433 if (pop_stat (&nmsgs
, &nbytes
) == NOTOK
)
434 adios (NULL
, "%s", response
);
438 adios (NULL
, "no mail to incorporate");
443 * We will get the mail from a file
444 * (typically the standard maildrop)
447 if (inc_type
== INC_FILE
) {
450 else if ((newmail
= getenv ("MAILDROP")) && *newmail
)
451 newmail
= m_mailpath (newmail
);
452 else if ((newmail
= context_find ("maildrop")) && *newmail
)
453 newmail
= m_mailpath (newmail
);
455 newmail
= concat (MAILDIR
, "/", MAILFIL
, NULL
);
457 if (stat (newmail
, &s1
) == NOTOK
|| s1
.st_size
== 0)
458 adios (NULL
, "no mail to incorporate");
459 if (s1
.st_mode
& S_IFDIR
) {
465 cp
= concat (newmail
, "/new", NULL
);
466 if ((md
= opendir(cp
)) == NULL
)
467 adios (NULL
, "unable to open %s", cp
);
468 while ((de
= readdir (md
)) != NULL
) {
469 if (de
->d_name
[0] == '.')
471 if (i
>= num_maildir_entries
) {
472 if ((Maildir
= realloc(Maildir
, sizeof(*Maildir
) * (2*i
+16))) == NULL
)
473 adios(NULL
, "not enough memory for %d messages", 2*i
+16);
474 num_maildir_entries
= 2*i
+16;
476 Maildir
[i
].filename
= concat (cp
, "/", de
->d_name
, NULL
);
477 if (stat(Maildir
[i
].filename
, &ms
) != 0)
478 adios (Maildir
[i
].filename
, "couldn't get delivery time");
479 Maildir
[i
].mtime
= ms
.st_mtime
;
484 cp
= concat (newmail
, "/cur", NULL
);
485 if ((md
= opendir(cp
)) == NULL
)
486 adios (NULL
, "unable to open %s", cp
);
487 while ((de
= readdir (md
)) != NULL
) {
488 if (de
->d_name
[0] == '.')
490 if (i
>= num_maildir_entries
) {
491 if ((Maildir
= realloc(Maildir
, sizeof(*Maildir
) * (2*i
+16))) == NULL
)
492 adios(NULL
, "not enough memory for %d messages", 2*i
+16);
493 num_maildir_entries
= 2*i
+16;
495 Maildir
[i
].filename
= concat (cp
, "/", de
->d_name
, NULL
);
496 if (stat(Maildir
[i
].filename
, &ms
) != 0)
497 adios (Maildir
[i
].filename
, "couldn't get delivery time");
498 Maildir
[i
].mtime
= ms
.st_mtime
;
504 adios (NULL
, "no mail to incorporate");
505 num_maildir_entries
= i
;
506 qsort (Maildir
, num_maildir_entries
, sizeof(*Maildir
), maildir_srt
);
509 if ((cp
= strdup(newmail
)) == NULL
)
510 adios (NULL
, "error allocating memory to copy newmail");
515 /* skip the folder setup */
516 if ((inc_type
== INC_POP
) && packfile
)
519 if (!context_find ("path"))
520 free (path ("./", TFOLDER
));
522 folder
= getfolder (0);
523 maildir
= m_maildir (folder
);
525 if ((maildir_copy
= strdup(maildir
)) == NULL
)
526 adios (maildir
, "error allocating memory to copy maildir");
528 if (!folder_exists(maildir
)) {
529 /* If the folder doesn't exist, and we're given the -silent flag,
533 create_folder(maildir
, 0, done
);
538 if (chdir (maildir
) == NOTOK
)
539 adios (maildir
, "unable to change directory to");
541 /* read folder and create message structure */
542 if (!(mp
= folder_read (folder
, 0)))
543 adios (NULL
, "unable to read folder %s", folder
);
547 if (inc_type
== INC_FILE
&& Maildir
== NULL
) {
548 if (access (newmail
, W_OK
) != NOTOK
) {
551 SIGNAL (SIGHUP
, SIG_IGN
);
552 SIGNAL (SIGINT
, SIG_IGN
);
553 SIGNAL (SIGQUIT
, SIG_IGN
);
554 SIGNAL (SIGTERM
, SIG_IGN
);
557 GETGROUPPRIVS(); /* Reset gid to lock mail file */
558 in
= lkfopenspool (newmail
, "r");
561 adios (NULL
, "unable to lock and fopen %s", newmail
);
562 fstat (fileno(in
), &s1
);
565 if ((in
= fopen (newmail
, "r")) == NULL
)
566 adios (newmail
, "unable to read");
570 /* This shouldn't be necessary but it can't hurt. */
575 if ((i
= stat (audfile
, &st
)) == NOTOK
)
576 advise (NULL
, "Creating Receive-Audit: %s", audfile
);
577 if ((aud
= fopen (audfile
, "a")) == NULL
)
578 adios (audfile
, "unable to append to");
580 chmod (audfile
, m_gmprot ());
583 fprintf (aud
, "<<inc>> %s -ms %s\n", dtimenow(0), from
);
586 fprintf (aud
, "<<inc>> %s -host %s -user %s\n", dtimenow(0),
589 fprintf (aud
, "<<inc>> %s\n", dtimenow (0));
593 /* Get new format string */
594 nfs
= new_fs (form
, format
, FORMAT
);
597 printf ("Incorporating new mail into %s...\n\n", folder
);
603 * Get the mail from a POP server
605 if (inc_type
== INC_POP
) {
608 packfile
= path (packfile
, TFILE
);
609 if (stat (packfile
, &st
) == NOTOK
) {
611 adios (packfile
, "error on file");
612 cp
= concat ("Create file \"", packfile
, "\"? ", NULL
);
613 if (noisy
&& !read_yes_or_no_if_tty (cp
))
617 msgnum
= map_count ();
618 if ((pd
= mbx_open (packfile
, mbx_style
, getuid(), getgid(), m_gmprot()))
620 adios (packfile
, "unable to open");
621 if ((pf
= fdopen (pd
, "w+")) == NULL
)
622 adios (NULL
, "unable to fdopen %s", packfile
);
624 hghnum
= msgnum
= mp
->hghmsg
;
627 for (i
= 1; i
<= nmsgs
; i
++) {
628 charstring_t scanl
= NULL
;
634 fseek (pf
, 0L, SEEK_CUR
);
637 len
= strlen(mmdlm1
);
638 if (fwrite(mmdlm1
, 1, len
, pf
) < len
)
639 advise (mmdlm1
, "fwrite");
642 if (pop_retr (i
, pop_pack
) == NOTOK
)
643 adios (NULL
, "%s", response
);
645 fseek (pf
, 0L, SEEK_CUR
);
648 adios (packfile
, "write error on");
649 fseek (pf
, start
, SEEK_SET
);
651 cp
= mh_xstrdup(m_name (msgnum
));
652 if ((pf
= fopen (cp
, "w+")) == NULL
)
653 adios (cp
, "unable to write");
654 chmod (cp
, m_gmprot ());
657 if (pop_retr (i
, pop_action
) == NOTOK
)
658 adios (NULL
, "%s", response
);
661 adios (cp
, "write error on");
662 fseek (pf
, 0L, SEEK_SET
);
664 switch (incerr
= scan (pf
, msgnum
, 0, nfs
, width
,
665 packfile
? 0 : msgnum
== mp
->hghmsg
+ 1 && chgflag
,
666 1, NULL
, stop
- start
, noisy
, &scanl
)) {
668 printf ("%*d empty\n", DMAXFOLDER
, msgnum
);
674 /* advise (cp, "unable to read"); already advised */
685 fputs (charstring_buffer (scanl
), aud
);
690 charstring_free (scanl
);
695 fseek (pf
, stop
, SEEK_SET
);
696 len
= strlen(mmdlm2
);
697 if (fwrite(mmdlm2
, 1, len
, pf
) < len
)
698 advise (mmdlm2
, "fwrite");
699 if (fflush (pf
) || ferror (pf
)) {
703 adios (packfile
, "write error on");
705 map_write (packfile
, pd
, 0, 0L, start
, stop
, pos
, size
, noisy
);
707 if (ferror(pf
) || fclose (pf
)) {
709 (void) m_unlink (cp
);
712 adios (cp
, "write error on");
717 if (trnflag
&& pop_dele (i
) == NOTOK
)
718 adios (NULL
, "%s", response
);
723 if (pop_quit () == NOTOK
)
724 adios (NULL
, "%s", response
);
726 mbx_close (packfile
, pd
);
732 * Get the mail from file (usually mail spool)
734 if (inc_type
== INC_FILE
&& Maildir
== NULL
) {
735 scan_detect_mbox_style (in
); /* the MAGIC invocation... */
736 hghnum
= msgnum
= mp
->hghmsg
;
738 charstring_t scanl
= NULL
;
740 /* create scanline for new message */
741 switch (incerr
= scan (in
, msgnum
+ 1, msgnum
+ 1, nfs
, width
,
742 msgnum
== hghnum
&& chgflag
, 1, NULL
, 0L, noisy
,
750 fputs ("inc aborted!\n", aud
);
751 advise (NULL
, "aborted!"); /* doesn't clean up locks! */
755 advise (NULL
, "BUG in %s, number out of range", invo_name
);
759 advise (NULL
, "BUG in %s, scan() botch (%d)", invo_name
, incerr
);
765 * Run the external program hook on the message.
768 (void)snprintf(b
, sizeof (b
), "%s/%d", maildir_copy
, msgnum
+ 1);
769 (void)ext_hook("add-hook", b
, NULL
);
772 fputs (charstring_buffer (scanl
), aud
);
779 charstring_free (scanl
);
781 /* If we get here there was some sort of error from scan(),
782 * so stop processing anything more from the spool.
786 } else if (inc_type
== INC_FILE
) { /* Maildir inbox to process */
791 hghnum
= msgnum
= mp
->hghmsg
;
792 for (i
= 0; i
< num_maildir_entries
; i
++) {
793 charstring_t scanl
= NULL
;
797 sp
= Maildir
[i
].filename
;
798 cp
= mh_xstrdup(m_name (msgnum
));
800 if (!trnflag
|| link(sp
, cp
) == -1) {
801 static char buf
[65536];
804 if ((sf
= fopen (sp
, "r")) == NULL
)
805 adios (sp
, "unable to read for copy");
806 if ((pf
= fopen (cp
, "w+")) == NULL
)
807 adios (cp
, "unable to write for copy");
808 while ((nrd
= fread(buf
, 1, sizeof(buf
), sf
)) > 0)
809 if (fwrite(buf
, 1, nrd
, pf
) != nrd
)
811 if (ferror(sf
) || fflush(pf
) || ferror(pf
)) {
813 fclose(pf
); fclose(sf
); (void) m_unlink(cp
);
815 adios(cp
, "copy error %s -> %s", sp
, cp
);
820 if (pf
== NULL
&& (pf
= fopen (cp
, "r")) == NULL
)
821 adios (cp
, "not available");
822 chmod (cp
, m_gmprot ());
824 fseek (pf
, 0L, SEEK_SET
);
825 switch (incerr
= scan (pf
, msgnum
, 0, nfs
, width
,
826 msgnum
== mp
->hghmsg
+ 1 && chgflag
,
827 1, NULL
, stop
- start
, noisy
, &scanl
)) {
829 printf ("%*d empty\n", DMAXFOLDER
, msgnum
);
835 /* advise (cp, "unable to read"); already advised */
846 * Run the external program hook on the message.
849 (void)snprintf(b
, sizeof (b
), "%s/%d", maildir_copy
, msgnum
+ 1);
850 (void)ext_hook("add-hook", b
, NULL
);
853 fputs (charstring_buffer (scanl
), aud
);
858 charstring_free (scanl
);
860 if (ferror(pf
) || fclose (pf
)) {
862 (void) m_unlink (cp
);
864 adios (cp
, "write error on");
869 if (trnflag
&& m_unlink (sp
) == NOTOK
)
870 adios (sp
, "couldn't unlink");
871 free (sp
); /* Free Maildir[i]->filename */
875 free (Maildir
); /* From now on Maildir is just a flag - don't dref! */
880 if (incerr
< 0) { /* error */
882 GETGROUPPRIVS(); /* Be sure we can unlock mail file */
883 (void) lkfclosespool (in
, newmail
); in
= NULL
;
884 DROPGROUPPRIVS(); /* And then return us to normal privileges */
886 fclose (in
); in
= NULL
;
888 adios (NULL
, "failed");
897 if ((inc_type
== INC_POP
) && packfile
)
901 * truncate file we are incorporating from
903 if (inc_type
== INC_FILE
&& Maildir
== NULL
) {
905 if (stat (newmail
, &st
) != NOTOK
&& s1
.st_mtime
!= st
.st_mtime
)
906 advise (NULL
, "new messages have arrived!\007");
909 if ((newfd
= creat (newmail
, 0600)) != NOTOK
)
912 admonish (newmail
, "error zero'ing");
913 (void) m_unlink(map_name(newmail
));
917 printf ("%s not zero'd\n", newmail
);
921 if (msgnum
== hghnum
) {
922 admonish (NULL
, "no messages incorporated");
925 * Lock the sequence file now, and loop to set the right flags
926 * in the folder structure
932 context_replace (pfolder
, folder
); /* update current folder */
934 if ((mp2
= folder_read(folder
, 1)) == NULL
) {
935 admonish(NULL
, "Unable to reread folder %s", folder
);
940 * Shouldn't happen, but just in case ...
943 if (msgnum
>= mp2
->hghoff
944 && !(mp2
= folder_realloc (mp2
, mp2
->lowoff
, msgnum
+ 1))) {
945 advise (NULL
, "unable to reallocate folder storage");
950 mp2
->curmsg
= hghnum
+ 1;
951 mp2
->hghmsg
= msgnum
;
953 if (mp2
->lowmsg
== 0)
955 if (chgflag
) /* sigh... */
956 seq_setcur (mp2
, mp2
->curmsg
);
958 for (i
= hghnum
+ 1; i
<= msgnum
; i
++) {
959 clear_msg_flags (mp2
, i
);
963 mp2
->msgflags
|= SEQMOD
;
964 seq_setunseen(mp2
, 0); /* Set the Unseen-Sequence */
965 seq_save(mp2
); /* Save the sequence file */
971 * unlock the mail spool
973 if (inc_type
== INC_FILE
&& Maildir
== NULL
) {
975 GETGROUPPRIVS(); /* Be sure we can unlock mail file */
976 (void) lkfclosespool (in
, newmail
); in
= NULL
;
977 DROPGROUPPRIVS(); /* And then return us to normal privileges */
979 fclose (in
); in
= NULL
;
983 context_save (); /* save the context file */
990 inc_done (int status
)
993 if (packfile
&& pd
!= NOTOK
)
994 mbx_close (packfile
, pd
);
998 lkfclosespool(in
, newmail
);
1005 pop_action (char *s
)
1007 fprintf (pf
, "%s\n", s
);
1008 stop
+= strlen (s
) + 1;
1009 return 0; /* Is return value used? This was missing before 1999-07-15. */
1016 char buffer
[BUFSIZ
];
1018 snprintf (buffer
, sizeof(buffer
), "%s\n", s
);
1019 for ( ; (j
= stringdex (mmdlm1
, buffer
)) >= 0; buffer
[j
]++)
1021 for ( ; (j
= stringdex (mmdlm2
, buffer
)) >= 0; buffer
[j
]++)
1024 size
+= strlen (buffer
) + 1;
1025 return 0; /* Is return value used? This was missing before 1999-07-15. */
1036 if (stat (packfile
, &st
) == NOTOK
)
1038 if ((md
= open (cp
= map_name (packfile
), O_RDONLY
)) == NOTOK
1039 || map_chk (cp
, md
, &d
, (long) st
.st_size
, 1)) {