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);
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);
138 fputs("os_type = 'generic'\n", stdout);
142 * This should be approximately in sync with the -V option dumping
145 printf("feature_options = (");
148 #endif /* POP2_ENABLE */
151 #endif /* POP3_ENABLE */
154 #endif /* IMAP_ENABLE */
156 printf("'imap-gss',");
158 #if defined(IMAP4) && defined(KERBEROS_V4)
159 printf("'imap-k4',");
160 #endif /* defined(IMAP4) && defined(KERBEROS_V4) */
163 #endif /* RPA_ENABLE */
166 #endif /* SDPS_ENABLE */
169 #endif /* ETRN_ENABLE */
178 #endif /* NET_SECURITY */
181 fputs("# Start of configuration initializer\n", stdout);
182 fputs("fetchmailrc = ", stdout);
185 numdump("poll_interval", runp->poll_interval);
186 stringdump("logfile", runp->logfile);
187 stringdump("idfile", runp->idfile);
188 stringdump("postmaster", runp->postmaster);
189 stringdump("properties", runp->properties);
190 booldump("invisible", runp->invisible);
191 booldump("syslog", runp->use_syslog);
195 fputs(" 'servers': []\n", stdout);
200 fputs("# List of server entries begins here\n", stdout);
202 fputs("'servers': ", stdout);
205 for (ctl = querylist; ctl; ctl = ctl->next)
208 * First, the server stuff.
210 if (!ctl->server.lead_server)
215 * Every time we see a leading server entry after the first one,
216 * it implicitly ends the both (a) the list of user structures
217 * associated with the previous entry, and (b) that previous entry.
229 fprintf(stdout,"# Entry for site `%s' begins:\n",ctl->server.pollname);
233 (ctl->server.protocol == P_POP3 &&
235 ctl->server.port == KPOP_PORT &&
237 0 == strcmp( ctl->server.service, KPOP_PORT ) &&
239 ctl->server.preauthenticate == A_KERBEROS_V4);
241 stringdump("pollname", ctl->server.pollname);
242 booldump("active", !ctl->server.skip);
243 stringdump("via", ctl->server.via);
244 stringdump("protocol",
245 using_kpop ? "KPOP" : showproto(ctl->server.protocol));
247 numdump("port", ctl->server.port);
249 stringdump("service", ctl->server.service);
251 numdump("timeout", ctl->server.timeout);
252 numdump("interval", ctl->server.interval);
254 if (ctl->server.envelope == STRING_DISABLED)
255 stringdump("envelope", NULL);
256 else if (ctl->server.envelope == NULL)
257 stringdump("envelope", "Received");
259 stringdump("envelope", ctl->server.envelope);
260 numdump("envskip", ctl->server.envskip);
261 stringdump("qvirtual", ctl->server.qvirtual);
263 if (ctl->server.preauthenticate == A_KERBEROS_V4)
264 stringdump("auth", "kerberos_v4");
265 else if (ctl->server.preauthenticate == A_KERBEROS_V5)
266 stringdump("auth", "kerberos_v5");
268 stringdump("auth", "password");
270 #if defined(HAVE_GETHOSTBYNAME) && defined(HAVE_RES_SEARCH)
271 booldump("dns", ctl->server.dns);
272 #endif /* HAVE_GETHOSTBYNAME && HAVE_RES_SEARCH */
273 booldump("uidl", ctl->server.uidl);
275 listdump("aka", ctl->server.akalist);
276 listdump("localdomains", ctl->server.localdomains);
279 stringdump("interface", ctl->server.interface);
280 stringdump("monitor", ctl->server.monitor);
283 stringdump("plugin", ctl->server.plugin);
284 stringdump("plugout", ctl->server.plugout);
287 fputs("'users': ", stdout);
293 stringdump("remote", ctl->remotename);
294 stringdump("password", ctl->password);
297 fprintf(stdout, "'localnames':[");
298 for (idp = ctl->localnames; idp; idp = idp->next)
300 char namebuf[USERNAMELEN + 1];
302 strncpy(namebuf, visbuf(idp->id), USERNAMELEN);
303 namebuf[USERNAMELEN] = '\0';
305 fprintf(stdout, "(\"%s\", %s)", namebuf, visbuf(idp->val.id2));
307 fprintf(stdout, "\"%s\"", namebuf);
312 fputs(", '*'", stdout);
313 fputs("],\n", stdout);
315 booldump("fetchall", ctl->fetchall);
316 booldump("keep", ctl->keep);
317 booldump("flush", ctl->flush);
318 booldump("rewrite", ctl->rewrite);
319 booldump("stripcr", ctl->stripcr);
320 booldump("forcecr", ctl->forcecr);
321 booldump("pass8bits", ctl->pass8bits);
322 booldump("dropstatus", ctl->dropstatus);
323 booldump("mimedecode", ctl->mimedecode);
325 stringdump("mda", ctl->mda);
326 stringdump("bsmtp", ctl->bsmtp);
328 if (ctl->listener == LMTP_MODE)
329 fputs("'lmtp':TRUE,\n", stdout);
331 fputs("'lmtp':FALSE,\n", stdout);
334 stringdump("netsec", ctl->server.netsec);
336 stringdump("preconnect", ctl->preconnect);
337 stringdump("postconnect", ctl->postconnect);
338 numdump("limit", ctl->limit);
339 numdump("warnings", ctl->warnings);
340 numdump("fetchlimit", ctl->fetchlimit);
341 numdump("batchlimit", ctl->batchlimit);
342 numdump("expunge", ctl->expunge);
343 stringdump("properties", ctl->properties);
344 listdump("smtphunt", ctl->smtphunt);
345 stringdump("smtpaddress", ctl->smtpaddress);
348 fprintf(stdout, "'antispam':'");
350 fputs("'\n", stdout);
353 for (idp = ctl->antispam; idp; idp = idp->next)
355 fprintf(stdout, "%d", idp->val.status.num);
359 fputs("',\n", stdout);
361 listdump("mailboxes", ctl->mailboxes);
368 /* end last span of user entries and last server entry */
372 /* end array of servers */
376 /* end top-level dictionary */
378 fputs("# End of initializer\n", stdout);
381 /* conf.c ends here */