119
124
static RETSIGTYPE donothing(int sig)
121
extern volatile int lastsig; /* declared in idle.c */
122
126
set_signal_handler(sig, donothing);
130
static void printcopyright(FILE *fp) {
131
fprintf(fp, GT_("Copyright (C) 2002, 2003 Eric S. Raymond\n"
132
"Copyright (C) 2004 Matthias Andree, Eric S. Raymond, Rob F. Funk, Graham Wilson\n"
133
"Copyright (C) 2005 Matthias Andree, Sunil Shetye\n"
134
"Copyright (C) 2006 Matthias Andree\n"));
135
fprintf(fp, GT_("Fetchmail comes with ABSOLUTELY NO WARRANTY. This is free software, and you\n"
136
"are welcome to redistribute it under certain conditions. For details,\n"
137
"please see the file COPYING in the source or documentation directory.\n"));
140
const char *iana_charset;
126
142
int main(int argc, char **argv)
128
144
int bkgd = FALSE;
129
int parsestatus, implicitmode = FALSE;
145
int implicitmode = FALSE;
130
146
struct query *ctl;
131
147
netrc_entry *netrc_list;
132
148
char *netrc_file, *tmpbuf;
185
if ((parsestatus = parsecmdline(argc,argv, &cmd_run, &cmd_opts)) < 0)
213
i = parsecmdline(argc, argv, &cmd_run, &cmd_opts);
217
if (quitmode && quitind == argc)
190
printf(GT_("This is fetchmail release %s"), VERSION);
223
const char *features =
191
224
#ifdef POP2_ENABLE
193
226
#endif /* POP2_ENABLE */
194
227
#ifndef POP3_ENABLE
196
229
#endif /* POP3_ENABLE */
197
230
#ifndef IMAP_ENABLE
199
232
#endif /* IMAP_ENABLE */
202
235
#endif /* GSSAPI */
203
236
#ifdef RPA_ENABLE
205
238
#endif /* RPA_ENABLE */
206
239
#ifdef NTLM_ENABLE
208
241
#endif /* NTLM_ENABLE */
209
242
#ifdef SDPS_ENABLE
211
244
#endif /* SDPS_ENABLE */
212
245
#ifndef ETRN_ENABLE
214
247
#endif /* ETRN_ENABLE */
215
248
#ifndef ODMR_ENABLE
217
250
#endif /* ODMR_ENABLE */
218
251
#ifdef SSL_ENABLE
223
256
#endif /* OPIE_ENABLE */
226
#endif /* INET6_ENABLE */
229
#endif /* NET_SECURITY */
257
#ifdef HAVE_PKG_hesiod
230
260
#ifdef HAVE_SOCKS
232
262
#endif /* HAVE_SOCKS */
235
265
#endif /* ENABLE_NLS */
267
printf(GT_("This is fetchmail release %s"), VERSION);
268
fputs(features, stdout);
270
printcopyright(stdout);
240
272
fputs("Fallback MDA: ", stdout);
241
273
#ifdef FALLBACK_MDA
242
274
fputs(FALLBACK_MDA, stdout);
391
fprintf(stderr,GT_("fetchmail: %s fetchmail at %d killed.\n"),
392
bkgd ? GT_("background") : GT_("foreground"), pid);
423
if (outlevel > O_SILENT)
424
fprintf(stderr,GT_("fetchmail: %s fetchmail at %d killed.\n"),
425
bkgd ? GT_("background") : GT_("foreground"), pid);
426
/* We used to nuke the other process's lock here, with
427
* fm_lock_release(), which is broken. The other process
428
* needs to clear its lock by itself. */
432
/* wait for other process to exit */
433
maxwait = 10; /* seconds */
434
while (kill(pid, 0) == 0 && --maxwait >= 0) {
463
503
GT_("fetchmail: can't find a password for %s@%s.\n"),
464
504
ctl->remotename, ctl->server.pollname);
465
505
return(PS_AUTHFAIL);
469
char* password_prompt = GT_("Enter password for %s@%s: ");
507
const char* password_prompt = GT_("Enter password for %s@%s: ");
508
size_t pplen = strlen(password_prompt) + strlen(ctl->remotename) + strlen(ctl->server.pollname) + 1;
471
xalloca(tmpbuf, char *, strlen(password_prompt) +
472
strlen(ctl->remotename) +
473
strlen(ctl->server.pollname) + 1);
474
(void) sprintf(tmpbuf, password_prompt,
475
ctl->remotename, ctl->server.pollname);
510
tmpbuf = xmalloc(pplen);
511
snprintf(tmpbuf, pplen, password_prompt,
512
ctl->remotename, ctl->server.pollname);
476
513
ctl->password = xstrdup((char *)fm_getpassword(tmpbuf));
1048
1086
* If we're using Kerberos for authentication, we need
1049
1087
* the FQDN in order to generate capability keys.
1051
if (strcmp(fetchmailhost, "localhost") == 0)
1052
for (ctl = querylist; ctl; ctl = ctl->next)
1089
for (ctl = querylist; ctl; ctl = ctl->next)
1054
1091
(ctl->server.protocol==P_ETRN || ctl->server.protocol==P_ODMR
1055
1092
|| ctl->server.authenticate == A_KERBEROS_V4
1056
1093
|| ctl->server.authenticate == A_KERBEROS_V5))
1058
fetchmailhost = host_fqdn();
1095
fetchmailhost = host_fqdn(1);
1099
if (!ctl) /* list exhausted */
1100
fetchmailhost = host_fqdn(0);
1102
/* this code enables flags to be turned off */
1103
#define DEFAULT(flag, dflt) if (flag == FLAG_TRUE)\
1105
else if (flag == FLAG_FALSE)\
1109
/* one global gets treated specially */
1110
DEFAULT(run.showdots, run.poll_interval==0 || nodetach);
1062
1112
/* merge in wired defaults, do sanity checks and prepare internal fields */
1063
1113
for (ctl = querylist; ctl; ctl = ctl->next)
1089
1139
if (configdump || ctl->active )
1091
/* this code enables flags to be turned off */
1092
#define DEFAULT(flag, dflt) if (flag == FLAG_TRUE)\
1094
else if (flag == FLAG_FALSE)\
1098
1141
DEFAULT(ctl->keep, FALSE);
1099
1142
DEFAULT(ctl->fetchall, FALSE);
1100
1143
DEFAULT(ctl->flush, FALSE);
1144
DEFAULT(ctl->limitflush, FALSE);
1101
1145
DEFAULT(ctl->rewrite, TRUE);
1102
1146
DEFAULT(ctl->stripcr, (ctl->mda != (char *)NULL));
1103
1147
DEFAULT(ctl->forcecr, FALSE);
1108
1152
DEFAULT(ctl->idle, FALSE);
1109
1153
DEFAULT(ctl->server.dns, TRUE);
1110
1154
DEFAULT(ctl->server.uidl, FALSE);
1112
1155
DEFAULT(ctl->use_ssl, FALSE);
1113
1156
DEFAULT(ctl->sslcertck, FALSE);
1115
1157
DEFAULT(ctl->server.checkalias, FALSE);
1116
1158
#ifndef SSL_ENABLE
1160
* XXX FIXME: do we need this check or can we rely on the .y
1161
* parser handling this?
1117
1163
if (ctl->use_ssl)
1119
1165
report(stderr, GT_("SSL support is not compiled in.\n"));
1120
1166
exit(PS_SYNTAX);
1122
1168
#endif /* SSL_ENABLE */
1123
/* one global gets treated specially */
1124
DEFAULT(run.showdots, run.poll_interval==0 || nodetach);
1128
1172
* Make sure we have a nonempty host list to forward to.
1130
1174
if (!ctl->smtphunt)
1131
save_str(&ctl->smtphunt, fetchmailhost, FALSE);
1175
save_str(&ctl->smtphunt, "localhost", FALSE);
1134
1178
* Make sure we have a nonempty list of domains to fetch from.
1144
1188
if (!ctl->localnames) /* for local delivery via SMTP */
1145
1189
save_str_pair(&ctl->localnames, user, NULL);
1147
#if !defined(HAVE_GETHOSTBYNAME) || !defined(HAVE_RES_SEARCH)
1191
#ifndef HAVE_RES_SEARCH
1148
1192
/* can't handle multidrop mailboxes unless we can do DNS lookups */
1149
if (ctl->localnames && ctl->localnames->next && ctl->server.dns)
1193
if (MULTIDROP(ctl) && ctl->server.dns)
1151
1195
ctl->server.dns = FALSE;
1152
1196
report(stderr, GT_("fetchmail: warning: no DNS available to check multidrop fetches from %s\n"), ctl->server.pollname);
1154
#endif /* !HAVE_GETHOSTBYNAME || !HAVE_RES_SEARCH */
1198
#endif /* !HAVE_RES_SEARCH */
1201
* can't handle multidrop mailboxes without "envelope"
1202
* option, this causes truckloads full of support complaints
1203
* "all mail forwarded to postmaster"
1205
if (MULTIDROP(ctl) && !ctl->server.envelope)
1207
report(stderr, GT_("warning: multidrop for %s requires envelope option!\n"), ctl->server.pollname);
1208
report(stderr, GT_("warning: Do not ask for support if all mail goes to postmaster!\n"));
1156
1211
/* if no folders were specified, set up the null one as default */
1157
1212
if (!ctl->mailboxes)
1158
1213
save_str(&ctl->mailboxes, (char *)NULL, 0);
1160
1215
/* maybe user overrode timeout on command line? */
1161
if (ctl->server.timeout == -1)
1216
if (ctl->server.timeout == -1)
1162
1217
ctl->server.timeout = CLIENT_TIMEOUT;
1165
1219
/* sanity checks */
1166
if (ctl->server.port < 0)
1168
(void) fprintf(stderr,
1169
GT_("%s configuration invalid, port number cannot be negative\n"),
1170
ctl->server.pollname);
1173
if (ctl->server.protocol == P_RPOP && ctl->server.port >= 1024)
1175
(void) fprintf(stderr,
1176
GT_("%s configuration invalid, RPOP requires a privileged port\n"),
1177
ctl->server.pollname);
1220
if (ctl->server.service) {
1221
int port = servport(ctl->server.service);
1224
(void) fprintf(stderr,
1225
GT_("fetchmail: %s configuration invalid, specify positive port number for service or port\n"),
1226
ctl->server.pollname);
1229
if (ctl->server.protocol == P_RPOP && port >= 1024)
1231
(void) fprintf(stderr,
1232
GT_("fetchmail: %s configuration invalid, RPOP requires a privileged port\n"),
1233
ctl->server.pollname);
1180
1237
if (ctl->listener == LMTP_MODE)
1236
1292
static RETSIGTYPE terminate_poll(int sig)
1237
1293
/* to be executed at the end of a poll cycle */
1240
* Close all SMTP delivery sockets. For optimum performance
1241
* we'd like to hold them open til end of run, but (1) this
1242
* loses if our poll interval is longer than the MTA's inactivity
1243
* timeout, and (2) some MTAs (like smail) don't deliver after
1244
* each message, but rather queue up mail and wait to actually
1245
* deliver it until the input socket is closed.
1247
* Sending SMTP QUIT on signal is theoretically nice, but led to a
1248
* subtle bug. If fetchmail was terminated by signal while it was
1249
* shipping message text, it would hang forever waiting for a
1250
* command acknowledge. In theory we could enable the QUIT
1251
* only outside of the message send. In practice, we don't
1252
* care. All mailservers hang up on a dropped TCP/IP connection
1257
1297
report(stdout, GT_("terminated with signal %d\n"), sig);
1262
/* terminate all SMTP connections cleanly */
1263
for (ctl = querylist; ctl; ctl = ctl->next)
1264
if (ctl->smtp_socket != -1)
1266
/* don't send QUIT for ODMR case because we're acting
1267
as a proxy between the SMTP server and client. */
1268
smtp_close(ctl, ctl->server.protocol != P_ODMR);
1272
1299
#ifdef POP3_ENABLE
1478
1495
printf(GT_(" Mail will be retrieved via %s\n"), ctl->server.via);
1480
1497
if (ctl->server.interval)
1481
printf(GT_(" Poll of this server will occur every %d intervals.\n"),
1482
ctl->server.interval);
1498
printf(ngettext(" Poll of this server will occur every %d interval.\n",
1499
" Poll of this server will occur every %d intervals.\n",
1500
ctl->server.interval), ctl->server.interval);
1483
1501
if (ctl->server.truename)
1484
1502
printf(GT_(" True name of server is %s.\n"), ctl->server.truename);
1485
1503
if (ctl->server.skip || outlevel >= O_VERBOSE)
1486
printf(GT_(" This host %s be queried when no host is specified.\n"),
1487
ctl->server.skip ? GT_("will not") : GT_("will"));
1504
printf(ctl->server.skip
1505
? GT_(" This host will not be queried when no host is specified.\n")
1506
: GT_(" This host will be queried when no host is specified.\n"));
1488
1507
if (!NO_PASSWORD(ctl))
1490
1509
if (!ctl->password)
1506
1525
if (ctl->server.protocol == P_POP3
1508
1526
&& ctl->server.service && !strcmp(ctl->server.service, KPOP_PORT)
1509
#else /* INET6_ENABLE */
1510
&& ctl->server.port == KPOP_PORT
1511
#endif /* INET6_ENABLE */
1512
1527
&& (ctl->server.authenticate == A_KERBEROS_V4 ||
1513
1528
ctl->server.authenticate == A_KERBEROS_V5))
1514
1529
printf(GT_(" Protocol is KPOP with Kerberos %s authentication"),
1515
1530
ctl->server.authenticate == A_KERBEROS_V5 ? "V" : "IV");
1517
1532
printf(GT_(" Protocol is %s"), showproto(ctl->server.protocol));
1519
1533
if (ctl->server.service)
1520
1534
printf(GT_(" (using service %s)"), ctl->server.service);
1521
if (ctl->server.netsec)
1522
printf(GT_(" (using network security options %s)"), ctl->server.netsec);
1523
#else /* INET6_ENABLE */
1524
if (ctl->server.port)
1525
printf(GT_(" (using port %d)"), ctl->server.port);
1526
#endif /* INET6_ENABLE */
1527
1535
else if (outlevel >= O_VERBOSE)
1528
1536
printf(GT_(" (using default port)"));
1529
1537
if (ctl->server.uidl && MAILBOX_PROTOCOL(ctl))
1593
1604
printf(GT_(" Selected mailboxes are:"));
1594
1605
for (idp = ctl->mailboxes; idp; idp = idp->next)
1595
printf(" %s", idp->id);
1606
printf(" %s", (char *)idp->id);
1598
printf(GT_(" %s messages will be retrieved (--all %s).\n"),
1599
ctl->fetchall ? GT_("All") : GT_("Only new"),
1600
ctl->fetchall ? "on" : "off");
1601
printf(GT_(" Fetched messages %s be kept on the server (--keep %s).\n"),
1602
ctl->keep ? GT_("will") : GT_("will not"),
1603
ctl->keep ? "on" : "off");
1604
printf(GT_(" Old messages %s be flushed before message retrieval (--flush %s).\n"),
1605
ctl->flush ? GT_("will") : GT_("will not"),
1606
ctl->flush ? "on" : "off");
1607
printf(GT_(" Rewrite of server-local addresses is %s (--norewrite %s).\n"),
1608
ctl->rewrite ? GT_("enabled") : GT_("disabled"),
1609
ctl->rewrite ? "off" : "on");
1610
printf(GT_(" Carriage-return stripping is %s (stripcr %s).\n"),
1611
ctl->stripcr ? GT_("enabled") : GT_("disabled"),
1612
ctl->stripcr ? "on" : "off");
1613
printf(GT_(" Carriage-return forcing is %s (forcecr %s).\n"),
1614
ctl->forcecr ? GT_("enabled") : GT_("disabled"),
1615
ctl->forcecr ? "on" : "off");
1616
printf(GT_(" Interpretation of Content-Transfer-Encoding is %s (pass8bits %s).\n"),
1617
ctl->pass8bits ? GT_("disabled") : GT_("enabled"),
1618
ctl->pass8bits ? "on" : "off");
1619
printf(GT_(" MIME decoding is %s (mimedecode %s).\n"),
1620
ctl->mimedecode ? GT_("enabled") : GT_("disabled"),
1621
ctl->mimedecode ? "on" : "off");
1622
printf(GT_(" Idle after poll is %s (idle %s).\n"),
1623
ctl->idle ? GT_("enabled") : GT_("disabled"),
1624
ctl->idle ? "on" : "off");
1625
printf(GT_(" Nonempty Status lines will be %s (dropstatus %s)\n"),
1626
ctl->dropstatus ? GT_("discarded") : GT_("kept"),
1627
ctl->dropstatus ? "on" : "off");
1628
printf(GT_(" Delivered-To lines will be %s (dropdelivered %s)\n"),
1629
ctl->dropdelivered ? GT_("discarded") : GT_("kept"),
1630
ctl->dropdelivered ? "on" : "off");
1609
printf(ctl->fetchall
1610
? GT_(" All messages will be retrieved (--all on).\n")
1611
: GT_(" Only new messages will be retrieved (--all off).\n"));
1613
? GT_(" Fetched messages will be kept on the server (--keep on).\n")
1614
: GT_(" Fetched messages will not be kept on the server (--keep off).\n"));
1616
? GT_(" Old messages will be flushed before message retrieval (--flush on).\n")
1617
: GT_(" Old messages will not be flushed before message retrieval (--flush off).\n"));
1618
printf(ctl->limitflush
1619
? GT_(" Oversized messages will be flushed before message retrieval (--limitflush on).\n")
1620
: GT_(" Oversized messages will not be flushed before message retrieval (--limitflush off).\n"));
1622
? GT_(" Rewrite of server-local addresses is enabled (--norewrite off).\n")
1623
: GT_(" Rewrite of server-local addresses is disabled (--norewrite on).\n"));
1625
? GT_(" Carriage-return stripping is enabled (stripcr on).\n")
1626
: GT_(" Carriage-return stripping is disabled (stripcr off).\n"));
1628
? GT_(" Carriage-return forcing is enabled (forcecr on).\n")
1629
: GT_(" Carriage-return forcing is disabled (forcecr off).\n"));
1630
printf(ctl->pass8bits
1631
? GT_(" Interpretation of Content-Transfer-Encoding is disabled (pass8bits on).\n")
1632
: GT_(" Interpretation of Content-Transfer-Encoding is enabled (pass8bits off).\n"));
1633
printf(ctl->mimedecode
1634
? GT_(" MIME decoding is enabled (mimedecode on).\n")
1635
: GT_(" MIME decoding is disabled (mimedecode off).\n"));
1637
? GT_(" Idle after poll is enabled (idle on).\n")
1638
: GT_(" Idle after poll is disabled (idle off).\n"));
1639
printf(ctl->dropstatus
1640
? GT_(" Nonempty Status lines will be discarded (dropstatus on)\n")
1641
: GT_(" Nonempty Status lines will be kept (dropstatus off)\n"));
1642
printf(ctl->dropdelivered
1643
? GT_(" Delivered-To lines will be discarded (dropdelivered on)\n")
1644
: GT_(" Delivered-To lines will be kept (dropdelivered off)\n"));
1631
1645
if (NUM_NONZERO(ctl->limit))
1633
1647
if (NUM_NONZERO(ctl->limit))
1753
1767
printf(GT_(" Single-drop mode: "));
1755
printf(GT_("%d local name(s) recognized.\n"), count);
1769
printf(ngettext("%d local name recognized.\n", "%d local names recognized.\n", count), count);
1756
1770
if (outlevel >= O_VERBOSE)
1758
1772
for (idp = ctl->localnames; idp; idp = idp->next)
1759
1773
if (idp->val.id2)
1760
printf("\t%s -> %s\n", idp->id, idp->val.id2);
1774
printf("\t%s -> %s\n", (char *)idp->id, (char *)idp->val.id2);
1762
printf("\t%s\n", idp->id);
1776
printf("\t%s\n", (char *)idp->id);
1763
1777
if (ctl->wildcard)
1764
1778
fputs("\t*\n", stdout);
1767
1781
if (count > 1 || ctl->wildcard)
1769
printf(GT_(" DNS lookup for multidrop addresses is %s.\n"),
1770
ctl->server.dns ? GT_("enabled") : GT_("disabled"));
1783
printf(ctl->server.dns
1784
? GT_(" DNS lookup for multidrop addresses is enabled.\n")
1785
: GT_(" DNS lookup for multidrop addresses is disabled.\n"));
1771
1786
if (ctl->server.dns)
1773
printf(GT_(" Server aliases will be compared with multidrop addresses by "));
1774
1788
if (ctl->server.checkalias)
1775
printf(GT_("IP address.\n"));
1789
printf(GT_(" Server aliases will be compared with multidrop addresses by IP address.\n"));
1777
printf(GT_("name.\n"));
1791
printf(GT_(" Server aliases will be compared with multidrop addresses by name.\n"));
1779
1793
if (ctl->server.envelope == STRING_DISABLED)
1780
1794
printf(GT_(" Envelope-address routing is disabled\n"));
1783
1797
printf(GT_(" Envelope header is assumed to be: %s\n"),
1784
ctl->server.envelope ? ctl->server.envelope:GT_("Received"));
1785
if (ctl->server.envskip > 1 || outlevel >= O_VERBOSE)
1786
printf(GT_(" Number of envelope header to be parsed: %d\n"),
1798
ctl->server.envelope ? ctl->server.envelope : "Received");
1799
if (ctl->server.envskip || outlevel >= O_VERBOSE)
1800
printf(GT_(" Number of envelope headers to be skipped over: %d\n"),
1787
1801
ctl->server.envskip);
1788
1802
if (ctl->server.qvirtual)
1789
1803
printf(GT_(" Prefix %s will be removed from user id\n"),