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 */
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 == '{')
60 static void stringdump(const char *name, const char *member)
61 /* dump a string member with current indent */
63 static char buf[BUFSIZ];
66 fprintf(stdout, "\"%s\":", name);
68 fprintf(stdout, "\"%s\"", visbuf(member));
70 fputs("None", stdout);
74 static int numdump(const char *name, const int num)
75 /* dump a numeric quantity at current indent */
78 fprintf(stdout, "'%s':%d,\n", name, num);
81 static int booldump(const char *name, const int onoff)
82 /* dump a boolean quantity at current indent */
86 fprintf(stdout, "'%s':TRUE,\n", name);
88 fprintf(stdout, "'%s':FALSE,\n", name);
91 static void listdump(const char *name, struct idlist *list)
92 /* dump a string list member with current indent */
95 fprintf(stdout, "\"%s\":", name);
98 fputs("None,\n", stdout);
104 for (idp = list; idp; idp = idp->next)
107 fprintf(stdout, "\"%s\"", visbuf(idp->id));
111 fputs("],\n", stdout);
116 * Note: this function dumps the entire configuration,
117 * after merging of the defaults record (if any). It
118 * is intended to produce output parseable by a configuration
119 * front end, not anything especially comfortable for humans.
122 void dump_config(struct runctl *runp, struct query *querylist)
123 /* dump the in-core configuration in recompilable form */
130 fputs("from Tkinter import TRUE, FALSE\n\n", stdout);
133 * We need this in order to know whether `interface' and `monitor'
134 * are valid options or not.
137 fputs("os_type = 'linux'\n", stdout);
139 fputs("os_type = 'generic'\n", stdout);
143 * This should be approximately in sync with the -V option dumping
146 printf("feature_options = (");
149 #endif /* POP2_ENABLE */
152 #endif /* POP3_ENABLE */
155 #endif /* IMAP_ENABLE */
157 printf("'imap-gss',");
159 #if defined(IMAP4) && defined(KERBEROS_V4)
160 printf("'imap-k4',");
161 #endif /* defined(IMAP4) && defined(KERBEROS_V4) */
164 #endif /* RPA_ENABLE */
167 #endif /* SDPS_ENABLE */
170 #endif /* ETRN_ENABLE */
179 #endif /* NET_SECURITY */
182 fputs("# Start of configuration initializer\n", stdout);
183 fputs("fetchmailrc = ", stdout);
186 numdump("poll_interval", runp->poll_interval);
187 booldump("syslog", runp->use_syslog);
188 stringdump("logfile", runp->logfile);
189 stringdump("idfile", runp->idfile);
190 stringdump("postmaster", runp->postmaster);
191 booldump("invisible", runp->invisible);
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 &&
234 ctl->server.port == KPOP_PORT &&
235 ctl->server.preauthenticate == A_KERBEROS_V4);
237 stringdump("pollname", ctl->server.pollname);
238 booldump("active", !ctl->server.skip);
239 stringdump("via", ctl->server.via);
240 stringdump("protocol",
241 using_kpop ? "KPOP" : showproto(ctl->server.protocol));
242 numdump("port", ctl->server.port);
243 numdump("timeout", ctl->server.timeout);
244 numdump("interval", ctl->server.interval);
246 if (ctl->server.envelope == STRING_DISABLED)
247 stringdump("envelope", NULL);
248 else if (ctl->server.envelope == NULL)
249 stringdump("envelope", "Received");
251 stringdump("envelope", ctl->server.envelope);
252 numdump("envskip", ctl->server.envskip);
253 stringdump("qvirtual", ctl->server.qvirtual);
255 if (ctl->server.preauthenticate == A_KERBEROS_V4)
256 stringdump("auth", "kerberos_v4");
257 else if (ctl->server.preauthenticate == A_KERBEROS_V5)
258 stringdump("auth", "kerberos_v5");
260 stringdump("auth", "password");
262 #if defined(HAVE_GETHOSTBYNAME) && defined(HAVE_RES_SEARCH)
263 booldump("dns", ctl->server.dns);
264 #endif /* HAVE_GETHOSTBYNAME && HAVE_RES_SEARCH */
265 booldump("uidl", ctl->server.uidl);
267 listdump("aka", ctl->server.akalist);
268 listdump("localdomains", ctl->server.localdomains);
271 stringdump("interface", ctl->server.interface);
272 stringdump("monitor", ctl->server.monitor);
276 fputs("'users': ", stdout);
282 stringdump("remote", ctl->remotename);
283 stringdump("password", ctl->password);
286 fprintf(stdout, "'localnames':[");
287 for (idp = ctl->localnames; idp; idp = idp->next)
289 char namebuf[USERNAMELEN + 1];
291 strncpy(namebuf, visbuf(idp->id), USERNAMELEN);
292 namebuf[USERNAMELEN] = '\0';
294 fprintf(stdout, "(\"%s\", %s)", namebuf, visbuf(idp->val.id2));
296 fprintf(stdout, "\"%s\"", namebuf);
301 fputs(", '*'", stdout);
302 fputs("],\n", stdout);
304 booldump("fetchall", ctl->fetchall);
305 booldump("keep", ctl->keep);
306 booldump("flush", ctl->flush);
307 booldump("rewrite", ctl->rewrite);
308 booldump("stripcr", ctl->stripcr);
309 booldump("forcecr", ctl->forcecr);
310 booldump("pass8bits", ctl->pass8bits);
311 booldump("dropstatus", ctl->dropstatus);
312 booldump("mimedecode", ctl->mimedecode);
314 stringdump("mda", ctl->mda);
316 stringdump("netsec", ctl->netsec);
318 stringdump("preconnect", ctl->preconnect);
319 stringdump("postconnect", ctl->postconnect);
320 numdump("limit", ctl->limit);
321 numdump("warnings", ctl->warnings);
322 numdump("fetchlimit", ctl->fetchlimit);
323 numdump("batchlimit", ctl->batchlimit);
324 numdump("expunge", ctl->expunge);
325 stringdump("properties", ctl->properties);
326 listdump("smtphunt", ctl->smtphunt);
327 stringdump("smtpaddress", ctl->smtpaddress);
330 fprintf(stdout, "'antispam':'");
332 fputs("'\n", stdout);
335 for (idp = ctl->antispam; idp; idp = idp->next)
337 fprintf(stdout, "%d", idp->val.status.num);
341 fputs("',\n", stdout);
343 listdump("mailboxes", ctl->mailboxes);
350 /* end last span of user entries and last server entry */
354 /* end array of servers */
358 /* end top-level dictionary */
360 fputs("# End of initializer\n", stdout);
363 /* conf.c ends here */