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 stringdump("properties", runp->properties);
196 booldump("invisible", runp->invisible);
197 booldump("syslog", runp->use_syslog);
201 fputs(" 'servers': []\n", stdout);
206 fputs("# List of server entries begins here\n", stdout);
208 fputs("'servers': ", stdout);
211 for (ctl = querylist; ctl; ctl = ctl->next)
214 * First, the server stuff.
216 if (!ctl->server.lead_server)
221 * Every time we see a leading server entry after the first one,
222 * it implicitly ends the both (a) the list of user structures
223 * associated with the previous entry, and (b) that previous entry.
235 fprintf(stdout,"# Entry for site `%s' begins:\n",ctl->server.pollname);
239 (ctl->server.protocol == P_POP3 &&
241 ctl->server.port == KPOP_PORT &&
243 0 == strcmp( ctl->server.service, KPOP_PORT ) &&
245 ctl->server.preauthenticate == A_KERBEROS_V4);
247 stringdump("pollname", ctl->server.pollname);
248 booldump("active", !ctl->server.skip);
249 stringdump("via", ctl->server.via);
250 stringdump("protocol",
251 using_kpop ? "KPOP" : showproto(ctl->server.protocol));
253 numdump("port", ctl->server.port);
255 stringdump("service", ctl->server.service);
257 numdump("timeout", ctl->server.timeout);
258 numdump("interval", ctl->server.interval);
260 if (ctl->server.envelope == STRING_DISABLED)
261 stringdump("envelope", NULL);
262 else if (ctl->server.envelope == NULL)
263 stringdump("envelope", "Received");
265 stringdump("envelope", ctl->server.envelope);
266 numdump("envskip", ctl->server.envskip);
267 stringdump("qvirtual", ctl->server.qvirtual);
269 if (ctl->server.preauthenticate == A_KERBEROS_V4)
270 stringdump("preauth", "kerberos_v4");
271 else if (ctl->server.preauthenticate == A_KERBEROS_V5)
272 stringdump("preauth", "kerberos_v5");
273 else if (ctl->server.preauthenticate == A_SSH)
274 stringdump("preauth", "ssh");
276 stringdump("preauth", "password");
278 #if defined(HAVE_GETHOSTBYNAME) && defined(HAVE_RES_SEARCH)
279 booldump("dns", ctl->server.dns);
280 #endif /* HAVE_GETHOSTBYNAME && HAVE_RES_SEARCH */
281 booldump("uidl", ctl->server.uidl);
283 listdump("aka", ctl->server.akalist);
284 listdump("localdomains", ctl->server.localdomains);
286 #if defined(linux) || defined(__FreeBSD__)
287 stringdump("interface", ctl->server.interface);
288 stringdump("monitor", ctl->server.monitor);
289 #endif /* linux || __FreeBSD__ */
291 stringdump("plugin", ctl->server.plugin);
292 stringdump("plugout", ctl->server.plugout);
295 fputs("'users': ", stdout);
301 stringdump("remote", ctl->remotename);
302 stringdump("password", ctl->password);
305 fprintf(stdout, "'localnames':[");
306 for (idp = ctl->localnames; idp; idp = idp->next)
308 char namebuf[USERNAMELEN + 1];
310 strncpy(namebuf, visbuf(idp->id), USERNAMELEN);
311 namebuf[USERNAMELEN] = '\0';
313 fprintf(stdout, "(\"%s\", %s)", namebuf, visbuf(idp->val.id2));
315 fprintf(stdout, "\"%s\"", namebuf);
320 fputs(", '*'", stdout);
321 fputs("],\n", stdout);
323 booldump("fetchall", ctl->fetchall);
324 booldump("keep", ctl->keep);
325 booldump("flush", ctl->flush);
326 booldump("rewrite", ctl->rewrite);
327 booldump("stripcr", ctl->stripcr);
328 booldump("forcecr", ctl->forcecr);
329 booldump("pass8bits", ctl->pass8bits);
330 booldump("dropstatus", ctl->dropstatus);
331 booldump("mimedecode", ctl->mimedecode);
333 stringdump("mda", ctl->mda);
334 stringdump("bsmtp", ctl->bsmtp);
336 if (ctl->listener == LMTP_MODE)
337 fputs("'lmtp':TRUE,\n", stdout);
339 fputs("'lmtp':FALSE,\n", stdout);
342 stringdump("netsec", ctl->server.netsec);
343 #endif /* INET6_ENABLE */
344 stringdump("preconnect", ctl->preconnect);
345 stringdump("postconnect", ctl->postconnect);
346 numdump("limit", ctl->limit);
347 numdump("warnings", ctl->warnings);
348 numdump("fetchlimit", ctl->fetchlimit);
349 numdump("batchlimit", ctl->batchlimit);
351 booldump("ssl", ctl->use_ssl);
352 stringdump("sslkey", ctl->sslkey);
353 stringdump("sslcert", ctl->sslcert);
354 #endif /* SSL_ENABLE */
355 numdump("expunge", ctl->expunge);
356 stringdump("properties", ctl->properties);
357 listdump("smtphunt", ctl->smtphunt);
358 stringdump("smtpaddress", ctl->smtpaddress);
361 fprintf(stdout, "'antispam':'");
363 fputs("'\n", stdout);
366 for (idp = ctl->antispam; idp; idp = idp->next)
368 fprintf(stdout, "%d", idp->val.status.num);
372 fputs("',\n", stdout);
374 listdump("mailboxes", ctl->mailboxes);
381 /* end last span of user entries and last server entry */
385 /* end array of servers */
389 /* end top-level dictionary */
391 fputs("# End of initializer\n", stdout);
394 /* conf.c ends here */