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 == '{')
60 static void stringdump(const char *name, const char *member)
61 /* dump a string member with current indent */
64 fprintf(stdout, "\"%s\":", name);
66 fprintf(stdout, "\"%s\"", visbuf(member));
68 fputs("None", stdout);
72 static void numdump(const char *name, const int num)
73 /* dump a numeric quantity at current indent */
76 fprintf(stdout, "'%s':%d,\n", name, num);
79 static void booldump(const char *name, const int onoff)
80 /* dump a boolean quantity at current indent */
84 fprintf(stdout, "'%s':TRUE,\n", name);
86 fprintf(stdout, "'%s':FALSE,\n", name);
89 static void listdump(const char *name, struct idlist *list)
90 /* dump a string list member with current indent */
93 fprintf(stdout, "\"%s\":", name);
96 fputs("None,\n", stdout);
102 for (idp = list; idp; idp = idp->next)
105 fprintf(stdout, "\"%s\"", visbuf(idp->id));
109 fputs("],\n", stdout);
114 * Note: this function dumps the entire configuration,
115 * after merging of the defaults record (if any). It
116 * is intended to produce output parseable by a configuration
117 * front end, not anything especially comfortable for humans.
120 void dump_config(struct runctl *runp, struct query *querylist)
121 /* dump the in-core configuration in recompilable form */
128 fputs("from Tkinter import TRUE, FALSE\n\n", stdout);
131 * We need this in order to know whether `interface' and `monitor'
132 * are valid options or not.
135 fputs("os_type = 'linux'\n", stdout);
137 fputs("os_type = 'generic'\n", stdout);
141 * This should be approximately in sync with the -V option dumping
144 printf("feature_options = (");
147 #endif /* POP2_ENABLE */
150 #endif /* POP3_ENABLE */
153 #endif /* IMAP_ENABLE */
155 printf("'imap-gss',");
157 #if defined(IMAP4) && defined(KERBEROS_V4)
158 printf("'imap-k4',");
159 #endif /* defined(IMAP4) && defined(KERBEROS_V4) */
162 #endif /* RPA_ENABLE */
165 #endif /* SDPS_ENABLE */
168 #endif /* ETRN_ENABLE */
177 #endif /* NET_SECURITY */
180 fputs("# Start of configuration initializer\n", stdout);
181 fputs("fetchmailrc = ", stdout);
184 numdump("poll_interval", runp->poll_interval);
185 booldump("syslog", runp->use_syslog);
186 stringdump("logfile", runp->logfile);
187 stringdump("idfile", runp->idfile);
188 stringdump("postmaster", runp->postmaster);
189 booldump("invisible", runp->invisible);
193 fputs(" 'servers': []\n", stdout);
198 fputs("# List of server entries begins here\n", stdout);
200 fputs("'servers': ", stdout);
203 for (ctl = querylist; ctl; ctl = ctl->next)
206 * First, the server stuff.
208 if (!ctl->server.lead_server)
213 * Every time we see a leading server entry after the first one,
214 * it implicitly ends the both (a) the list of user structures
215 * associated with the previous entry, and (b) that previous entry.
227 fprintf(stdout,"# Entry for site `%s' begins:\n",ctl->server.pollname);
231 (ctl->server.protocol == P_POP3 &&
232 ctl->server.port == KPOP_PORT &&
233 ctl->server.preauthenticate == A_KERBEROS_V4);
235 stringdump("pollname", ctl->server.pollname);
236 booldump("active", !ctl->server.skip);
237 stringdump("via", ctl->server.via);
238 stringdump("protocol",
239 using_kpop ? "KPOP" : showproto(ctl->server.protocol));
240 numdump("port", ctl->server.port);
241 numdump("timeout", ctl->server.timeout);
242 numdump("interval", ctl->server.interval);
244 if (ctl->server.envelope == STRING_DISABLED)
245 stringdump("envelope", NULL);
246 else if (ctl->server.envelope == NULL)
247 stringdump("envelope", "Received");
249 stringdump("envelope", ctl->server.envelope);
250 numdump("envskip", ctl->server.envskip);
251 stringdump("qvirtual", ctl->server.qvirtual);
253 if (ctl->server.preauthenticate == A_KERBEROS_V4)
254 stringdump("auth", "kerberos_v4");
255 else if (ctl->server.preauthenticate == A_KERBEROS_V5)
256 stringdump("auth", "kerberos_v5");
258 stringdump("auth", "password");
260 #if defined(HAVE_GETHOSTBYNAME) && defined(HAVE_RES_SEARCH)
261 booldump("dns", ctl->server.dns);
262 #endif /* HAVE_GETHOSTBYNAME && HAVE_RES_SEARCH */
263 booldump("uidl", ctl->server.uidl);
265 listdump("aka", ctl->server.akalist);
266 listdump("localdomains", ctl->server.localdomains);
269 stringdump("interface", ctl->server.interface);
270 stringdump("monitor", ctl->server.monitor);
274 fputs("'users': ", stdout);
280 stringdump("remote", ctl->remotename);
281 stringdump("password", ctl->password);
284 fprintf(stdout, "'localnames':[");
285 for (idp = ctl->localnames; idp; idp = idp->next)
287 char namebuf[USERNAMELEN + 1];
289 strncpy(namebuf, visbuf(idp->id), USERNAMELEN);
290 namebuf[USERNAMELEN] = '\0';
292 fprintf(stdout, "(\"%s\", %s)", namebuf, visbuf(idp->val.id2));
294 fprintf(stdout, "\"%s\"", namebuf);
299 fputs(", '*'", stdout);
300 fputs("],\n", stdout);
302 booldump("fetchall", ctl->fetchall);
303 booldump("keep", ctl->keep);
304 booldump("flush", ctl->flush);
305 booldump("rewrite", ctl->rewrite);
306 booldump("stripcr", ctl->stripcr);
307 booldump("forcecr", ctl->forcecr);
308 booldump("pass8bits", ctl->pass8bits);
309 booldump("dropstatus", ctl->dropstatus);
310 booldump("mimedecode", ctl->mimedecode);
312 stringdump("mda", ctl->mda);
313 stringdump("bsmtp", ctl->bsmtp);
315 stringdump("netsec", ctl->netsec);
317 stringdump("preconnect", ctl->preconnect);
318 stringdump("postconnect", ctl->postconnect);
319 numdump("limit", ctl->limit);
320 numdump("warnings", ctl->warnings);
321 numdump("fetchlimit", ctl->fetchlimit);
322 numdump("batchlimit", ctl->batchlimit);
323 numdump("expunge", ctl->expunge);
324 stringdump("properties", ctl->properties);
325 listdump("smtphunt", ctl->smtphunt);
326 stringdump("smtpaddress", ctl->smtpaddress);
329 fprintf(stdout, "'antispam':'");
331 fputs("'\n", stdout);
334 for (idp = ctl->antispam; idp; idp = idp->next)
336 fprintf(stdout, "%d", idp->val.status.num);
340 fputs("',\n", stdout);
342 listdump("mailboxes", ctl->mailboxes);
349 /* end last span of user entries and last server entry */
353 /* end array of servers */
357 /* end top-level dictionary */
359 fputs("# End of initializer\n", stdout);
362 /* conf.c ends here */