/* * conf.c -- dump fetchmail configuration as Python dictionary initializer * * For license terms, see the file COPYING in this directory. */ #include "config.h" #include "tunable.h" #include #include #if defined(STDC_HEADERS) #include #endif #if defined(HAVE_UNISTD_H) #include #endif #include #include #include #include "fetchmail.h" /* Python prettyprinting functions */ static int indent_level; static void indent(char ic) /* indent current line */ { int i; if (ic == ')' || ic == ']' || ic == '}') indent_level--; /* * The guard here is a kluge. It depends on the fact that in the * particular structure we're dumping, opening [s are always * initializers for dictionary members and thus will be preceded * by a member name. */ if (ic != '[') { for (i = 0; i < indent_level / 2; i++) putc('\t', stdout); if (indent_level % 2) fputs(" ", stdout); } if (ic) { putc(ic, stdout); putc('\n', stdout); } if (ic == '(' || ic == '[' || ic == '{') indent_level++; } static void stringdump(const char *name, const char *member) /* dump a string member with current indent */ { indent('\0'); fprintf(stdout, "\"%s\":", name); if (member) fprintf(stdout, "\"%s\"", visbuf(member)); else fputs("None", stdout); fputs(",\n", stdout); } static void numdump(const char *name, const int num) /* dump a numeric quantity at current indent */ { indent('\0'); fprintf(stdout, "'%s':%d,\n", name, NUM_VALUE_OUT(num)); } static void booldump(const char *name, const int onoff) /* dump a boolean quantity at current indent */ { indent('\0'); if (onoff) fprintf(stdout, "'%s':TRUE,\n", name); else fprintf(stdout, "'%s':FALSE,\n", name); } static void listdump(const char *name, struct idlist *list) /* dump a string list member with current indent */ { indent('\0'); fprintf(stdout, "\"%s\":", name); if (!list) fputs("None,\n", stdout); else { struct idlist *idp; fputs("[", stdout); for (idp = list; idp; idp = idp->next) if (idp->id) { fprintf(stdout, "\"%s\"", visbuf(idp->id)); if (idp->next) fputs(", ", stdout); } fputs("],\n", stdout); } } /* * Note: this function dumps the entire configuration, * after merging of the defaults record (if any). It * is intended to produce output parseable by a configuration * front end, not anything especially comfortable for humans. */ void dump_config(struct runctl *runp, struct query *querylist) /* dump the in-core configuration in recompilable form */ { struct query *ctl; struct idlist *idp; indent_level = 0; fputs("from Tkinter import TRUE, FALSE\n\n", stdout); /* * We need this in order to know whether `interface' and `monitor' * are valid options or not. */ #if defined(linux) fputs("os_type = 'linux'\n", stdout); #elif defined(__FreeBSD__) fputs("os_type = 'freebsd'\n", stdout); #else fputs("os_type = 'generic'\n", stdout); #endif /* * This should be approximately in sync with the -V option dumping * in fetchmail.c. */ printf("feature_options = ("); #ifdef POP2_ENABLE printf("'pop2',"); #endif /* POP2_ENABLE */ #ifdef POP3_ENABLE printf("'pop3',"); #endif /* POP3_ENABLE */ #ifdef IMAP_ENABLE printf("'imap',"); #endif /* IMAP_ENABLE */ #ifdef GSSAPI printf("'imap-gss',"); #endif /* GSSAPI */ #if defined(IMAP4) && defined(KERBEROS_V4) printf("'imap-k4',"); #endif /* defined(IMAP4) && defined(KERBEROS_V4) */ #ifdef RPA_ENABLE printf("'rpa',"); #endif /* RPA_ENABLE */ #ifdef SDPS_ENABLE printf("'sdps',"); #endif /* SDPS_ENABLE */ #ifdef ETRN_ENABLE printf("'etrn',"); #endif
# Set up command completion for zsh
#
fetchmailauthtypes=(password kerberos kerberos_v5)
fetchmailprotocols=(auto pop2 pop3 apop rpop kpop sdps imap imap-k4 imap-gss etrn)
function fetchmailformattedinterfaces ()
{ reply=(`ifconfig|perl -e '$/="";while(<>){s/[\r\n]//g;if(/^(\w+\d*).*inet addr:([\d\.]+)/){print "$1/$2\n";}}'`) }
function fetchmailcompctl ()
{ reply=(`awk '{ print $2 }' < ~/.fetchmailrc` `fetchmail --help 2>&1| cut -c 7-19 | sed "s/,//g"`) }
compctl -K fetchmailcompctl \
	-x "C[-1,-L|--logfile]" -f \
	-  "C[-1,-f|--fetchmailrc]" -f \
	-  "C[-1,-i|--idfile