#!/bin/bash -x get_date() { mail_date=$(cat "$1" | grep Date:) mail_date=${mail_date##*"Date: "} unixtime_mail=$(date -d "$mail_date" +%s) unixtime_compair_max=$(date -d "2008-01-01" +%s) unixtime_compair_min=$(date -d "2007-01-01" +%s) match_date=0 if [ $unixtime_mail -lt $unixtime_compair_max ] && [ $unixtime_mail -gt $unixtime_compair_min ] then match_date=1 mail_year=$(date -d "$date" +%Y) fi #debugging echo "$match_date" echo "$mail_year" echo "$mail_date" return 1 } get_from() { mail_from=$(cat "$1" | grep From:) mail_from=${mail_from#*:} mail_from=${mail_from#*\"} mail_from=${mail_from%\"*} mail_from=${mail_from%=*} mail_from=${mail_from%<*} #debugging echo "$mail_from" return 1 } move_file() { #ATTENTION# #This fuction does not now the variable $mail_year and $mail_from [ ! -e "$mail_path/.$mail_year.$mail_from" ] && mkdir -p -m 700 "$mail_path/.$mail_year.$mail_from" && chown $mail_user.$mail_group "$mail_path/.$mail_year.$mail_from" [ ! -e "$mail_path/.$mail_year.$mail_from/cur" ] && mkdir -p -m 700 "$mail_path/.$mail_year.$mail_from/cur" && chown $mail_user.$mail_group "$mail_path/.$mail_year.$mail_from/cur" mv "$1" "$mail_path/.$mail_year.$mail_from/cur" return 1 } log_process() { log="mail_file=$1 mail_path=$mail_path mail_date=$mail_year mail_from=$mail_from location=$mail_path/.$mail_year.$mail_from/cur --- --- --- --- ---" echo "$log" >> maildir-archive.log return 1 } process_file() { check_date=$(get_date "$1") check_from=$(get_from "$1") check_move=$(move_file "$1") check_log=$(log_process "$1") } scan_directory() { for file in "$1"/* do if [ -f "$file" ] then [[ "$file" = *ashley* ]] && process_file "$file" fi if [ -d "$file" ] then scan_directory "$file" fi done } mail_path="$1" #mail_user="vmail" #mail_group="vmail" mail_user="jelle" mail_group="jelle" #cp "$mail_path" "$mail_path-backup" rm "$mail_path" cp -r "$mail_path-backup" "$mail_path" scan_directory "$1" #/etc/init.d/dovecot restart exit