2 * conf.c -- dump fetchmail configuration as Python dictionary initializer
4 * For license terms, see the file COPYING in this directory.
12 #if defined(STDC_HEADERS)
15 #if defined(HAVE_UNISTD_H)
22 #include "fetchmail.h"
24 /* Python prettyprinting functions */
26 static int indent_level;
28 static void indent(char ic)
29 /* indent current line */
33 if (ic == ')' || ic == ']' || ic == '}')
37 * The guard here is a kluge. It depends on the fact that in the
38 * particular structure we're dumping, opening [s are always
39 * initializers for dictionary members and thus will be preceded
44 for (i = 0; i < indent_level / 2; i++)
56 if (ic == '(' || ic == '[' || ic == '{')
61 static void stringdump(const char *name, const char *member)
62 /* dump a string member with current indent */
65 fprintf(stdout, "\"%s\":", name);
67 fprintf(stdout, "\"%s\"", visbuf(member));
69 fputs("None", stdout);
73 static void numdump(const char *name, const int num)
74 /* dump a numeric quantity at current indent */
77 fprintf(stdout, "'%s':%d,\n", name, NUM_VALUE_OUT(num));
80 static void booldump(const char *name, const int onoff)
81 /* dump a boolean quantity at current indent */
85 fprintf(stdout, "'%s':TRUE,\n", name);
87 fprintf(stdout, "'%s':FALSE,\n", name);
90 static void listdump(const char *name, struct idlist *list)
91 /* dump a string list member with current indent */
94 fprintf(stdout, "\"%s\":", name);
97 fputs("None,\n", stdout);
103 for (idp = list; idp; idp = idp->next)
106 fprintf(stdout, "\"%s\"", visbuf(idp->id));
110 fputs("],\n", stdout);
115 * Note: this function dumps the entire configuration,
116 * after merging of the defaults record (if any). It
117 * is intended to produce output parseable by a configuration
118 * front end, not anything especially comfortable for humans.
121 void dump_config(struct runctl *runp, struct query *querylist)
122 /* dump the in-core configuration in recompilable form */
129 fputs("from Tkinter import TRUE, FALSE\n\n", stdout);
132 * We need this in order to know whether `interface' and `monitor'
133 * are valid options or not.
136 fputs("os_type = 'linux'\n", stdout);
137 #elif defined(__FreeBSD__)
138 fputs("os_type = 'freebsd'\n", stdout);
140 fputs("os_type = 'generic'\n", stdout);
144 * This should be approximately in sync with the -V option dumping
147 printf("feature_options = (");
150 #endif /* POP2_ENABLE */
153 #endif /* POP3_ENABLE */
156 #endif /* IMAP_ENABLE */
158 printf("'imap-gss',");
160 #if defined(IMAP4) && defined(KERBEROS_V4)
161 printf("'imap-k4',");
162 #endif /* defined(IMAP4) && defined(KERBEROS_V4) */
165 #endif /* RPA_ENABLE */
168 #endif /* SDPS_ENABLE */
171 #endif /* ETRN_ENABLE */
174 #endif /* SSL_ENABLE */
177 #endif /* OPIE_ENABLE */
180 #endif /* INET6_ENABLE */
183 #endif /* NET_SECURITY */
186 fputs("# Start of configuration initializer\n", stdout);
187 fputs("fetchmailrc = ", stdout);
190 numdump("poll_interval", runp->poll_interval);
191 stringdump("logfile", runp->logfile);
192 stringdump("idfile", runp->idfile);
193 stringdump("postmaster", runp->postmaster);
194 booldump("bouncemail", runp->bouncemail);
195 booldump("spambounce", runp->spambounce);
196 stringdump("properties", runp->properties);
197 booldump("invisible", runp->invisible);
198 booldump("showdots", runp->showdots);
199 booldump("syslog", runp->use_syslog);
203 fputs(" 'servers': []\n", stdout);
208 fputs("# List of server entries begins here\n", stdout);
210 fputs("'servers': ", stdout);
213 for (ctl = querylist; ctl; ctl = ctl->next)
216 * First, the server stuff.
218 if (!ctl->server.lead_server)
223 * Every time we see a leading server entry after the first one,
224 * it implicitly ends the both (a) the list of user structures
225 * associated with the previous entry, and (b) that previous entry.
237 fprintf(stdout,"# Entry for site `%s' begins:\n",ctl->server.pollname);
241 (ctl->server.protocol == P_POP3 &&
243 ctl->server.port == KPOP_PORT &&
245 ctl->server.service && !strcmp(ctl->server.service, KPOP_PORT ) &&
247 ctl->server.preauthenticate == A_KERBEROS_V4);
249 stringdump("pollname", ctl->server.pollname);
250 booldump("active", !ctl->server.skip);
251 stringdump("via", ctl->server.via);
252 stringdump("protocol",
253 using_kpop ? "KPOP" : showproto(ctl->server.protocol));
255 numdump("port", ctl->server.port);
257 stringdump("port", ctl->server.service);
259 numdump("timeout", ctl->server.timeout);
260 numdump("interval", ctl->server.interval);
262 if (ctl->server.envelope == STRING_DISABLED)
263 stringdump("envelope", NULL);
264 else if (ctl->server.envelope == NULL)
265 stringdump("envelope", "Received");
267 stringdump("envelope", ctl->server.envelope);
268 numdump("envskip", ctl->server.envskip);
269 stringdump("qvirtual", ctl->server.qvirtual);
271 if (ctl->server.preauthenticate == A_KERBEROS_V4)
272 stringdump("preauth", "kerberos_v4");
273 else if (ctl->server.preauthenticate == A_KERBEROS_V5)
274 stringdump("preauth", "kerberos_v5");
275 else if (ctl->server.preauthenticate == A_SSH)
276 stringdump("preauth", "ssh");
278 stringdump("preauth", "password");
280 #if defined(HAVE_GETHOSTBYNAME) && defined(HAVE_RES_SEARCH)
281 booldump("dns", ctl->server.dns);
282 #endif /* HAVE_GETHOSTBYNAME && HAVE_RES_SEARCH */
283 booldump("uidl", ctl->server.uidl);
285 listdump("aka", ctl->server.akalist);
286 listdump("localdomains", ctl->server.localdomains);
288 #if defined(linux) || defined(__FreeBSD__)
289 stringdump("interface", ctl->server.interface);
290 stringdump("monitor", ctl->server.monitor);
291 #endif /* linux || __FreeBSD__ */
293 stringdump("plugin", ctl->server.plugin);
294 stringdump("plugout", ctl->server.plugout);
295 stringdump("principal", ctl->server.principal);
298 fputs("'users': ", stdout);
304 stringdump("remote", ctl->remotename);
305 stringdump("password", ctl->password);
308 fprintf(stdout, "'localnames':[");
309 for (idp = ctl->localnames; idp; idp = idp->next)
311 char namebuf[USERNAMELEN + 1];
313 strncpy(namebuf, visbuf(idp->id), USERNAMELEN);
314 namebuf[USERNAMELEN] = '\0';
316 fprintf(stdout, "(\"%s\", %s)", namebuf, visbuf(idp->val.id2));
318 fprintf(stdout, "\"%s\"", namebuf);
323 fputs(", '*'", stdout);
324 fputs("],\n", stdout);
326 booldump("fetchall", ctl->fetchall);
327 booldump("keep", ctl->keep);
328 booldump("flush", ctl->flush);
329 booldump("rewrite", ctl->rewrite);
330 booldump("stripcr", ctl->stripcr);
331 booldump("forcecr", ctl->forcecr);
332 booldump("pass8bits", ctl->pass8bits);
333 booldump("dropstatus", ctl->dropstatus);
334 booldump("dropdelivered", ctl->dropdelivered);
335 booldump("mimedecode", ctl->mimedecode);
336 booldump("idle", ctl->idle);
338 stringdump("mda", ctl->mda);
339 stringdump("bsmtp", ctl->bsmtp);
341 if (ctl->listener == LMTP_MODE)
342 fputs("'lmtp':TRUE,\n", stdout);
344 fputs("'lmtp':FALSE,\n", stdout);
347 stringdump("netsec", ctl->server.netsec);
348 #endif /* INET6_ENABLE */
349 stringdump("preconnect", ctl->preconnect);
350 stringdump("postconnect", ctl->postconnect);
351 numdump("limit", ctl->limit);
352 numdump("warnings", ctl->warnings);
353 numdump("fetchlimit", ctl->fetchlimit);
354 numdump("batchlimit", ctl->batchlimit);
356 booldump("ssl", ctl->use_ssl);
357 stringdump("sslkey", ctl->sslkey);
358 stringdump("sslcert", ctl->sslcert);
359 #endif /* SSL_ENABLE */
360 numdump("expunge", ctl->expunge);
361 stringdump("properties", ctl->properties);
362 listdump("smtphunt", ctl->smtphunt);
363 stringdump("smtpaddress", ctl->smtpaddress);
364 stringdump("smtpname", ctl->smtpname);
367 fprintf(stdout, "'antispam':'");
369 fputs("'\n", stdout);
372 for (idp = ctl->antispam; idp; idp = idp->next)
374 fprintf(stdout, "%d", idp->val.status.num);
378 fputs("',\n", stdout);
380 listdump("mailboxes", ctl->mailboxes);
387 /* end last span of user entries and last server entry */
391 /* end array of servers */
395 /* end top-level dictionary */
397 fputs("# End of initializer\n", stdout);
400 /* conf.c ends here */