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 #ifdef HAVE_GETHOSTBYNAME
21 #endif /* HAVE_GETHOSTBYNAME */
23 extern char *getenv(); /* needed on sysV68 R3V7.1. */
25 char *user, *home, *fetchmailhost;
27 extern char *program_name;
29 void envquery(int argc, char **argv)
30 /* set up basic stuff from the environment (including the rc file name) */
32 char *tmpdir, tmpbuf[BUFSIZ];
36 if ((program_name = strrchr(argv[0], '/')) != NULL)
39 program_name = argv[0];
41 if ((user = getenv("USER")) == (char *)NULL)
42 user = getenv("LOGNAME");
44 if ((user == (char *)NULL) || (home = getenv("HOME")) == (char *)NULL)
46 if ((pw = getpwuid(getuid())) != NULL)
54 "%s: can't find your name and home directory!\n",
60 /* we'll need this for the SMTP forwarding target and error messages */
61 if (gethostname(tmpbuf, sizeof(tmpbuf)))
63 fprintf(stderr, "%s: can't determine your host!", program_name);
66 #ifdef HAVE_GETHOSTBYNAME
70 /* in case we got a basename (as we do in Linux) make a FQDN of it */
71 hp = gethostbyname(tmpbuf);
72 if (hp == (struct hostent *) NULL)
74 /* exit with error message */
75 fprintf(stderr, "gethostbyname failed for %s", tmpbuf);
78 strcpy(tmpbuf, hp->h_name);
80 #endif /* HAVE_GETHOSTBYNAME */
81 fetchmailhost = xstrdup(tmpbuf);
83 #define RCFILE_NAME ".fetchmailrc"
84 rcfile = (char *) xmalloc(strlen(home)+strlen(RCFILE_NAME)+2);
87 strcat(rcfile, RCFILE_NAME);
90 char *showproto(int proto)
91 /* protocol index to protocol name mapping */
95 case P_AUTO: return("auto"); break;
97 case P_POP2: return("POP2"); break;
98 #endif /* POP2_ENABLE */
99 case P_POP3: return("POP3"); break;
100 case P_IMAP: return("IMAP"); break;
101 case P_IMAP_K4: return("IMAP-K4"); break;
102 case P_APOP: return("APOP"); break;
103 case P_RPOP: return("RPOP"); break;
104 case P_ETRN: return("ETRN"); break;
105 default: return("unknown?!?"); break;
109 char *visbuf(const char *buf)
110 /* visibilize a given string */
112 static char vbuf[BUFSIZ];
117 if (isprint(*buf) || *buf == ' ')
119 else if (*buf == '\n')
121 *tp++ = '\\'; *tp++ = 'n';
124 else if (*buf == '\r')
126 *tp++ = '\\'; *tp++ = 'r';
129 else if (*buf == '\b')
131 *tp++ = '\\'; *tp++ = 'b';
136 *tp++ = '\\'; *tp++ = '^'; *tp++ = '@' + *buf;
141 (void) sprintf(tp, "\\0x%02x", *buf++);
149 /* env.c ends here */