#else
#include <varargs.h>
#endif
+#include <limits.h>
#ifdef HAVE_NET_SOCKET_H
#include <net/socket.h>
#include "socket.h"
#include "fetchmail.h"
+#define _FIX_INT_MIN(x) ((x) < INT_MIN ? INT_MIN : (x))
+#define _FIX_INT_MAX(x) ((x) > INT_MAX ? INT_MAX : (x))
+#define CAST_TO_INT(x) ((int)(_FIX_INT_MIN(_FIX_INT_MAX(x))))
+#define UCAST_TO_INT(x) ((int)(_FIX_INT_MAX(x)))
+
/* global variables: please reinitialize them explicitly for proper
* working in daemon mode */
char tag[TAGLEN];
static int tagnum;
#define GENSYM (sprintf(tag, "A%04d", ++tagnum % TAGMOD), tag)
-static struct method *protocol;
+static const struct method *protocol;
char shroud[PASSWORDLEN*2+3]; /* string to shroud in debug output */
/* session variables initialized in do_session() */
has_nuls = TRUE;
if (outlevel > O_SILENT)
report(stdout,
- GT_("incorrect header line found while scanning headers\n"));
+ GT_("incorrect header line found - see manpage for bad-header option\n"));
if (outlevel >= O_VERBOSE)
report (stdout, GT_("line: %s"), line);
refuse_mail = 1;
* our terminating combination \n\0, we move backwards to
* make sure that we don't catch some \n\0 stored in the
* decoded part of the message */
- for (tcp = line + linelen - 1; tcp > line && (*tcp != 0 || tcp[-1] != '\n'); tcp--);
+ for (tcp = line + linelen - 1; tcp > line && (*tcp != 0 || tcp[-1] != '\n'); tcp--) { }
if (tcp > line) linelen = tcp - line;
}
* turns on the dropstatus flag.
*/
{
- char *cp;
+ char *tcp;
if (!strncasecmp(line, "Status:", 7))
- cp = line + 7;
+ tcp = line + 7;
else if (!strncasecmp(line, "X-Mozilla-Status:", 17))
- cp = line + 17;
+ tcp = line + 17;
else
- cp = NULL;
- if (cp) {
- while (*cp && isspace((unsigned char)*cp)) cp++;
- if (!*cp || ctl->dropstatus)
+ tcp = NULL;
+ if (tcp) {
+ while (*tcp && isspace((unsigned char)*tcp)) tcp++;
+ if (!*tcp || ctl->dropstatus)
{
free(line);
continue;
free(sdps_envto);
} else
#endif /* SDPS_ENABLE */
- if (env_offs > -1) /* We have the actual envelope addressee */
- find_server_names(msgblk.headers + env_offs, ctl, &msgblk.recipients);
+ if (env_offs > -1) { /* We have the actual envelope addressee */
+ if (outlevel >= O_DEBUG) {
+ const char *tmps = msgblk.headers + env_offs;
+ size_t l = strcspn(tmps, "\r\n");
+ report(stdout, GT_("Parsing envelope \"%s\" names \"%-.*s\"\n"), ctl->server.envelope, UCAST_TO_INT(l), tmps);
+ }
+ find_server_names(msgblk.headers + env_offs, ctl, &msgblk.recipients);
+ }
else if (delivered_to && ctl->server.envelope != STRING_DISABLED &&
- ctl->server.envelope && !strcasecmp(ctl->server.envelope, "Delivered-To"))
- {
+ ctl->server.envelope && !strcasecmp(ctl->server.envelope, "Delivered-To"))
+ {
+ if (outlevel >= O_DEBUG) {
+ const char *tmps = delivered_to + 2 + strlen(ctl->server.envelope);
+ size_t l = strcspn(tmps, "\r\n");
+ report(stdout, GT_("Parsing envelope \"%s\" names \"%-.*s\"\n"), ctl->server.envelope, UCAST_TO_INT(l), tmps);
+ }
find_server_names(delivered_to, ctl, &msgblk.recipients);
xfree(delivered_to);
- }
- else if (received_for)
+ } else if (received_for) {
/*
* We have the Received for addressee.
* It has to be a mailserver address, or we
* We use find_server_names() to let local
* hostnames go through.
*/
+ if (outlevel >= O_DEBUG) {
+ const char *tmps = received_for + 2;
+ size_t l = strcspn(tmps, "\r\n");
+ report(stdout, GT_("Parsing Received names \"%-.*s\"\n"), UCAST_TO_INT(l), tmps);
+ }
find_server_names(received_for, ctl, &msgblk.recipients);
- else
- {
+ } else {
/*
* We haven't extracted the envelope address.
* So check all the "Resent-To" header addresses if
* the "To" addresses.
*/
register struct addrblk *nextptr;
+ if (outlevel >= O_DEBUG)
+ report(stdout, GT_("No envelope recipient found, resorting to header guessing.\n"));
if (resent_to_addrchain) {
/* delete the "To" chain and substitute it
* with the "Resent-To" list
}
/* now look for remaining adresses */
while (to_addrchain) {
+ if (outlevel >= O_DEBUG) {
+ const char *tmps = msgblk.headers+to_addrchain->offset;
+ size_t l = strcspn(tmps, "\r\n");
+ report(stdout, GT_("Guessing from header \"%-.*s\".\n"), UCAST_TO_INT(l), tmps);
+ }
+
find_server_names(msgblk.headers+to_addrchain->offset, ctl, &msgblk.recipients);
nextptr = to_addrchain->next;
free(to_addrchain);
for (idp = msgblk.recipients; idp; idp = idp->next)
if (idp->val.status.mark == XMIT_ACCEPT)
break; /* only report first address */
- snprintf(buf+1, sizeof(buf)-1,
- "for <%s>", rcpt_address (ctl, idp->id, 1));
+ if (idp)
+ snprintf(buf+1, sizeof(buf)-1,
+ "for <%s>", rcpt_address (ctl, idp->id, 1));
snprintf(buf+strlen(buf), sizeof(buf)-strlen(buf)-1,
" (%s); ",
MULTIDROP(ctl) ? "multi-drop" : "single-drop");
suppress_tags = FALSE;
tagnum = 0;
tag[0] = '\0'; /* nuke any tag hanging out from previous query */
- protocol = (struct method *)proto;
+ protocol = proto;
shroud[0] = '\0';
}