Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Mailbot in bash
- # Setup some cronjobs to run this script in the given intervals:
- # run weekly: mailbot.sh weekly-request
- # run weekly the day after the other: mailbot.sh weekly-downvote
- # run hourly between the first and the second weekly: mailbot.sh hourly-reminder
- # setup your mailserver to process mails for a given mailaddress with this script
- # create the database, flat file with one dataset per line
- # fields seperated by :
- # fields: "email" "name" "expected count of emails (decremented on email receive, incremented on weekly-request)" "voting"
- #
- # you'll need http://pastebin.com/hxEmY1ZV, too
- source /home/littlefox/bin/mailbot/functions.sh
- case $1 in
- received)
- mail=$(cat)
- from=$(mailGetFrom "$mail")
- subject=$(mailGetSubject "$mail")
- expectedMails=$(getExpectedMails "$from")
- appendLog "$from:$subject:$expectedMails"
- if [ "$expectedMails" -gt "0" ]
- then
- decExpectedMails "$from"
- incVoting "$from"
- appendLog "Received mail from '$from', increased voting"
- else
- sendNonExpected "$from" "$subject"
- appendLog "Received unexpected mail from '$from'"
- fi
- ;;
- weekly-request)
- getDevelopers | while read line
- do
- sendWeeklyRequest "$line"
- done
- ;;
- weekly-downvote)
- getDevelopers | while read line
- do
- expectedMails=$(getExpectedMails "$line")
- if [ ! "$expectedMails" = "0" ]
- then
- sendWeeklyDownvote "$line"
- fi
- done
- ;;
- hourly-reminder)
- getDevelopers | while read line
- do
- expectedMails=$(getExpectedMails "$line")
- if [ ! "$expectedMails" = 0 ]
- then
- sendReminder "$line"
- fi
- done
- ;;
- *|help)
- echo "Usage: mailbot.sh [ received | weekly-request | weekly-downvote ]"
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement