maildir-filter-1.20/maildir-filter.10000644000175200017520000000223310105765267017703 0ustar ruosoruoso00000000000000.TH MAILDIR-FILTER 1 .\" NAME should be all caps, SECTION should be 1-8, maybe w/ subsection .\" other parms are allowed: see man(7), man(1) .SH NAME maildir-filter \- program to filter mail in Maildir folders. .SH SYNOPSIS .B maildir-filter .I "-r [-d ./Maildir/.folder | -b] [-D] [-p] [-i] [-V] [-n] [-H]" .br .SH "DESCRIPTION" .BR maildir-filter is used to filter messages in Maildir folders. It reads the message from stdin and used qmail's exit conde conventions, so it can work from your .qmail file. It can be used to bounce, deliver or just send messages do /dev/null. .PP .SH OPTIONS The programs follow the usual GNU command line syntax. A summary of options are included below. .TP .B \-r Use this regexp to match the message. It follows perl syntax. .TP .B \-D turn on a few debug messages .TP .B \-b bounce if matches .TP .B \-p print messa to stdout .TP .B \-i .case insensitive match .TP .B \-V print version and exit .TP .B \-n negate regexp (!~ m// in perl talk) .TP .B \-H only try to match the headers .TP .B \-k kill the message .SH "SEE ALSO" .B dot-qmail(5) .SH AUTHOR This manual page was written by Marcelo Bezerra . maildir-filter-1.20/maildir-filter.c0000644000175200017520000001213110105765101017746 0ustar ruosoruoso00000000000000#include #include #include #include #include #include #include #include #include #define _(X) gettext(X) #define BOUNCE 100 #define DEFERAL 111 #define STOP_PROCESSING 99 #define DONE_OK EXIT_SUCCESS #ifdef DEBUG #define D(X) (X) #else #define D(X) #endif #define VERSION "$Id: maildir-filter.c,v 1.2 2004/07/14 04:25:07 mosca Exp $" char **message=NULL; char *directory=NULL; int lines=0; int kill=0; int echo=0; int debug=0; int bounce=0; int reg_opt=0; int negated=0; int headers_only=0; pcre *regexp; pcre_extra *reg_info; void usage(int argc,char **argv); void do_bounce(); void do_kill(); void do_deliver(const char *directory, unsigned long msg_len); void version(int argc,char **argv); int main(int argc,char **argv) { char *line=NULL; int c; char *pattern=NULL; const char *err_msg=NULL; int err_offset; int matched=0; unsigned long msg_len=0; int in_headers=1; textdomain("maildir-filter"); while((c=getopt(argc,argv,"r:kd:pDibVnH"))>0) { switch(c) { case 'r': pattern=optarg; break; case 'd': directory=optarg; break; case 'p': echo=1; break; case 'V': version(argc,argv); break; case 'D': debug=1; break; case 'i': reg_opt|=PCRE_CASELESS; break; case 'b': bounce=1; break; case 'n': negated=1; break; case 'H': headers_only=1; break; case 'k': kill = 1; break; default: case ':': case '?': if(c != ':' && c != '?') fprintf(stderr,_("Unkown option: %c\n"),c); usage(argc,argv); break; } } D(fprintf(stderr,"We are running...")); if(!pattern || (!directory && !bounce)) { D(fprintf(stderr,"pattern: %s\ndirectory: %s\nbounce: %i\n",pattern,directory,bounce)); usage(argc,argv); } for(lines=0,line=malloc(BUFSIZ);line && fgets(line,BUFSIZ,stdin);lines++,line=malloc(BUFSIZ)) { size_t len = strlen(line); msg_len+=len; realloc(line, len+1); message=realloc(message,sizeof(void*) * lines+1); message[lines]=line; } if(!line || !message) { fprintf(stderr,_("%s: OOM: %s\n"),argv[0],strerror(errno)); exit(DEFERAL); } regexp=pcre_compile((const char *)pattern,reg_opt,&err_msg,&err_offset,NULL); if(!regexp) { fprintf(stderr,_("Error compiling regexp: '%s' at character %i\n"),pattern,err_offset); fprintf(stderr,"%s\n",err_msg); exit(DEFERAL); } else { reg_info=pcre_study(regexp,0,&err_msg); } for(c=0;c=0) { fprintf(stderr, "%s : %s %i,", VERSION, _("we got a match at line"),c+1); if(bounce) fprintf(stderr,_(" bouncing\n")); else fprintf(stderr, _(" delivering to %s. %lu bytes\n"), directory, msg_len); matched=1; if(!echo) break; } else if(ret<-1) { fprintf(stderr,_("Unexpect error matching string: %i\n"),ret); exit(DEFERAL); } } } } if(negated) matched = matched?0:1; if(matched) { if(bounce) do_bounce(); else if(kill) do_kill(); else do_deliver((const char *)directory, msg_len); } exit(DONE_OK); } void version(int argc,char **argv) { fprintf(stderr,"%s\n", VERSION); fprintf(stderr, " by Marcelo Bezerra \n"); exit(EXIT_SUCCESS); } void usage(int argc,char **argv) { fprintf(stderr, _("Incorrect usage\n")); fprintf(stderr, _("%s -r [-d ./Maildir/.folder | -b] [-D] [-p] [-i] [-V] [-n] [-H]\n"),argv[0]); fprintf(stderr, _("\t-b\tbounce if matches\n")); fprintf(stderr, _("\t-D\tturn on a few debug messages\n")); fprintf(stderr, _("\t-p\tprint message to stdout\n")); fprintf(stderr, _("\t-i\tcase insensitive match (m//i)\n")); fprintf(stderr, _("\t-V\tprint version and exit\n")); fprintf(stderr, _("\t-n\tnegate regexp. (!~ m//)\n")); fprintf(stderr, _("\t-k\tkill message (delete)\n")); fprintf(stderr, _("\t-H\tmatch headers only\n")); exit(DEFERAL); } void do_kill() { exit(STOP_PROCESSING); } void do_bounce() { exit(BOUNCE); } void do_deliver(const char *directory, unsigned long msg_len) { char fname[BUFSIZ]; char tmpname[BUFSIZ]; struct utsname uts; int c; FILE *fp; time_t now; now=time(NULL); uname(&uts); snprintf(tmpname, BUFSIZ-1, "%s/tmp/%lu.%u.%s,S=%lu", directory, now, getpid(), uts.nodename, msg_len); snprintf(fname, BUFSIZ-1, "%s/new/%lu.%u.%s,S=%lu", directory, now, getpid(), uts.nodename, msg_len); fp=fopen(tmpname, "w"); if(!fp) { perror("maildir-filter: do_deliver: fopen"); exit(DEFERAL); } for(c=0;c, YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2004-08-09 18:21-0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" #: mf.c:89 maildir-filter.c:89 maildir-filter.c:94 #, c-format msgid "Unkown option: %c\n" msgstr "" #: mf.c:109 maildir-filter.c:109 maildir-filter.c:114 #, c-format msgid "%s: OOM: %s\n" msgstr "" #: mf.c:115 maildir-filter.c:115 maildir-filter.c:120 #, c-format msgid "Error compiling regexp: '%s' at character %i\n" msgstr "" #: mf.c:140 maildir-filter.c:140 maildir-filter.c:145 msgid "we got a match at line" msgstr "" #: mf.c:142 maildir-filter.c:142 maildir-filter.c:147 #, c-format msgid " bouncing\n" msgstr "" #: mf.c:144 maildir-filter.c:144 maildir-filter.c:149 #, c-format msgid " delivering to %s. %lu bytes\n" msgstr "" #: mf.c:150 maildir-filter.c:150 maildir-filter.c:155 #, c-format msgid "Unexpect error matching string: %i\n" msgstr "" #: mf.c:177 maildir-filter.c:178 maildir-filter.c:185 #, c-format msgid "Incorrect usage\n" msgstr "" #: mf.c:178 maildir-filter.c:179 maildir-filter.c:186 #, c-format msgid "" "%s -r [-d ./Maildir/.folder | -b] [-D] [-p] [-i] [-V] [-n] [-H]\n" msgstr "" #: mf.c:179 maildir-filter.c:180 maildir-filter.c:187 #, c-format msgid "\t-b\tbounce if matches\n" msgstr "" #: mf.c:180 maildir-filter.c:181 maildir-filter.c:188 #, c-format msgid "\t-D\tturn on a few debug messages\n" msgstr "" #: mf.c:181 maildir-filter.c:182 maildir-filter.c:189 #, c-format msgid "\t-p\tprint message to stdout\n" msgstr "" #: mf.c:182 maildir-filter.c:183 maildir-filter.c:190 #, c-format msgid "\t-i\tcase insensitive match (m//i)\n" msgstr "" #: mf.c:183 maildir-filter.c:184 maildir-filter.c:191 #, c-format msgid "\t-V\tprint version and exit\n" msgstr "" #: mf.c:184 maildir-filter.c:185 maildir-filter.c:192 #, c-format msgid "\t-n\tnegate regexp. (!~ m//)\n" msgstr "" #: mf.c:185 maildir-filter.c:186 maildir-filter.c:194 #, c-format msgid "\t-H\tmatch headers only\n" msgstr "" #: maildir-filter.c:193 #, c-format msgid "\t-k\tkill message (delete)\n" msgstr ""