#!/bin/bash # #Beginning of the wiki script######################################################### # File should be put to /bin. Make a symbolic link to this if you want. #Add the file to autostarted files of your desktop environment #(KDE -> ~/.kde/Autostart) #************ #in Gnome: #Control Center and then navigate to Sessions followed by Startup Programs. # modify: ~/.gnome2/session-manual # [Default] # num_clients=1 # 0,RestartClientHint=3 # 0,Priority=50 # 0,RestartCommand=gdesklets # 0,Program=gdesklets #and enjoy having mails from many sources just in one IMAP place. # # # Fetches every SLEEP seconds mails from mail accounts defined in ~/.getmail/getmailrc-something # something is string containing letters a-z, A-Z, digits 0-9 and/or minus signs "-" # SLEEP=30 # the time in seconds to wait between fetches while sleep $SLEEP; do wait # Wait for previous fetch to complete #Cleaning various backup files: #If you are going to use Grifter's script, this cleaning is necessary. Various editors #leaves hidden backup files ending with "~" character. If you used one of them to edit an #email, and the editor made such a file, Grifter's script won't work because it was made to #handle only digits which are valid names for MH. Other files are ignored. find ~/Mail -name "*~" -exec rm {} \; #If you are using emacs as an email client, it can leave autosave files (like #file#) that can #stuff your drafts folder. You can coment the line that cleans this type of files or configure #emacs not to create them or put them to a special directory. Read emacs documentation. find ~/Mail -name "*#" -exec rm {} \; # Removing messages in the trash folder deleted by Mutt: find ~/Mail/trash -name ",*" -exec rm {} \; ########################################################################################### #This script is written by Grifter from http://forums.debian.net #It scans your MH mailbox for deleted MH files (like ",1"), make them readable and put them #into trash folder which you need to create. If you use Mutt, do it withing Mutt. It doesn't #except any folder compiled not by itself. Make sure there are no files ending with charachtors #like "1~" that are left by text editors like gedit as backup files. There should be only #digits in your mailbox directories. Otherwise the script won't work. Other files are ignored. #This script works fine for me. Give it it a try. ########################################################################################### # Set this dir to be the location of where you want # the files moved, be aware that this should be the # dump for all deleted mails, it should not be an # existing mailbox that has to compete with 'real' # mails UN=/home/user/Mail/trash # Set this dir to be the root of the mailstructure # you want to search for ",filenames" DEUX=/home/user/Mail # Check for the latest mail, stripping the padding zeroes # (let doesn't preserve the padding zeroes, so we need to # re-pad them later on) VARCOUNT=`ls $UN | sed -r 's/(0*)(.*)/\2/' | tail -n 1` # Check if it's the first run, if not we'll let the var # iterate higher, so the next filename won't overwrite # the previous mail if [ -z $VARCOUNT ]; then VARCOUNT=00001 else let VARCOUNT+=1 fi # Just making sure something isn't funky if [ -f $VARCOUNT ]; then echo "ARRGH! File exists when it shouldn't! Funky Alert!" exit 1 fi # Here we start the loop to find ",filenames", when it finds one # it will test how many characters the current count has, first # testing for 5 characters where no padding is needed, if the # var doesn't have 5 chars it will test for 4, and pad one zero # infront of the count, otherwise it will continue down the list, # adding extra zeroes as needed, to make it 5 characters for i in $( find $DEUX -name ',*'); do if [ -n "`echo $VARCOUNT | grep .....`" ]; then mv $i ${UN}/${VARCOUNT} elif [ -n "`echo $VARCOUNT | grep ....`" ]; then mv $i ${UN}/0${VARCOUNT} elif [ -n "`echo $VARCOUNT | grep ...`" ]; then mv $i ${UN}/00${VARCOUNT} elif [ -n "`echo $VARCOUNT | grep ..`" ]; then mv $i ${UN}/000${VARCOUNT} elif [ -n "`echo $VARCOUNT | grep .`" ]; then mv $i ${UN}/0000${VARCOUNT} fi # ",file" has been renamed to VARCOUNT with leading zeroes if needed, now we # increase the count by one to prepare for the next iteration of the loop let VARCOUNT+=1 # Closing loop done #End of Grifter's script. ############################################################################################ # Renaiming Grifter's renamed files containing zeros into valid MH files that don't start with zeros in the trash folder: cd ~/Mail ##--Beginning of dri's script--############################################################# #The script made by dri to rename deleted MH files into valid and readable ones and put them to thetrash folder. # @(#) s1 Demonstrate move and rename. # Provide audit trail for learning and debugging. # Interchange the two debug lines to toggle printing on and off. debug="echo" debug=":" # Set up the test situation. # For production, comment out the remove and create calls. count() { local a d total a=$( ls -1 trash | wc -l ) d=$( ls -1 trash | wc -l ) total=$( expr $a ) echo " total = $total" echo " trash = $d" } count echo DIRS="trash" echo " Current state:" ls -R $DIRS trash echo $debug " audit trail of operations:" $debug highest=0 for d in $DIRS do for file in $( ls -1 $d/ | grep '^0[0-9][0-9]*$' ) do $debug " Working on $d/$file" n=${file#,} $debug " extracted :$n: from :$file: in :$d:" m=$( expr $n + 0 ) $debug " transformed $n into $m" xform=$m if [ -f trash/$xform ] then highest=$( expr $highest + 1 ) $debug " set highest number to :$highest:" while [ -f trash/$highest ] do $debug " highest increased to $highest" highest=$( expr $highest + 1 ) done mv $d/$file trash/$highest $debug " moved (bumped) $d/$file to trash/$highest" else # echo mv $d/$xform trash mv $d/$file trash/$xform $debug " moved $d/$file to trash/$xform" highest=$xform $debug " set highest number to :$highest:" fi done done echo echo " Final state:" ls -R $DIRS trash echo count ###--End of dri's script--################################################# #Wiki's script: http://gentoo-wiki.com/HOWTO_Fetch_mails_from_multiple_POP/IMAP-mailboxes_and_export_them_via_IMAP_to_Thunderbird/SquirrelMail_etc cmd="getmail -d" for file in `find ~/.getmail -regex '.*/getmailrc-[a-zA-Z0-9-]*$'`; do cmd="$cmd"" --rcfile ""$file" done echo $cmd $cmd & echo "Sleeping for $SLEEP seconds" done #End of the wiki script######################################################################