#include <netdb.h>
#endif /* HAVE_GETHOSTBYNAME */
#include <sys/types.h>
-#include <time.h>
#include "fetchmail.h"
#include "i18n.h"
+#if defined(HAVE_SETLOCALE) && defined(ENABLE_NLS) && defined(HAVE_STRFTIME)
+#include <locale.h>
+#endif
-extern char *getenv(); /* needed on sysV68 R3V7.1. */
-
-extern char *program_name;
+extern char *getenv(const char *); /* needed on sysV68 R3V7.1. */
void envquery(int argc, char **argv)
/* set up basic stuff from the environment (including the rc file name) */
{
struct passwd by_name, by_uid, *pwp;
- (user = getenv("FETCHMAILUSER"))
- || (user = getenv("LOGNAME"))
- || (user = getenv("USER"));
+ if (!(user = getenv("FETCHMAILUSER")))
+ {
+ if (!(user = getenv("LOGNAME")))
+ {
+ user = getenv("USER");
+ }
+ }
+
+ if ((program_name = strrchr(argv[0], '/')) != NULL)
+ ++program_name;
+ else
+ program_name = argv[0];
+
+ if (getenv("QMAILINJECT") && strcmp(getenv("QMAILINJECT"), ""))
+ {
+ fprintf(stderr,
+ GT_("%s: The QMAILINJECT environment variable is set.\n"
+ "This is dangerous as it can make qmail-inject or qmail's sendmail wrapper\n"
+ "tamper with your From: or Message-ID: headers.\n"
+ "Try \"env QMAILINJECT= %s YOUR ARGUMENTS HERE\"\n"
+ "%s: Abort.\n"),
+ program_name, program_name, program_name);
+ exit(PS_UNDEFINED);
+ }
+
+ if (getenv("NULLMAILER_FLAGS") && strcmp(getenv("NULLMAILER_FLAGS"), ""))
+ {
+ fprintf(stderr,
+ GT_("%s: The NULLMAILER_FLAGS environment variable is set.\n"
+ "This is dangerous as it can make nullmailer-inject or nullmailer's\n"
+ "sendmail wrapper tamper with your From:, Message-ID: or Return-Path: headers.\n"
+ "Try \"env NULLMAILER_FLAGS= %s YOUR ARGUMENTS HERE\"\n"
+ "%s: Abort.\n"),
+ program_name, program_name, program_name);
+ exit(PS_UNDEFINED);
+ }
if (!(pwp = getpwuid(getuid())))
{
fprintf(stderr,
- _("%s: You don't exist. Go away.\n"),
+ GT_("%s: You don't exist. Go away.\n"),
program_name);
exit(PS_UNDEFINED);
}
}
/* compute user's home directory */
- if (!(home = getenv("HOME")))
+ home = getenv("HOME_ETC");
+ if (!home && !(home = getenv("HOME")))
home = pwp->pw_dir;
/* compute fetchmail's home directory */
if (!(fmhome = getenv("FETCHMAILHOME")))
fmhome = home;
- if ((program_name = strrchr(argv[0], '/')) != NULL)
- ++program_name;
- else
- program_name = argv[0];
-
#define RCFILE_NAME "fetchmailrc"
/*
* The (fmhome==home) leaves an extra character for a . at the
if (gethostname(tmpbuf, sizeof(tmpbuf)))
{
- fprintf(stderr, _("%s: can't determine your host!"),
+ fprintf(stderr, GT_("%s: can't determine your host!"),
program_name);
exit(PS_DNS);
}
{
struct hostent *hp;
+ /** XXX FIXME: use getaddrinfo instead? */
/* if we got a basename (as we do in Linux) make a FQDN of it */
hp = gethostbyname(tmpbuf);
if (hp == (struct hostent *) NULL)
{
/* exit with error message */
fprintf(stderr,
- _("gethostbyname failed for %s\n"), tmpbuf);
+ GT_("gethostbyname failed for %s\n"), tmpbuf);
exit(PS_DNS);
}
return(xstrdup(hp->h_name));
}
if (off >= 24 * 60) /* should be impossible */
off = 23 * 60 + 59; /* if not, insert silly value */
- sprintf(offset_string, "%c%02d%02d", sign, off / 60, off % 60);
+ snprintf(offset_string, sizeof(offset_string),
+ "%c%02d%02d", sign, off / 60, off % 60);
return (offset_string);
}
* Conform to RFC822. We generate a 4-digit year here, avoiding
* Y2K hassles. Max length of this timestamp in an English locale
* should be 29 chars. The only things that should vary by locale
- * are the day and month abbreviations.
+ * are the day and month abbreviations. The set_locale calls prevent
+ * weird multibyte i18n characters (such as kanji) from showing up
+ * in your Received headers.
*/
+#if defined(HAVE_SETLOCALE) && defined(ENABLE_NLS)
+ setlocale (LC_TIME, "C");
+#endif
strftime(buf, sizeof(buf)-1,
"%a, %d %b %Y %H:%M:%S XXXXX (%Z)", localtime(&now));
+#if defined(HAVE_SETLOCALE) && defined(ENABLE_NLS)
+ setlocale (LC_TIME, "");
+#endif
strncpy(strstr(buf, "XXXXX"), tzoffset(&now), 5);
#else
/*
* date format ctime(3) emits is not RFC822
* conformant.
*/
- strcpy(buf, ctime(&now));
+ strlcpy(buf, ctime(&now), sizeof(buf));
buf[strlen(buf)-1] = '\0'; /* remove trailing \n */
#endif /* HAVE_STRFTIME */
case P_APOP: return("APOP");
case P_RPOP: return("RPOP");
#endif /* POP3_ENABLE */
+#ifdef IMAP_ENABLE
+ case P_IMAP: return("IMAP");
+#endif /* IMAP_ENABLE */
#ifdef ETRN_ENABLE
case P_ETRN: return("ETRN");
#endif /* ETRN_ENABLE */
char *visbuf(const char *buf)
/* visibilize a given string */
{
- static char vbuf[BUFSIZ];
- char *tp = vbuf;
+ static char *vbuf;
+ static size_t vbufs;
+ char *tp;
+ size_t needed;
+
+ needed = strlen(buf) * 5 + 1; /* worst case: HEX, plus NUL byte */
+
+ if (needed > vbufs) {
+ vbufs = needed;
+ vbuf = xrealloc(vbuf, vbufs);
+ }
+
+ tp = vbuf;
while (*buf)
{
- if (*buf == '"')
- {
- *tp++ = '\\'; *tp++ = '"';
- buf++;
- }
- else if (*buf == '\\')
- {
- *tp++ = '\\'; *tp++ = '\\';
- buf++;
- }
- else if (isprint(*buf) || *buf == ' ')
- *tp++ = *buf++;
- else if (*buf == '\n')
- {
- *tp++ = '\\'; *tp++ = 'n';
- buf++;
- }
- else if (*buf == '\r')
- {
- *tp++ = '\\'; *tp++ = 'r';
- buf++;
- }
- else if (*buf == '\b')
- {
- *tp++ = '\\'; *tp++ = 'b';
- buf++;
- }
- else if (*buf < ' ')
- {
- *tp++ = '\\'; *tp++ = '^'; *tp++ = '@' + *buf;
- buf++;
- }
+ if (*buf == '"') { *tp++ = '\\'; *tp++ = '"'; buf++; }
+ else if (*buf == '\\') { *tp++ = '\\'; *tp++ = '\\'; buf++; }
+ else if (isprint((unsigned char)*buf) || *buf == ' ') *tp++ = *buf++;
+ else if (*buf == '\a') { *tp++ = '\\'; *tp++ = 'a'; buf++; }
+ else if (*buf == '\b') { *tp++ = '\\'; *tp++ = 'b'; buf++; }
+ else if (*buf == '\f') { *tp++ = '\\'; *tp++ = 'f'; buf++; }
+ else if (*buf == '\n') { *tp++ = '\\'; *tp++ = 'n'; buf++; }
+ else if (*buf == '\r') { *tp++ = '\\'; *tp++ = 'r'; buf++; }
+ else if (*buf == '\t') { *tp++ = '\\'; *tp++ = 't'; buf++; }
+ else if (*buf == '\v') { *tp++ = '\\'; *tp++ = 'v'; buf++; }
else
{
- (void) sprintf(tp, "\\0x%02x", *buf++);
- tp += strlen(tp);
+ const char hex[] = "0123456789abcdef";
+ *tp++ = '\\'; *tp++ = '0'; *tp++ = 'x';
+ *tp++ = hex[*buf >> 4];
+ *tp++ = hex[*buf & 0xf];
+ buf++;
}
}
*tp++ = '\0';
return(vbuf);
}
-
/* env.c ends here */