Advertisement
LittleFox94

mailbot.sh - Mailbot in bash

Feb 16th, 2014
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.72 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Mailbot in bash
  4. # Setup some cronjobs to run this script in the given intervals:
  5. # run weekly: mailbot.sh weekly-request
  6. # run weekly the day after the other: mailbot.sh weekly-downvote
  7. # run hourly between the first and the second weekly: mailbot.sh hourly-reminder
  8. # setup your mailserver to process mails for a given mailaddress with this script
  9. # create the database, flat file with one dataset per line
  10. # fields seperated by :
  11. # fields: "email" "name" "expected count of emails (decremented on email receive, incremented on weekly-request)" "voting"
  12. #
  13. # you'll need http://pastebin.com/hxEmY1ZV, too
  14.  
  15. source /home/littlefox/bin/mailbot/functions.sh
  16.  
  17. case $1 in
  18.     received)
  19.         mail=$(cat)
  20.  
  21.         from=$(mailGetFrom "$mail")
  22.         subject=$(mailGetSubject "$mail")
  23.         expectedMails=$(getExpectedMails "$from")
  24.  
  25.         appendLog "$from:$subject:$expectedMails"
  26.  
  27.         if [ "$expectedMails" -gt "0" ]
  28.         then
  29.             decExpectedMails "$from"
  30.             incVoting "$from"
  31.             appendLog "Received mail from '$from', increased voting"
  32.         else
  33.             sendNonExpected "$from" "$subject"
  34.             appendLog "Received unexpected mail from '$from'"
  35.         fi
  36.         ;;
  37.     weekly-request)
  38.         getDevelopers | while read line
  39.         do
  40.             sendWeeklyRequest "$line"
  41.         done
  42.         ;;
  43.     weekly-downvote)
  44.         getDevelopers | while read line
  45.         do
  46.             expectedMails=$(getExpectedMails "$line")
  47.  
  48.             if [ ! "$expectedMails" = "0" ]
  49.             then
  50.                 sendWeeklyDownvote "$line"
  51.             fi
  52.         done
  53.         ;;
  54.     hourly-reminder)
  55.         getDevelopers | while read line
  56.         do
  57.             expectedMails=$(getExpectedMails "$line")
  58.  
  59.             if [ ! "$expectedMails" = 0 ]
  60.             then
  61.                 sendReminder "$line"
  62.             fi
  63.         done
  64.         ;;
  65.     *|help)
  66.         echo "Usage: mailbot.sh [ received | weekly-request | weekly-downvote ]"
  67.         ;;
  68. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement