2 * env.c -- small service routines
4 * For license terms, see the file COPYING in this directory.
10 #if defined(STDC_HEADERS)
13 #if defined(HAVE_UNISTD_H)
19 char *user, *home, *fetchmailhost;
21 extern char *program_name;
23 void envquery(int argc, char **argv)
24 /* set up basic stuff from the environment (including the rc file name) */
26 char *tmpdir, tmpbuf[BUFSIZ];
30 if ((program_name = strrchr(argv[0], '/')) != NULL)
33 program_name = argv[0];
35 if ((user = getenv("USER")) == (char *)NULL)
36 user = getenv("LOGNAME");
38 if ((user == (char *)NULL) || (home = getenv("HOME")) == (char *)NULL)
40 if ((pw = getpwuid(getuid())) != NULL)
48 "%s: can't find your name and home directory!\n",
54 /* we'll need this for the SMTP forwarding target and error messages */
55 if (gethostname(tmpbuf, sizeof(tmpbuf)))
57 fprintf(stderr, "%s: can't determine your host!", program_name);
60 fetchmailhost = xstrdup(tmpbuf);
62 #define RCFILE_NAME ".fetchmailrc"
63 rcfile = (char *) xmalloc(strlen(home)+strlen(RCFILE_NAME)+2);
66 strcat(rcfile, RCFILE_NAME);
69 char *showproto(int proto)
70 /* protocol index to protocol name mapping */
74 case P_AUTO: return("auto"); break;
76 case P_POP2: return("POP2"); break;
77 #endif /* POP2_ENABLE */
78 case P_POP3: return("POP3"); break;
79 case P_IMAP: return("IMAP"); break;
80 case P_IMAP_K4: return("IMAP-K4"); break;
81 case P_APOP: return("APOP"); break;
82 case P_RPOP: return("RPOP"); break;
83 case P_ETRN: return("ETRN"); break;
84 default: return("unknown?!?"); break;
88 char *visbuf(const char *buf)
89 /* visibilize a given string */
91 static char vbuf[BUFSIZ];
96 if (isprint(*buf) || *buf == ' ')
98 else if (*buf == '\n')
100 *tp++ = '\\'; *tp++ = 'n';
103 else if (*buf == '\r')
105 *tp++ = '\\'; *tp++ = 'r';
108 else if (*buf == '\b')
110 *tp++ = '\\'; *tp++ = 'b';
115 *tp++ = '\\'; *tp++ = '^'; *tp++ = '@' + *buf;
120 (void) sprintf(tp, "\\0x%02x", *buf++);
128 /* env.c ends here */