Mercurial > masqmail
comparison src/masqmail.c @ 192:89f951be358f
REMOVED POP3 SUPPORT
masqmail will not include a POP3 client anymore from 0.3.0 on
maybe the POP3 code will be reworked into a standalone program
some day
if you rely on the POP3 client, use fetchmail or something similar
instead
author | meillo@marmaro.de |
---|---|
date | Thu, 15 Jul 2010 14:24:40 +0200 |
parents | 8630e37ae445 |
children | 5745edd5b769 |
comparison
equal
deleted
inserted
replaced
191:f186650135c3 | 192:89f951be358f |
---|---|
32 | 32 |
33 #include <glib.h> | 33 #include <glib.h> |
34 | 34 |
35 #include "masqmail.h" | 35 #include "masqmail.h" |
36 | 36 |
37 /* mutually exclusive modes. Note that there is neither a 'get' mode | 37 /* mutually exclusive modes. Note that there is no 'queue daemon' mode. |
38 nor a 'queue daemon' mode. These, as well as the distinction beween | 38 It, as well as the distinction beween the two (non exclusive) daemon |
39 the two (non exclusive) daemon (queue and listen) modes are handled | 39 (queue and listen) modes, is handled by flags.*/ |
40 by flags.*/ | |
41 typedef enum _mta_mode { | 40 typedef enum _mta_mode { |
42 MODE_ACCEPT = 0, /* accept message on stdin */ | 41 MODE_ACCEPT = 0, /* accept message on stdin */ |
43 MODE_DAEMON, /* run as daemon */ | 42 MODE_DAEMON, /* run as daemon */ |
44 MODE_RUNQUEUE, /* single queue run, online or offline */ | 43 MODE_RUNQUEUE, /* single queue run, online or offline */ |
45 MODE_GET_DAEMON, /* run as get (retrieve) daemon */ | |
46 MODE_SMTP, /* accept SMTP on stdin */ | 44 MODE_SMTP, /* accept SMTP on stdin */ |
47 MODE_LIST, /* list queue */ | 45 MODE_LIST, /* list queue */ |
48 MODE_MCMD, /* do queue manipulation */ | 46 MODE_MCMD, /* do queue manipulation */ |
49 MODE_VERSION, /* show version */ | 47 MODE_VERSION, /* show version */ |
50 MODE_BI, /* fake ;-) */ | 48 MODE_BI, /* fake ;-) */ |
176 logopen(); | 174 logopen(); |
177 | 175 |
178 logwrite(LOG_NOTICE, "%s %s daemon starting", PACKAGE, VERSION); | 176 logwrite(LOG_NOTICE, "%s %s daemon starting", PACKAGE, VERSION); |
179 listen_port(do_listen ? conf.listen_addresses : NULL, queue_interval, argv); | 177 listen_port(do_listen ? conf.listen_addresses : NULL, queue_interval, argv); |
180 } | 178 } |
181 | |
182 #ifdef ENABLE_POP3 | |
183 static void | |
184 mode_get_daemon(gint get_interval, char *argv[]) | |
185 { | |
186 guint pid; | |
187 | |
188 /* daemon */ | |
189 if (!conf.run_as_user) { | |
190 if ((conf.orig_uid != 0) && (conf.orig_uid != conf.mail_uid)) { | |
191 fprintf(stderr, "must be root or %s for daemon.\n", DEF_MAIL_USER); | |
192 exit(EXIT_FAILURE); | |
193 } | |
194 } | |
195 | |
196 /* reparent to init only if init is not already the parent */ | |
197 if (getppid() != 1) { | |
198 if ((pid = fork()) > 0) { | |
199 exit(EXIT_SUCCESS); | |
200 } else if (pid < 0) { | |
201 logwrite(LOG_ALERT, "could not fork!"); | |
202 exit(EXIT_FAILURE); | |
203 } | |
204 } | |
205 | |
206 signal(SIGTERM, sigterm_handler); | |
207 write_pidfile(PIDFILEDIR "/masqmail-get.pid"); | |
208 | |
209 conf.do_verbose = FALSE; | |
210 | |
211 /* closing and reopening the log ensures that it is open afterwards | |
212 because it is possible that the log is assigned to fd 1 and gets | |
213 thus closes by fclose(stdout). Similar for the debugfile. | |
214 */ | |
215 logclose(); | |
216 fclose(stdin); | |
217 fclose(stdout); | |
218 fclose(stderr); | |
219 logopen(); | |
220 | |
221 get_daemon(get_interval, argv); | |
222 } | |
223 #endif | |
224 | 179 |
225 #ifdef ENABLE_SMTP_SERVER | 180 #ifdef ENABLE_SMTP_SERVER |
226 static void | 181 static void |
227 mode_smtp() | 182 mode_smtp() |
228 { | 183 { |
334 main(int argc, char *argv[]) | 289 main(int argc, char *argv[]) |
335 { | 290 { |
336 /* cmd line flags */ | 291 /* cmd line flags */ |
337 gchar *conf_file = CONF_FILE; | 292 gchar *conf_file = CONF_FILE; |
338 gint arg = 1; | 293 gint arg = 1; |
339 gboolean do_get = FALSE; | |
340 gboolean do_get_online = FALSE; | |
341 | 294 |
342 gboolean do_listen = FALSE; | 295 gboolean do_listen = FALSE; |
343 gboolean do_runq = FALSE; | 296 gboolean do_runq = FALSE; |
344 gboolean do_runq_online = FALSE; | 297 gboolean do_runq_online = FALSE; |
345 | 298 |
349 gint debug_level = -1; | 302 gint debug_level = -1; |
350 | 303 |
351 mta_mode mta_mode = MODE_ACCEPT; | 304 mta_mode mta_mode = MODE_ACCEPT; |
352 | 305 |
353 gint queue_interval = 0; | 306 gint queue_interval = 0; |
354 gint get_interval = 0; | |
355 gboolean opt_t = FALSE; | 307 gboolean opt_t = FALSE; |
356 gboolean opt_i = FALSE; | 308 gboolean opt_i = FALSE; |
357 gboolean opt_odb = FALSE; | 309 gboolean opt_odb = FALSE; |
358 gboolean opt_oem = FALSE; | 310 gboolean opt_oem = FALSE; |
359 gboolean exit_failure = FALSE; | 311 gboolean exit_failure = FALSE; |
360 | 312 |
361 gchar *M_cmd = NULL; | 313 gchar *M_cmd = NULL; |
362 | 314 |
363 gint exit_code = EXIT_SUCCESS; | 315 gint exit_code = EXIT_SUCCESS; |
364 gchar *route_name = NULL; | 316 gchar *route_name = NULL; |
365 gchar *get_name = NULL; | |
366 gchar *progname; | 317 gchar *progname; |
367 gchar *f_address = NULL; | 318 gchar *f_address = NULL; |
368 gchar *full_sender_name = NULL; | 319 gchar *full_sender_name = NULL; |
369 address *return_path = NULL; /* may be changed by -f option */ | 320 address *return_path = NULL; /* may be changed by -f option */ |
370 | 321 |
462 fprintf(stderr, "-f requires an address as an argument\n"); | 413 fprintf(stderr, "-f requires an address as an argument\n"); |
463 exit(EXIT_FAILURE); | 414 exit(EXIT_FAILURE); |
464 } | 415 } |
465 } | 416 } |
466 break; | 417 break; |
467 case 'g': | |
468 do_get = TRUE; | |
469 if (!mta_mode) | |
470 mta_mode = MODE_NONE; /* to prevent default MODE_ACCEPT */ | |
471 if (argv[arg][pos] == 'o') { | |
472 pos++; | |
473 do_get_online = TRUE; | |
474 /* can be NULL, then we use online detection method */ | |
475 route_name = get_optarg(argv, argc, &arg, &pos); | |
476 | |
477 if (route_name != NULL) { | |
478 if (isdigit(route_name[0])) { | |
479 get_interval = time_interval(route_name, &pos); | |
480 route_name = get_optarg(argv, argc, &arg, &pos); | |
481 mta_mode = MODE_GET_DAEMON; | |
482 do_get = FALSE; | |
483 } | |
484 } | |
485 } else { | |
486 if ((optarg = get_optarg(argv, argc, &arg, &pos))) { | |
487 get_name = get_optarg(argv, argc, &arg, &pos); | |
488 } | |
489 } | |
490 break; | |
491 case 'i': | 418 case 'i': |
492 if (argv[arg][pos] == 0) { | 419 if (argv[arg][pos] == 0) { |
493 opt_i = TRUE; | 420 opt_i = TRUE; |
494 exit_failure = FALSE; /* may override -oem */ | 421 exit_failure = FALSE; /* may override -oem */ |
495 } else { | 422 } else { |
572 } | 499 } |
573 | 500 |
574 if (mta_mode == MODE_VERSION) { | 501 if (mta_mode == MODE_VERSION) { |
575 gchar *with_resolver = ""; | 502 gchar *with_resolver = ""; |
576 gchar *with_smtp_server = ""; | 503 gchar *with_smtp_server = ""; |
577 gchar *with_pop3 = ""; | |
578 gchar *with_auth = ""; | 504 gchar *with_auth = ""; |
579 gchar *with_maildir = ""; | 505 gchar *with_maildir = ""; |
580 gchar *with_ident = ""; | 506 gchar *with_ident = ""; |
581 | 507 |
582 #ifdef ENABLE_RESOLVER | 508 #ifdef ENABLE_RESOLVER |
583 with_resolver = " +resolver"; | 509 with_resolver = " +resolver"; |
584 #endif | 510 #endif |
585 #ifdef ENABLE_SMTP_SERVER | 511 #ifdef ENABLE_SMTP_SERVER |
586 with_smtp_server = " +smtp-server"; | 512 with_smtp_server = " +smtp-server"; |
587 #endif | 513 #endif |
588 #ifdef ENABLE_POP3 | |
589 with_pop3 = " +pop3"; | |
590 #endif | |
591 #ifdef ENABLE_AUTH | 514 #ifdef ENABLE_AUTH |
592 with_auth = " +auth"; | 515 with_auth = " +auth"; |
593 #endif | 516 #endif |
594 #ifdef ENABLE_MAILDIR | 517 #ifdef ENABLE_MAILDIR |
595 with_maildir = " +maildir"; | 518 with_maildir = " +maildir"; |
596 #endif | 519 #endif |
597 #ifdef ENABLE_IDENT | 520 #ifdef ENABLE_IDENT |
598 with_ident = " +ident"; | 521 with_ident = " +ident"; |
599 #endif | 522 #endif |
600 | 523 |
601 printf("%s %s%s%s%s%s%s%s\n", PACKAGE, VERSION, with_resolver, with_smtp_server, | 524 printf("%s %s%s%s%s%s%s\n", PACKAGE, VERSION, with_resolver, with_smtp_server, |
602 with_pop3, with_auth, with_maildir, with_ident); | 525 with_auth, with_maildir, with_ident); |
603 | 526 |
604 exit(EXIT_SUCCESS); | 527 exit(EXIT_SUCCESS); |
605 } | 528 } |
606 | 529 |
607 /* initialize random generator */ | 530 /* initialize random generator */ |
697 fprintf(stderr, "invalid RFC821 address: %s\n", f_address); | 620 fprintf(stderr, "invalid RFC821 address: %s\n", f_address); |
698 exit(EXIT_FAILURE); | 621 exit(EXIT_FAILURE); |
699 } | 622 } |
700 } | 623 } |
701 | 624 |
702 if (do_get) { | |
703 #ifdef ENABLE_POP3 | |
704 if ((mta_mode == MODE_NONE) || (mta_mode == MODE_RUNQUEUE)) { | |
705 set_identity(conf.orig_uid, "getting mail"); | |
706 if (do_get_online) { | |
707 if (route_name != NULL) { | |
708 conf.online_detect = g_strdup("argument"); | |
709 set_online_name(route_name); | |
710 } | |
711 get_online(); | |
712 } else { | |
713 if (get_name) | |
714 get_from_name(get_name); | |
715 else | |
716 get_all(); | |
717 } | |
718 } else { | |
719 logwrite(LOG_ALERT, "get (-g) only allowed alone or together with queue run (-q)\n"); | |
720 } | |
721 #else | |
722 fprintf(stderr, "get (pop) support not compiled in\n"); | |
723 #endif | |
724 } | |
725 | |
726 switch (mta_mode) { | 625 switch (mta_mode) { |
727 case MODE_DAEMON: | 626 case MODE_DAEMON: |
728 mode_daemon(do_listen, queue_interval, argv); | 627 mode_daemon(do_listen, queue_interval, argv); |
729 break; | 628 break; |
730 case MODE_RUNQUEUE: | 629 case MODE_RUNQUEUE: |
742 } | 641 } |
743 exit_code = | 642 exit_code = |
744 queue_run_online() ? EXIT_SUCCESS : EXIT_FAILURE; | 643 queue_run_online() ? EXIT_SUCCESS : EXIT_FAILURE; |
745 } | 644 } |
746 } | 645 } |
747 break; | |
748 case MODE_GET_DAEMON: | |
749 #ifdef ENABLE_POP3 | |
750 if (route_name != NULL) { | |
751 conf.online_detect = g_strdup("argument"); | |
752 set_online_name(route_name); | |
753 } | |
754 mode_get_daemon(get_interval, argv); | |
755 #endif | |
756 break; | 646 break; |
757 | 647 |
758 case MODE_SMTP: | 648 case MODE_SMTP: |
759 #ifdef ENABLE_SMTP_SERVER | 649 #ifdef ENABLE_SMTP_SERVER |
760 mode_smtp(); | 650 mode_smtp(); |