]>
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 SASLminc(a) (a)
49 # define SASLminc(a) 0
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", -5, SNOOPSW) \
73 X("sasl", SASLminc(5), SASLSW) \
74 X("nosasl", SASLminc(3), NOSASLSW) \
75 X("saslmech", SASLminc(5), SASLMECHSW) \
76 X("authservice", SASLminc(0), AUTHSERVICESW) \
77 X("proxy command", 0, PROXYSW) \
79 #define X(sw, minchars, id) id,
80 DEFINE_SWITCH_ENUM(INC
);
83 #define X(sw, minchars, id) { sw, minchars, id },
84 DEFINE_SWITCH_ARRAY(INC
, switches
);
88 * flags for the mail source
94 static struct Maildir_entry
{
98 static int num_maildir_entries
= 0;
101 extern char response
[];
106 static int mbx_style
= MMDF_FORMAT
;
107 static int pd
= NOTOK
;
112 static char *packfile
= NULL
;
113 static FILE *pf
= NULL
;
115 /* This is an attempt to simplify things by putting all the
116 * privilege ops into macros.
117 * *GROUPPRIVS() is related to handling the setgid MAIL property,
118 * and only applies if MAILGROUP is defined.
119 * Basically, SAVEGROUPPRIVS() is called right at the top of main()
120 * to initialise things, and then DROPGROUPPRIVS() and GETGROUPPRIVS()
121 * do the obvious thing.
123 * There's probably a better implementation if we're allowed to use
124 * BSD-style setreuid() rather than using POSIX saved-ids.
125 * Anyway, if you're euid root it's a bit pointless to drop the group
128 * I'm pretty happy that the security is good provided we aren't setuid root.
129 * The only things we trust with group=mail privilege are lkfopen()
134 * For setting and returning to "mail" gid
137 static gid_t return_gid
;
138 #define TRYDROPGROUPPRIVS() DROPGROUPPRIVS()
139 #define DROPGROUPPRIVS() \
140 if (setegid(getgid()) != 0) { \
141 adios ("setegid", "unable to restore group to %ld", (long) getgid()); \
143 #define GETGROUPPRIVS() \
144 if (setegid(return_gid) != 0) { \
145 adios ("setegid", "unable to set group to %ld", (long) return_gid); \
147 #define SAVEGROUPPRIVS() return_gid = getegid()
149 /* define *GROUPPRIVS() as null; this avoids having lots of "#ifdef MAILGROUP"s */
150 #define TRYDROPGROUPPRIVS()
151 #define DROPGROUPPRIVS()
152 #define GETGROUPPRIVS()
153 #define SAVEGROUPPRIVS()
154 #endif /* not MAILGROUP */
156 /* these variables have to be globals so that done() can correctly clean up the lockfile */
157 static int locked
= 0;
158 static char *newmail
;
164 char *map_name(char *);
166 static void inc_done(int) NORETURN
;
167 static int pop_action(char *);
168 static int pop_pack(char *);
169 static int map_count(void);
172 maildir_srt(const void *va
, const void *vb
)
174 const struct Maildir_entry
*a
= va
, *b
= vb
;
175 if (a
->mtime
> b
->mtime
)
177 else if (a
->mtime
< b
->mtime
)
184 main (int argc
, char **argv
)
186 int chgflag
= 1, trnflag
= 1;
187 int noisy
= 1, width
= -1;
188 int hghnum
= 0, msgnum
= 0;
190 int incerr
= 0; /* <0 if inc hits an error which means it should not truncate mailspool */
191 char *cp
, *maildir
= NULL
, *folder
= NULL
;
192 char *format
= NULL
, *form
= NULL
;
193 char *host
= NULL
, *port
= NULL
, *user
= NULL
, *proxy
= NULL
;
194 char *audfile
= NULL
, *from
= NULL
, *saslmech
= NULL
, *auth_svc
= NULL
;
195 char buf
[BUFSIZ
], **argp
, *nfs
, **arguments
;
196 struct msgs
*mp
= NULL
;
199 char b
[PATH_MAX
+ 1];
200 char *maildir_copy
= NULL
; /* copy of mail directory because the static gets overwritten */
203 char *MAILHOST_env_variable
;
206 /* absolutely the first thing we do is save our privileges,
207 * and drop them if we can.
212 if (nmh_init(argv
[0], 1)) { return 1; }
214 mts_init (invo_name
);
215 arguments
= getarguments (invo_name
, argc
, argv
, 1);
220 * use MAILHOST environment variable if present,
222 * If that fails, use the default (if any)
223 * provided by mts.conf in mts_init()
225 if ((MAILHOST_env_variable
= getenv("MAILHOST")) != NULL
)
226 pophost
= MAILHOST_env_variable
;
228 * If there is a valid "pophost" entry in mts.conf,
229 * then use it as the default host.
231 if (pophost
&& *pophost
)
234 while ((cp
= *argp
++)) {
236 switch (smatch (++cp
, switches
)) {
238 ambigsw (cp
, switches
);
241 adios (NULL
, "-%s unknown", cp
);
244 snprintf (buf
, sizeof(buf
), "%s [+folder] [switches]", invo_name
);
245 print_help (buf
, switches
, 1);
248 print_version(invo_name
);
252 if (!(cp
= *argp
++) || *cp
== '-')
253 adios (NULL
, "missing argument to %s", argp
[-2]);
254 audfile
= getcpy (m_maildir (cp
));
268 * The flag `trnflag' has the value:
270 * 2 if -truncate is given
271 * 1 by default (truncating is default)
272 * 0 if -notruncate is given
282 if (!(cp
= *argp
++) || *cp
== '-')
283 adios (NULL
, "missing argument to %s", argp
[-2]);
284 from
= path (cp
, TFILE
);
287 * If the truncate file is in default state,
288 * change to not truncate.
302 if (!(form
= *argp
++) || *form
== '-')
303 adios (NULL
, "missing argument to %s", argp
[-2]);
307 if (!(format
= *argp
++) || *format
== '-')
308 adios (NULL
, "missing argument to %s", argp
[-2]);
313 if (!(cp
= *argp
++) || *cp
== '-')
314 adios (NULL
, "missing argument to %s", argp
[-2]);
319 if (!(host
= *argp
++) || *host
== '-')
320 adios (NULL
, "missing argument to %s", argp
[-2]);
324 if (!(port
= *argp
++) || *port
== '-')
325 adios (NULL
, "missing argument to %s", argp
[-2]);
329 if (!(user
= *argp
++) || *user
== '-')
330 adios (NULL
, "missing argument to %s", argp
[-2]);
334 if (!(packfile
= *argp
++) || *packfile
== '-')
335 adios (NULL
, "missing argument to %s", argp
[-2]);
353 if (!(saslmech
= *argp
++) || *saslmech
== '-')
354 adios (NULL
, "missing argument to %s", argp
[-2]);
359 if (!(auth_svc
= *argp
++) || *auth_svc
== '-')
360 adios (NULL
, "missing argument to %s", argp
[-2]);
362 adios (NULL
, "not built with OAuth support");
367 if (!(proxy
= *argp
++) || *proxy
== '-')
368 adios (NULL
, "missing argument to %s", argp
[-2]);
372 if (*cp
== '+' || *cp
== '@') {
374 adios (NULL
, "only one folder at a time!");
376 folder
= pluspath (cp
);
378 adios (NULL
, "usage: %s [+folder] [switches]", invo_name
);
382 /* NOTE: above this point you should use TRYDROPGROUPPRIVS(),
383 * not DROPGROUPPRIVS().
388 /* guarantee dropping group priveleges; we might not have done so earlier */
392 * Where are we getting the new mail?
402 * Are we getting the mail from
405 if (inc_type
== INC_POP
) {
406 struct nmh_creds creds
= { 0, 0, 0 };
408 if (auth_svc
== NULL
) {
409 if (saslmech
&& ! strcasecmp(saslmech
, "xoauth2")) {
410 adios (NULL
, "must specify -authservice with -saslmech xoauth2");
412 nmh_get_credentials (host
, user
, sasl
, &creds
);
415 adios (NULL
, "must specify -user with -saslmech xoauth2");
421 * initialize POP connection
423 if (pop_init (host
, port
, creds
.user
, creds
.password
, proxy
, snoop
,
424 sasl
, saslmech
, auth_svc
) == NOTOK
)
425 adios (NULL
, "%s", response
);
427 /* Check if there are any messages */
428 if (pop_stat (&nmsgs
, &nbytes
) == NOTOK
)
429 adios (NULL
, "%s", response
);
433 adios (NULL
, "no mail to incorporate");
438 * We will get the mail from a file
439 * (typically the standard maildrop)
442 if (inc_type
== INC_FILE
) {
445 else if ((newmail
= getenv ("MAILDROP")) && *newmail
)
446 newmail
= m_mailpath (newmail
);
447 else if ((newmail
= context_find ("maildrop")) && *newmail
)
448 newmail
= m_mailpath (newmail
);
450 newmail
= concat (MAILDIR
, "/", MAILFIL
, NULL
);
452 if (stat (newmail
, &s1
) == NOTOK
|| s1
.st_size
== 0)
453 adios (NULL
, "no mail to incorporate");
454 if (s1
.st_mode
& S_IFDIR
) {
460 cp
= concat (newmail
, "/new", NULL
);
461 if ((md
= opendir(cp
)) == NULL
)
462 adios (NULL
, "unable to open %s", cp
);
463 while ((de
= readdir (md
)) != NULL
) {
464 if (de
->d_name
[0] == '.')
466 if (i
>= num_maildir_entries
) {
467 if ((Maildir
= realloc(Maildir
, sizeof(*Maildir
) * (2*i
+16))) == NULL
)
468 adios(NULL
, "not enough memory for %d messages", 2*i
+16);
469 num_maildir_entries
= 2*i
+16;
471 Maildir
[i
].filename
= concat (cp
, "/", de
->d_name
, NULL
);
472 if (stat(Maildir
[i
].filename
, &ms
) != 0)
473 adios (Maildir
[i
].filename
, "couldn't get delivery time");
474 Maildir
[i
].mtime
= ms
.st_mtime
;
479 cp
= concat (newmail
, "/cur", NULL
);
480 if ((md
= opendir(cp
)) == NULL
)
481 adios (NULL
, "unable to open %s", cp
);
482 while ((de
= readdir (md
)) != NULL
) {
483 if (de
->d_name
[0] == '.')
485 if (i
>= num_maildir_entries
) {
486 if ((Maildir
= realloc(Maildir
, sizeof(*Maildir
) * (2*i
+16))) == NULL
)
487 adios(NULL
, "not enough memory for %d messages", 2*i
+16);
488 num_maildir_entries
= 2*i
+16;
490 Maildir
[i
].filename
= concat (cp
, "/", de
->d_name
, NULL
);
491 if (stat(Maildir
[i
].filename
, &ms
) != 0)
492 adios (Maildir
[i
].filename
, "couldn't get delivery time");
493 Maildir
[i
].mtime
= ms
.st_mtime
;
499 adios (NULL
, "no mail to incorporate");
500 num_maildir_entries
= i
;
501 qsort (Maildir
, num_maildir_entries
, sizeof(*Maildir
), maildir_srt
);
504 if ((cp
= strdup(newmail
)) == (char *)0)
505 adios (NULL
, "error allocating memory to copy newmail");
510 /* skip the folder setup */
511 if ((inc_type
== INC_POP
) && packfile
)
514 if (!context_find ("path"))
515 free (path ("./", TFOLDER
));
517 folder
= getfolder (0);
518 maildir
= m_maildir (folder
);
520 if ((maildir_copy
= strdup(maildir
)) == (char *)0)
521 adios (maildir
, "error allocating memory to copy maildir");
523 if (!folder_exists(maildir
)) {
524 /* If the folder doesn't exist, and we're given the -silent flag,
528 create_folder(maildir
, 0, done
);
533 if (chdir (maildir
) == NOTOK
)
534 adios (maildir
, "unable to change directory to");
536 /* read folder and create message structure */
537 if (!(mp
= folder_read (folder
, 0)))
538 adios (NULL
, "unable to read folder %s", folder
);
542 if (inc_type
== INC_FILE
&& Maildir
== NULL
) {
543 if (access (newmail
, W_OK
) != NOTOK
) {
546 SIGNAL (SIGHUP
, SIG_IGN
);
547 SIGNAL (SIGINT
, SIG_IGN
);
548 SIGNAL (SIGQUIT
, SIG_IGN
);
549 SIGNAL (SIGTERM
, SIG_IGN
);
552 GETGROUPPRIVS(); /* Reset gid to lock mail file */
553 in
= lkfopenspool (newmail
, "r");
556 adios (NULL
, "unable to lock and fopen %s", newmail
);
557 fstat (fileno(in
), &s1
);
560 if ((in
= fopen (newmail
, "r")) == NULL
)
561 adios (newmail
, "unable to read");
565 /* This shouldn't be necessary but it can't hurt. */
570 if ((i
= stat (audfile
, &st
)) == NOTOK
)
571 advise (NULL
, "Creating Receive-Audit: %s", audfile
);
572 if ((aud
= fopen (audfile
, "a")) == NULL
)
573 adios (audfile
, "unable to append to");
575 chmod (audfile
, m_gmprot ());
578 fprintf (aud
, "<<inc>> %s -ms %s\n", dtimenow(0), from
);
581 fprintf (aud
, "<<inc>> %s -host %s -user %s\n", dtimenow(0),
584 fprintf (aud
, "<<inc>> %s\n", dtimenow (0));
588 /* Get new format string */
589 nfs
= new_fs (form
, format
, FORMAT
);
592 printf ("Incorporating new mail into %s...\n\n", folder
);
598 * Get the mail from a POP server
600 if (inc_type
== INC_POP
) {
603 packfile
= path (packfile
, TFILE
);
604 if (stat (packfile
, &st
) == NOTOK
) {
606 adios (packfile
, "error on file");
607 cp
= concat ("Create file \"", packfile
, "\"? ", NULL
);
608 if (noisy
&& !read_yes_or_no_if_tty (cp
))
612 msgnum
= map_count ();
613 if ((pd
= mbx_open (packfile
, mbx_style
, getuid(), getgid(), m_gmprot()))
615 adios (packfile
, "unable to open");
616 if ((pf
= fdopen (pd
, "w+")) == NULL
)
617 adios (NULL
, "unable to fdopen %s", packfile
);
619 hghnum
= msgnum
= mp
->hghmsg
;
622 for (i
= 1; i
<= nmsgs
; i
++) {
623 charstring_t scanl
= NULL
;
627 fseek (pf
, 0L, SEEK_CUR
);
630 if (fwrite (mmdlm1
, 1, strlen (mmdlm1
), pf
) < strlen (mmdlm1
)) {
631 advise (mmdlm1
, "fwrite");
635 if (pop_retr (i
, pop_pack
) == NOTOK
)
636 adios (NULL
, "%s", response
);
638 fseek (pf
, 0L, SEEK_CUR
);
641 adios (packfile
, "write error on");
642 fseek (pf
, start
, SEEK_SET
);
644 cp
= getcpy (m_name (msgnum
));
645 if ((pf
= fopen (cp
, "w+")) == NULL
)
646 adios (cp
, "unable to write");
647 chmod (cp
, m_gmprot ());
650 if (pop_retr (i
, pop_action
) == NOTOK
)
651 adios (NULL
, "%s", response
);
654 adios (cp
, "write error on");
655 fseek (pf
, 0L, SEEK_SET
);
657 switch (incerr
= scan (pf
, msgnum
, 0, nfs
, width
,
658 packfile
? 0 : msgnum
== mp
->hghmsg
+ 1 && chgflag
,
659 1, NULL
, stop
- start
, noisy
, &scanl
)) {
661 printf ("%*d empty\n", DMAXFOLDER
, msgnum
);
667 /* advise (cp, "unable to read"); already advised */
678 fputs (charstring_buffer (scanl
), aud
);
683 charstring_free (scanl
);
686 fseek (pf
, stop
, SEEK_SET
);
687 if (fwrite (mmdlm2
, 1, strlen (mmdlm2
), pf
) < strlen (mmdlm1
)) {
688 advise (mmdlm2
, "fwrite");
690 if (fflush (pf
) || ferror (pf
)) {
694 adios (packfile
, "write error on");
696 map_write (packfile
, pd
, 0, 0L, start
, stop
, pos
, size
, noisy
);
698 if (ferror(pf
) || fclose (pf
)) {
700 (void) m_unlink (cp
);
703 adios (cp
, "write error on");
708 if (trnflag
&& pop_dele (i
) == NOTOK
)
709 adios (NULL
, "%s", response
);
714 if (pop_quit () == NOTOK
)
715 adios (NULL
, "%s", response
);
717 mbx_close (packfile
, pd
);
723 * Get the mail from file (usually mail spool)
725 if (inc_type
== INC_FILE
&& Maildir
== NULL
) {
726 scan_detect_mbox_style (in
); /* the MAGIC invocation... */
727 hghnum
= msgnum
= mp
->hghmsg
;
729 charstring_t scanl
= NULL
;
731 /* create scanline for new message */
732 switch (incerr
= scan (in
, msgnum
+ 1, msgnum
+ 1, nfs
, width
,
733 msgnum
== hghnum
&& chgflag
, 1, NULL
, 0L, noisy
,
741 fputs ("inc aborted!\n", aud
);
742 advise (NULL
, "aborted!"); /* doesn't clean up locks! */
746 advise (NULL
, "BUG in %s, number out of range", invo_name
);
750 advise (NULL
, "BUG in %s, scan() botch (%d)", invo_name
, incerr
);
756 * Run the external program hook on the message.
759 (void)snprintf(b
, sizeof (b
), "%s/%d", maildir_copy
, msgnum
+ 1);
760 (void)ext_hook("add-hook", b
, (char *)0);
763 fputs (charstring_buffer (scanl
), aud
);
770 charstring_free (scanl
);
772 /* If we get here there was some sort of error from scan(),
773 * so stop processing anything more from the spool.
777 } else if (inc_type
== INC_FILE
) { /* Maildir inbox to process */
782 hghnum
= msgnum
= mp
->hghmsg
;
783 for (i
= 0; i
< num_maildir_entries
; i
++) {
784 charstring_t scanl
= NULL
;
788 sp
= Maildir
[i
].filename
;
789 cp
= getcpy (m_name (msgnum
));
791 if (!trnflag
|| link(sp
, cp
) == -1) {
792 static char buf
[65536];
795 if ((sf
= fopen (sp
, "r")) == NULL
)
796 adios (sp
, "unable to read for copy");
797 if ((pf
= fopen (cp
, "w+")) == NULL
)
798 adios (cp
, "unable to write for copy");
799 while ((nrd
= fread(buf
, 1, sizeof(buf
), sf
)) > 0)
800 if (fwrite(buf
, 1, nrd
, pf
) != nrd
)
802 if (ferror(sf
) || fflush(pf
) || ferror(pf
)) {
804 fclose(pf
); fclose(sf
); (void) m_unlink(cp
);
806 adios(cp
, "copy error %s -> %s", sp
, cp
);
811 if (pf
== NULL
&& (pf
= fopen (cp
, "r")) == NULL
)
812 adios (cp
, "not available");
813 chmod (cp
, m_gmprot ());
815 fseek (pf
, 0L, SEEK_SET
);
816 switch (incerr
= scan (pf
, msgnum
, 0, nfs
, width
,
817 msgnum
== mp
->hghmsg
+ 1 && chgflag
,
818 1, NULL
, stop
- start
, noisy
, &scanl
)) {
820 printf ("%*d empty\n", DMAXFOLDER
, msgnum
);
826 /* advise (cp, "unable to read"); already advised */
837 * Run the external program hook on the message.
840 (void)snprintf(b
, sizeof (b
), "%s/%d", maildir_copy
, msgnum
+ 1);
841 (void)ext_hook("add-hook", b
, (char *)0);
844 fputs (charstring_buffer (scanl
), aud
);
849 charstring_free (scanl
);
851 if (ferror(pf
) || fclose (pf
)) {
853 (void) m_unlink (cp
);
855 adios (cp
, "write error on");
860 if (trnflag
&& m_unlink (sp
) == NOTOK
)
861 adios (sp
, "couldn't unlink");
862 free (sp
); /* Free Maildir[i]->filename */
866 free (Maildir
); /* From now on Maildir is just a flag - don't dref! */
871 if (incerr
< 0) { /* error */
873 GETGROUPPRIVS(); /* Be sure we can unlock mail file */
874 (void) lkfclosespool (in
, newmail
); in
= NULL
;
875 DROPGROUPPRIVS(); /* And then return us to normal privileges */
877 fclose (in
); in
= NULL
;
879 adios (NULL
, "failed");
888 if ((inc_type
== INC_POP
) && packfile
)
892 * truncate file we are incorporating from
894 if (inc_type
== INC_FILE
&& Maildir
== NULL
) {
896 if (stat (newmail
, &st
) != NOTOK
&& s1
.st_mtime
!= st
.st_mtime
)
897 advise (NULL
, "new messages have arrived!\007");
900 if ((newfd
= creat (newmail
, 0600)) != NOTOK
)
903 admonish (newmail
, "error zero'ing");
904 (void) m_unlink(map_name(newmail
));
908 printf ("%s not zero'd\n", newmail
);
912 if (msgnum
== hghnum
) {
913 admonish (NULL
, "no messages incorporated");
916 * Lock the sequence file now, and loop to set the right flags
917 * in the folder structure
923 context_replace (pfolder
, folder
); /* update current folder */
925 if ((mp2
= folder_read(folder
, 1)) == NULL
) {
926 admonish(NULL
, "Unable to reread folder %s", folder
);
931 * Shouldn't happen, but just in case ...
934 if (msgnum
>= mp2
->hghoff
935 && !(mp2
= folder_realloc (mp2
, mp2
->lowoff
, msgnum
+ 1))) {
936 advise (NULL
, "unable to reallocate folder storage");
941 mp2
->curmsg
= hghnum
+ 1;
942 mp2
->hghmsg
= msgnum
;
944 if (mp2
->lowmsg
== 0)
946 if (chgflag
) /* sigh... */
947 seq_setcur (mp2
, mp2
->curmsg
);
949 for (i
= hghnum
+ 1; i
<= msgnum
; i
++) {
950 clear_msg_flags (mp2
, i
);
954 mp2
->msgflags
|= SEQMOD
;
955 seq_setunseen(mp2
, 0); /* Set the Unseen-Sequence */
956 seq_save(mp2
); /* Save the sequence file */
962 * unlock the mail spool
964 if (inc_type
== INC_FILE
&& Maildir
== NULL
) {
966 GETGROUPPRIVS(); /* Be sure we can unlock mail file */
967 (void) lkfclosespool (in
, newmail
); in
= NULL
;
968 DROPGROUPPRIVS(); /* And then return us to normal privileges */
970 fclose (in
); in
= NULL
;
974 context_save (); /* save the context file */
981 inc_done (int status
)
984 if (packfile
&& pd
!= NOTOK
)
985 mbx_close (packfile
, pd
);
989 lkfclosespool(in
, newmail
);
998 fprintf (pf
, "%s\n", s
);
999 stop
+= strlen (s
) + 1;
1000 return 0; /* Is return value used? This was missing before 1999-07-15. */
1007 char buffer
[BUFSIZ
];
1009 snprintf (buffer
, sizeof(buffer
), "%s\n", s
);
1010 for ( ; (j
= stringdex (mmdlm1
, buffer
)) >= 0; buffer
[j
]++)
1012 for ( ; (j
= stringdex (mmdlm2
, buffer
)) >= 0; buffer
[j
]++)
1015 size
+= strlen (buffer
) + 1;
1016 return 0; /* Is return value used? This was missing before 1999-07-15. */
1027 if (stat (packfile
, &st
) == NOTOK
)
1029 if ((md
= open (cp
= map_name (packfile
), O_RDONLY
)) == NOTOK
1030 || map_chk (cp
, md
, &d
, (long) st
.st_size
, 1)) {