22 |
int ex_quota_tempfail; |
int ex_quota_tempfail; |
23 |
int exit_code = EX_OK; |
int exit_code = EX_OK; |
24 |
uid_t uid; |
uid_t uid; |
|
char *maildir = MU_PATH_MAILDIR; |
|
25 |
char *quotadbname = NULL; |
char *quotadbname = NULL; |
26 |
int lock_timeout = 300; |
int lock_timeout = 300; |
27 |
|
|
39 |
void mailer_err (char *fmt, ...); |
void mailer_err (char *fmt, ...); |
40 |
void notify_biff (mailbox_t mbox, char *name, size_t size); |
void notify_biff (mailbox_t mbox, char *name, size_t size); |
41 |
|
|
42 |
char short_opts[] = "hf:Llm:q:r:s:x::vW;"; |
const char *argp_program_version = "mail.local (" PACKAGE ") " VERSION; |
43 |
|
const char *argp_program_bug_address = "<bug-mailutils@gnu.org>"; |
44 |
|
static char doc[] = "GNU mail.local -- the local MDA"; |
45 |
|
static char args_doc[] = "recipient [recipient ...]"; |
46 |
|
|
47 |
|
#define ARG_MULTIPLE_DELIVERY 1 |
48 |
|
#define ARG_QUOTA_TEMPFAIL 2 |
49 |
|
|
50 |
|
static struct argp_option options[] = |
51 |
|
{ |
52 |
|
{ "ex-multiple-delivery-success", ARG_MULTIPLE_DELIVERY, NULL, 0, |
53 |
|
"Don't return errors when delivering to multiple recipients", 0 }, |
54 |
|
{ "ex-quota-tempfail", ARG_QUOTA_TEMPFAIL, NULL, 0, |
55 |
|
"Return temporary failure if disk or mailbox quota is exceeded", 0 }, |
56 |
|
{ "from", 'f', "EMAIL", 0, |
57 |
|
"Specify the sender's name" }, |
58 |
|
{ NULL, 'r', NULL, OPTION_ALIAS, NULL }, |
59 |
|
#ifdef USE_DBM |
60 |
|
{ "quota-db", 'q', "FILE", 0, |
61 |
|
"Specify path to quota database", 0 }, |
62 |
|
#endif |
63 |
|
#ifdef WITH_GUILE |
64 |
|
{ "source", 's', "PATTERN", 0, |
65 |
|
"Set name pattern for user-defined mail filters", 0 }, |
66 |
|
#endif |
67 |
|
{ "debug", 'x', |
68 |
|
#ifdef WITH_GUILE |
69 |
|
"{NUMBER|guile}", |
70 |
|
#else |
71 |
|
"NUMBER", |
72 |
|
#endif |
73 |
|
0, |
74 |
|
"Enable debugging", 0 }, |
75 |
|
{ "timeout", 't', "NUMBER", 0, |
76 |
|
"Set timeout for acquiring the lockfile" }, |
77 |
|
|
78 |
static struct option long_opts[] = { |
{ NULL, 0, NULL, 0, NULL, 0 } |
|
{ "ex-multiple-delivery-success", no_argument, &multiple_delivery, 1 }, |
|
|
{ "ex-quota-tempfail", no_argument, &ex_quota_tempfail, 1 }, |
|
|
{ "from", required_argument, 0, 'f' }, |
|
|
{ "help", no_argument, 0, 'h' }, |
|
|
{ "license", no_argument, 0, 'L' }, |
|
|
{ "maildir", required_argument, 0, 'm' }, |
|
|
{ "quota-db", required_argument, 0, 'q' }, |
|
|
{ "source", required_argument, 0, 's' }, |
|
|
{ "timeout", required_argument, 0, 't' }, |
|
|
{ "debug", optional_argument, 0, 'x' }, |
|
|
{ "version", no_argument, 0, 'v' }, |
|
|
{ 0, 0, 0, 0 } |
|
79 |
}; |
}; |
|
|
|
80 |
|
|
81 |
int |
static error_t parse_opt (int key, char *arg, struct argp_state *state); |
82 |
main (int argc, char *argv[]) |
|
83 |
|
static struct argp argp = { |
84 |
|
options, |
85 |
|
parse_opt, |
86 |
|
args_doc, |
87 |
|
doc, |
88 |
|
mu_common_argp_child, |
89 |
|
NULL, NULL |
90 |
|
}; |
91 |
|
|
92 |
|
char *from = NULL; |
93 |
|
char *progfile_pattern = NULL; |
94 |
|
|
95 |
|
static error_t |
96 |
|
parse_opt (int key, char *arg, struct argp_state *state) |
97 |
{ |
{ |
98 |
int c; |
switch (key) |
99 |
FILE *fp; |
{ |
100 |
char *from = NULL; |
case ARG_MULTIPLE_DELIVERY: |
101 |
char *progfile_pattern = NULL; |
multiple_delivery = 1; |
102 |
char *tempfile = NULL; |
break; |
|
|
|
|
/* Preparative work: close inherited fds, force a reasonable umask |
|
|
and prepare a logging. */ |
|
|
close_fds (); |
|
|
umask (0077); |
|
103 |
|
|
104 |
openlog ("mail.local", LOG_PID, LOG_FACILITY); |
case ARG_QUOTA_TEMPFAIL: |
105 |
mu_error_set_print (mu_syslog_error_printer); |
ex_quota_tempfail = 1; |
106 |
|
break; |
|
uid = getuid (); |
|
|
while ((c = getopt_long (argc, argv, short_opts, long_opts, NULL)) != EOF) |
|
|
switch (c) |
|
|
{ |
|
|
case 0: /* option already handled */ |
|
|
break; |
|
|
case 'r': |
|
|
case 'f': |
|
|
if (from != NULL) |
|
|
{ |
|
|
mu_error ("multiple --from options"); |
|
|
return EX_USAGE; |
|
|
} |
|
|
from = optarg; |
|
|
break; |
|
107 |
|
|
108 |
case 'h': |
case 'r': |
109 |
print_help (); |
case 'f': |
110 |
break; |
if (from != NULL) |
111 |
|
{ |
112 |
case 'L': |
mu_error ("multiple --from options"); |
113 |
print_license (); |
return EX_USAGE; |
114 |
break; |
} |
115 |
|
from = arg; |
116 |
|
break; |
117 |
|
|
|
case 'm': |
|
|
maildir = optarg; |
|
|
break; |
|
|
|
|
118 |
#ifdef USE_DBM |
#ifdef USE_DBM |
119 |
case 'q': |
case 'q': |
120 |
quotadbname = optarg; |
quotadbname = arg; |
121 |
break; |
break; |
122 |
#endif |
#endif |
123 |
|
|
124 |
#ifdef WITH_GUILE |
#ifdef WITH_GUILE |
139 |
debug_guile = 1; |
debug_guile = 1; |
140 |
else |
else |
141 |
#endif |
#endif |
142 |
debug_level = strtoul (optarg, NULL, 0); |
debug_level = strtoul (optarg, NULL, 0); |
143 |
} |
} |
144 |
else |
else |
145 |
{ |
{ |
149 |
#endif |
#endif |
150 |
} |
} |
151 |
break; |
break; |
|
|
|
|
case 'v': |
|
|
print_version (); |
|
|
break; |
|
|
|
|
|
default: |
|
|
return EX_USAGE; |
|
|
} |
|
152 |
|
|
153 |
argc -= optind; |
default: |
154 |
argv += optind; |
return ARGP_ERR_UNKNOWN; |
155 |
|
|
156 |
|
case ARGP_KEY_ERROR: |
157 |
|
exit (EX_USAGE); |
158 |
|
} |
159 |
|
return 0; |
160 |
|
} |
161 |
|
|
162 |
|
int |
163 |
|
main (int argc, char *argv[]) |
164 |
|
{ |
165 |
|
FILE *fp; |
166 |
|
char *tempfile = NULL; |
167 |
|
int arg_index; |
168 |
|
|
169 |
|
/* Preparative work: close inherited fds, force a reasonable umask |
170 |
|
and prepare a logging. */ |
171 |
|
close_fds (); |
172 |
|
umask (0077); |
173 |
|
|
174 |
|
mu_create_argcv (argc, argv, &argc, &argv); |
175 |
|
argp_parse (&argp, argc, argv, 0, &arg_index, NULL); |
176 |
|
|
177 |
|
openlog ("mail.local", LOG_PID, log_facility); |
178 |
|
mu_error_set_print (mu_syslog_error_printer); |
179 |
|
|
180 |
|
uid = getuid (); |
181 |
|
|
182 |
|
argc -= arg_index; |
183 |
|
argv += arg_index; |
184 |
|
|
185 |
if (!argc) |
if (!argc) |
186 |
print_help (); |
print_help (); |
762 |
exit (0); |
exit (0); |
763 |
} |
} |
764 |
|
|
|
void |
|
|
print_license () |
|
|
{ |
|
|
static char license_text[] = |
|
|
" This program is free software; you can redistribute it and/or modify\n" |
|
|
" it under the terms of the GNU General Public License as published by\n" |
|
|
" the Free Software Foundation; either version 2, or (at your option)\n" |
|
|
" any later version.\n" |
|
|
"\n" |
|
|
" This program is distributed in the hope that it will be useful,\n" |
|
|
" but WITHOUT ANY WARRANTY; without even the implied warranty of\n" |
|
|
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" |
|
|
" GNU General Public License for more details.\n" |
|
|
"\n" |
|
|
" You should have received a copy of the GNU General Public License\n" |
|
|
" along with this program; if not, write to the Free Software\n" |
|
|
" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n"; |
|
|
printf ("%s", license_text); |
|
|
exit (0); |
|
|
} |
|
765 |
|
|
|
void |
|
|
print_version () |
|
|
{ |
|
|
printf ("mail.local ("PACKAGE " " VERSION ")\n"); |
|
|
exit (0); |
|
|
} |
|
766 |
|
|