____ __ __ _ _ | _ \ ___ _ __ | \/ | __ _(_) | | |_) / _ \| '_ \| |\/| |/ _` | | | | __/ (_) | |_) | | | | (_| | | | |_| \___/| .__/|_| |_|\__,_|_|_| |_| Copyright (c) 2000 Santiago Romero Iglesias WHAT IS THIS PROGRAM FOR ======================================================================= That's my POP3-email-checker-plus-spam-eraser: just a way to browse the contents of your mailboxes and delete emails you don't want to fetch. This program will not fetch the emails (use fetchmail, jfpop or fetchpop to do this), it just applies some rules to the messages IN THE MAILBOX in order to allow you to delete some emails before receiving them (you could, as an example, delete emails with a given From: (sender) header so that forget about some common spammers). You can also filter emails larger than a specified size, using the maxsize option in your .popmailrc file (or you can disable it by commenting that line or setting it to a big number or -1). POPMail has an "easy-setup" feature: just run popmail the first time and it will create a config file asking you all what it needs to create it (pop servers, account users, passwords and ports), and then give the file the right permissions. This is the easy-setup method to configure popmail. Just answer some questions and popmail will create all for you. POPMail can log info about deleted messages on a text file (if you want) so that you can always know what's doing popmail (and see the amount of spammers you ignored :-). LICENSE ======================================================================= This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. (...Read the file GNU_License...) THANKS TO... ======================================================================= o Steven Radack (steve@lconn.net), author of mailcheck v0.1 . o Juanjo Alvarez (*puntero_loco) and Ferkys. o Jim Frost (jimf@world.std.com), for his "BSD Sockets" tutorial. o Esteban Navarro (aka ScanDisk) for the beta-testing :). o Stefan Baehre, author of PopSneaker. o Lord Iņaki Arenaza and J. A. Gutierrez for all the help given since I started programming under Linux. Surely this program (and others I've coded) would not exist without their help. HOW TO USE THIS PROGRAM ======================================================================= o Just run the popmail executable. It will open the .popmailrc file in your HOME directory, will parse it (please read the syntax in the example file given in the sources or in /usr/doc/popmail) and will enter and display the info of each pop3 server found in the config file. o If you have specified the "maxsize " option in your .popmailrc file, popmail will delete emails larger than bytes. You can disable this feature by commenting the maxsize option, (-> #maxsize 100000) or by setting it's value to a big number (well, surely you don't want to fetch a 10 Mb email, right?, so you can set it to 10000000 :-) o If .popmailrc does not exist, when you run popmail it will ask you to create it (by asking you some questions). You can also answer 'n' to popmail's question and create it by yourself. In that case, please read the INSTALL and .popmailrc.example files located in the documentation directory (usually /usr/doc/popmail-version). o Specify your filter rules in the filterfile in a similar format to the filterfile.example file. You can this way filter by looking at the message headers. Usage: popmail [options] Options: --silent Do not report info to the screen. --normal Report some info to the screen. --verbose Be verbose repporting info. --rebuildconfig Creates a new config file. --help This help. o After executing popmail, run fetchmail to retrieve the remaining email. Remember that popmail does not fetch email, it's just an anti-spam filtering program... it allows you to delete emails _BEFORE_ downloading them, so that you _never_ waste time or bandwidth _downloading_ emails you don't want to read. If you use cron (by example) to fetch email with fetchmail, replace: fetchmail by popmail; fetchmail This will clear your mailbox of spam before download messages. HOW TO INSTALL THIS PROGRAM ======================================================================= Just type the following (as root): make make install It will copy the popmail executable to /usr/local/bin (you can change that by editing the Makefile and changing DESTBINPATH), and the CHANGES, README, INSTALL, TO_DO and popmailrc.example files to /usr/doc/popmail-version (you can change it by modifying the DESTDOCPATH variable in the Makefile). After that you should create a .popmailrc file and a .filterfile in your HOME directory, containing the configuration and the filter rules. You can create it by hand or simply running popmail. It will detect that config files do not exist and it will create a config file asking you all what it needs to create it (pop server, account user, password and port), and then give the file the right permissions. This is the easy-setup method to configure popmail. Just answer some questions and popmail will create all for you. If you prefer creating them by hand, just write something like that on a $HOME/.popmailrc file: #>------->---------.popmailrc begins-------->-------># # How many accounts are defined in the file popservers 2 #--- account number 1 ---------------- server pop.somewhere.com user theuser password thepasswd port 110 #--- account number 2 ---------------- server pop.another.com user anotheruser password anotherpass port 110 # and so on..., note that # are comments (ignored). # Now we define some setup options for popmail maxsize 1000000 filterfile /home/youruser/.filterfile logfile /home/youruser/.popmail.log #>------->---------.popmailrc ends --------->-------># When creating this file, please follow the same order as the above example: first of all must be popservers . After that, you can put as blocks as defined in . Follow too the same order (first server, then user, then password and last port). Finally you can put popmail's extra options such the maxsize or the filterfile. Give it the right permissions (chmod 0600 .popmailrc), and run popmail. It will parse the config file and it will browse all the pop3 servers specified, deleting all the SPAM/Trash messages (according to the filters that you insert in the config file). Remember that you can disable any of the extra options (maxsize and filter file) just by putting a '#' at the start of the line. The maxsize option specifies the maximum size an email can have to be downloaded (popmail will erase emails bigger than maxsize, so I set it to 1000000 because I don't want to receive big emails). The filter file is just a text file which will contain the rules for the messages that must be deleted. Use '#' to write comment lines, and use the following template: #>------->-------- yourfilterfile starts ----->-------># # This is my filter file. I filter some common spammers. deny ^From:.*spammer@spammer.com deny ^From:.*@spammerserver.com deny ^From:.*spammer_changing_servers@ deny ^Subject:.*WIN MONEY deny ^Subject:.*FOR FREE deny ^Subject:.*FREE.*SEX #>------->-------- yourfilterfile ends-------->-------># This way if you are receiving spam from a given email address, or from a given domain, or tipical messages ("free sex, earn money, and so on") you can delete it by putting a filter in this file. Remember that THE MESSAGE IS DELETED ON THE SERVER, you don't need to get it to delete them. This means that you will not download the message, saving time and money. Note that POPMail does not retrieve email, it just deletes those which you don't want to receive. Call fetchmail or similar (netscape, mutt, balsa, kmail, jfpop, animail...) after executing popmail in order to retrieve the _remaining_ (no spam) messages. Take a look to the filterfile.example file... The logfile will be created by POPMail with info about each deteled message (in order you can ask the Sender or just know who is sending you spam). It looks like: POPMail - Account: mailuser on pop.mail.com at Wed Jun 14 16:02:48 2000 > Msg 13 deleted [2264 b]. Deny ^From:.*SenderEmail@somewhere.com > From: SenderEmail@somewhere.com > Subject: Buy my new computer stuff!!! POPMail - Account: mailuser on pop.mail.com at Thu Jan 14 16:02:49 2000 > Msg 2 deleted: 1217600 bytes > MAXSIZE (100000). > From: TheEmail@bigmessages.org > Subject: Get this mpeg video... about 10 minutes downloading... (and so on). You can delete this file whenever you want. I suggest using logs so that you know what's doing popmail. If you lose a message by a bad filter you put on .filterfile, you can use this file to determine the failing filter, and ask the Sender to re-send you the message. HOW TO TEST THIS PROGRAM ======================================================================= Although being version lower than 1.0, popmail is fully functional. The 0.3-0.4 version is a very low number, This is NOT because the program is dangerous or something like that, I just wanted to implement all the features in 0.1, 0.2, and 0.3 and start making it very very very stable (stable to fails, to timeouts, and so on), translate it to more languages, etc. from 0.3 to 1.0. I'll repeat it: POPMail is not dangerous: I've tested it and it works perfectly, but still needs testing, in order to find and correct any bug it could have. Of course, this is GPL'ed softwate, so this program is distributed without any warranty: if you put a filter such as Deny: .*$ and you delete all your messages, it's your fault. Of course, I've tested it enough to see that filters are working and "Deny: ^From:.*spammer@spammer.com" will only filter that email address (read the second section on this file for more info) and no more addresses. If you want to help me finding bugs, or if you just don't trust me about POPMail it's not dangerous, you can test it into your localhost (with your local mailbox) instead than testing it with your personal email. To do this, you need a POP3 server installed on your machine. I use QPOPPER (http://www.eudora.com/qpopper). Download version 3.x, untar it, and do "./configure; make; make install". You can also go to RPMFIND (rpmfind.net) enter into de RPM DATABASE, select SORT BY NAME, enter into the 'Q' and download the QPopper RPM package. After installing qpopper, edit /etc/inetd.conf and add this line: pop3 stream tcp nowait root /usr/sbin/tcpd in.qpopper The spaces are tabs. Edit /etc/services and add this line too: pop3 110/tcp # POP version 3 Now restart the inet service (or the computer :-). In Redhat you will write: /etc/rc.d/init.d/inet restart Ok, you now have a POP3 server on you machine. Now you can specify localhost (or your IP/hostname) as popserver in .popmailrc and POPMail will connect your machine and do it's job with the messages of any user. Create a new user or use a user that has no new mail into his mailbox (ls -l /var/spool/mail/user). Now we're going to insert some email there (to do testing): cat Mail/email_file_from_mutt_or_similar >> /var/spool/mail/user In my case I use: cat Mail/valux-linux-spanish.list >> /var/spool/mail/user Then I get new mail in my mailbox: [localuser@compiler localuser]$ mail Mail version 8.1 6/6/93. Type ? for help. "/var/spool/mail/localuser": 7 messages > 1 Majordomo@valux.org 32/1296 "Majordomo results: au" 2 Majordomo@valux.org 56/2167 "Welcome to valux-list" 3 Majordomo@valux.org 52/1965 "Confirmation for subs" 4 Majordomo@valux.org 56/2255 "Majordomo results: su" 5 compiler@imame.com 90/3901 "Me presento a la list" 6 luisauertes@remmmmil 63/2480 "Benaguasil P@rty 2000" 7 mana@europa2.com 56/2301 "RE: no os lo perdais" & Nice, we have now messages for testing. You can delete them in any moment by just running mail and using the d (delete) option followed by the message number to delete (exs: d 1 or d 1-7). Now we create a .popmailrc file: popservers 1 server localhost user localuser password passwd port 110 maxsize 10000000 filterfile /home/localuser/.filterfile Finally we create a .filterfile to test filters: # my filter file. It will delete (I hope) 4 messages... deny ^From:.*Majordomo@valux.org Now we're going to test popmail: POPMail - (c) 2000 Santiago Romero - Published under the GNU License. - The user localuser in localhost has 7 message(s) (16429 bytes). Message 1 deleted: Deny ^From:.*Majordomo@valux.org . Message 2 deleted: Deny ^From:.*Majordomo@valux.org . Message 3 deleted: Deny ^From:.*Majordomo@valux.org . Message 4 deleted: Deny ^From:.*Majordomo@valux.org . [localuser@compiler localuser]$ mail Mail version 8.1 6/6/93. Type ? for help. "/var/spool/mail/localuser": 3 messages > 1 compiler@imame.com 90/3901 "Me presento a la list" 2 luiafuertes@remmmmil 63/2480 "Benaguasil P@rty 2000" 3 mana@europa2.com 56/2301 "RE: no os lo perdais" So it works!!! but ... maybe while testing in your mailbox you found a bug... a timeout produced a segfault... this kind of nice bugs that the coder never finds and the user always gets ... :-) In that case email me... this is the way I want to convert 0.3 o 1.0 and make it 100% stable and usable. Once you've seen that popmail works you can use it with a remote POP3 server and report any bug you can find. In the other hand, please use the Logging Capabilities (by adding a logfile on the .popmailrc) in order to have info about deleted messages (allowing you to know what the program is doing in the background). SOME RULES ABOUT FILTERING ======================================================================= Remember that the Deny filters are regular expressions (regexp). Do "man regexp" to learn about them... I'll try to give you some guidelines there. o Using simple expresions such as the following is no dangerous: Deny ^From:.*name@domain.com Deny ^From:.*@domain.com Deny ^From:.*name@ Deny ^Subject:.*WIN.*MONEY Deny ^Subject:.*FREE.*SEX Feel free to use lots of these expressions (maybe you could escape the . character, such as explained in the next advice). In fact, my filter file is 99% plenty of expressions like the above, so the danger of losing messages by a failure when writing new filters reduces to nothing. o Escape all special characters. If you want to filter something like ^Subject:.*[eya-list].*$ (all the messages that have in the subject the string [eya-list]), DON'T DO THE FOLLOWING: Deny ^Subject:.*[eya-list].*$ THAT'S WRONG: [ and ] are special characters to regexps... they mean "any of the characters between them". If you use the above regexp as filter, you will delete all the messages that contains an 'e', an 'y', an 'a, an 'l', ... or any 't' in the subject... Almost all the Subjects will have 'a' or 'e', so you will delete all the messages. The RIGHT WAY IS THIS: Deny ^Subject:.*\[eya-list\].*$ With \ you escape the special characters and treat it as normal ones. Do the same with the . (means: any character), *, ^ and so on. Or just do man regexp and learn the nice world of regexp. :-) ABOUT THIS PROGRAM ======================================================================= o Maybe someone will think that is better to download the spam than read all the messages in the server looking for it. I've calculated that it takes more time (in my own case) to download all the spam I receive each day than filtering it at the server. Think that for small messages, testing if a message is spam can take 0.25 seconds, but downloading, reading and deleting it by hand will surely take more time... and if the message is big (I receive some 100-200 Kb html price lists) it will be ALWAYS better running popmail instead of downloading all the email. o Remember: popmail does not fetch email. Use fetchmail after calling popmail. With popmail you clean your mailbox and with fetchmail you download messages from it (the same goes for netscape, jfpop...). o I hope it will be fully usable in just a few versions :) At this moment it's not 100% stable... Santiago Romero AkA NoP/Compiler.