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)
20 extern char *getenv(); /* needed on sysV68 R3V7.1. */
22 char *user, *home, *fetchmailhost;
24 extern char *program_name;
26 void envquery(int argc, char **argv)
27 /* set up basic stuff from the environment (including the rc file name) */
29 char *tmpdir, tmpbuf[BUFSIZ];
33 if ((program_name = strrchr(argv[0], '/')) != NULL)
36 program_name = argv[0];
38 if ((user = getenv("USER")) == (char *)NULL)
39 user = getenv("LOGNAME");
41 if ((user == (char *)NULL) || (home = getenv("HOME")) == (char *)NULL)
43 if ((pw = getpwuid(getuid())) != NULL)
51 "%s: can't find your name and home directory!\n",
57 /* we'll need this for the SMTP forwarding target and error messages */
58 if (gethostname(tmpbuf, sizeof(tmpbuf)))
60 fprintf(stderr, "%s: can't determine your host!", program_name);
63 fetchmailhost = xstrdup(tmpbuf);
65 #define RCFILE_NAME ".fetchmailrc"
66 rcfile = (char *) xmalloc(strlen(home)+strlen(RCFILE_NAME)+2);
69 strcat(rcfile, RCFILE_NAME);
72 char *showproto(int proto)
73 /* protocol index to protocol name mapping */
77 case P_AUTO: return("auto"); break;
79 case P_POP2: return("POP2"); break;
80 #endif /* POP2_ENABLE */
81 case P_POP3: return("POP3"); break;
82 case P_IMAP: return("IMAP"); break;
83 case P_IMAP_K4: return("IMAP-K4"); break;
84 case P_APOP: return("APOP"); break;
85 case P_RPOP: return("RPOP"); break;
86 case P_ETRN: return("ETRN"); break;
87 default: return("unknown?!?"); break;
91 char *visbuf(const char *buf)
92 /* visibilize a given string */
94 static char vbuf[BUFSIZ];
99 if (isprint(*buf) || *buf == ' ')
101 else if (*buf == '\n')
103 *tp++ = '\\'; *tp++ = 'n';
106 else if (*buf == '\r')
108 *tp++ = '\\'; *tp++ = 'r';
111 else if (*buf == '\b')
113 *tp++ = '\\'; *tp++ = 'b';
118 *tp++ = '\\'; *tp++ = '^'; *tp++ = '@' + *buf;
123 (void) sprintf(tp, "\\0x%02x", *buf++);
131 /* env.c ends here */