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);
132 fputs("# Start of initializer\n", stdout);
133 fputs("fetchmailrc = ", stdout);
136 numdump("poll_interval", runp->poll_interval);
137 booldump("syslog", runp->use_syslog);
138 stringdump("logfile", runp->logfile);
139 stringdump("idfile", runp->idfile);
140 stringdump("postmaster", runp->postmaster);
141 booldump("invisible", runp->invisible);
145 fputs(" 'servers': []\n", stdout);
150 fputs("# List of server entries begins here\n", stdout);
152 fputs("'servers': ", stdout);
155 for (ctl = querylist; ctl; ctl = ctl->next)
158 * First, the server stuff.
160 if (!ctl->server.lead_server)
165 * Every time we see a leading server entry after the first one,
166 * it implicitly ends the both (a) the list of user structures
167 * associated with the previous entry, and (b) that previous entry.
179 fprintf(stdout,"# Entry for site `%s' begins:\n",ctl->server.pollname);
183 (ctl->server.protocol == P_POP3 &&
184 ctl->server.port == KPOP_PORT &&
185 ctl->server.preauthenticate == A_KERBEROS_V4);
187 stringdump("pollname", ctl->server.pollname);
188 booldump("active", !ctl->server.skip);
189 stringdump("via", ctl->server.via);
190 stringdump("protocol",
191 using_kpop ? "KPOP" : showproto(ctl->server.protocol));
192 numdump("port", ctl->server.port);
193 numdump("timeout", ctl->server.timeout);
194 numdump("interval", ctl->server.interval);
196 if (ctl->server.envelope == STRING_DISABLED)
197 stringdump("envelope", NULL);
198 else if (ctl->server.envelope == NULL)
199 stringdump("envelope", "Received");
201 stringdump("envelope", ctl->server.envelope);
202 numdump("envskip", ctl->server.envskip);
203 stringdump("qvirtual", ctl->server.qvirtual);
205 if (ctl->server.preauthenticate == A_KERBEROS_V4)
206 stringdump("auth", "kerberos_v4");
207 else if (ctl->server.preauthenticate == A_KERBEROS_V5)
208 stringdump("auth", "kerberos_v5");
210 stringdump("auth", "password");
212 #if defined(HAVE_GETHOSTBYNAME) && defined(HAVE_RES_SEARCH)
213 booldump("dns", ctl->server.dns);
214 #endif /* HAVE_GETHOSTBYNAME && HAVE_RES_SEARCH */
215 booldump("uidl", ctl->server.uidl);
217 listdump("aka", ctl->server.akalist);
218 listdump("localdomains", ctl->server.localdomains);
221 stringdump("interface", ctl->server.interface);
222 stringdump("monitor", ctl->server.monitor);
226 fputs("'users': ", stdout);
232 stringdump("remote", ctl->remotename);
233 stringdump("password", ctl->password);
236 fprintf(stdout, "'localnames':[");
237 for (idp = ctl->localnames; idp; idp = idp->next)
240 fprintf(stdout, "('%s', %s)",
241 visbuf(idp->id), visbuf(idp->val.id2));
243 fprintf(stdout, "'%s'", visbuf(idp->id));
248 fputs(", '*'", stdout);
249 fputs("],\n", stdout);
251 booldump("fetchall", ctl->fetchall);
252 booldump("keep", ctl->keep);
253 booldump("flush", ctl->flush);
254 booldump("rewrite", ctl->rewrite);
255 booldump("stripcr", ctl->stripcr);
256 booldump("forcecr", ctl->forcecr);
257 booldump("pass8bits", ctl->pass8bits);
258 booldump("dropstatus", ctl->dropstatus);
259 booldump("mimedecode", ctl->mimedecode);
261 stringdump("mda", ctl->mda);
263 stringdump("netsec", ctl->netsec);
265 stringdump("preconnect", ctl->preconnect);
266 stringdump("postconnect", ctl->postconnect);
267 numdump("limit", ctl->limit);
268 numdump("fetchlimit", ctl->fetchlimit);
269 numdump("batchlimit", ctl->batchlimit);
270 numdump("expunge", ctl->expunge);
271 listdump("smtphunt", ctl->smtphunt);
272 stringdump("smtpaddress", ctl->smtpaddress);
273 numdump("antispam", ctl->antispam);
274 listdump("mailboxes", ctl->mailboxes);
281 /* end last span of user entries and last server entry */
285 /* end array of servers */
289 /* end top-level dictionary */
291 fputs("# End of initializer\n", stdout);
294 /* conf.c ends here */