Search
Write a publication
Pull to refresh

Gmail Checker своими руками

Поскольку в портейджах Gentoo не нашел какого-либо проверщика почты для Gmail (может плохо искал), а установка НЕ из портейджей зачастую приносит много проблем, то решил написать свой скрипт, который бы был удобен для меня.
Суть скрипта проста — запускается в консоли, просит ввести Ваш логин-пароль, а полсе этого каждые 15 секунд проверяет вашу почту на gmail. Если почта есть, то вслух произносится непрочитанных сколько писем и от кого. Кроме того я прикрутил туда маленькую функцию, которая в случае ошибки соединения (нет интернета, неверный логин-пароль, или просто gmail глючит), произносит вслух «Connection Error!».
Для того, чтобы все это работало нужно, чтоб был установлена программа espeak (в Убунте она вроде стоит по умолчанию)

В общем, вот сам скрипт:
#!/bin/bash

repeat=5
refresh=15
audiofile="msg_email.wav"
vol=100

function show_info
{
clear
echo "Email: $gmail_login@gmail.com"
echo "Pass : $(echo $gmail_password|sed -e "s/./*/g")"
echo "Checking for mail every "$refresh"s"
}

function check_mail
{
mail="$(wget --secure-protocol=TLSv1 --timeout=3 -t 1 -q -O - https://${gmail_login}:${gmail_password}@mail.google.com/mail/feed/atom --no-check-certificate)"
mails="$(echo $mail| grep 'fullcount' | sed -e 's/.*//;s/<\/fullcount>.*//' 2>/dev/null)"
from=$(echo "$mail"|grep name|sed -e 's/.*//;s/<\/name>.*//'|sort|uniq|tr "\n" "&"|sed -e 's/&$//'|sed -e 's/&/, /g')
}

function connection_check
{
while ! [ "$mails" -eq "$mails" 2>/dev/null ];
do
show_info
echo "Connection error!"
espeak -g 5 -p 30 -a 200 -s 120 -w $audiofile "Connection error!" && mplayer -really-quiet -volume $vol $audiofile && rm $audiofile
process $repeat
check_mail
done
}

function process
{
for((i=0;i<$1;i++));
do
printf "."
sleep 1;
done
}

function get_login_pass
{
clear
# gmail_login="gjxnjdsq.zobr"
echo "Write your email account."
read gmail_login
echo "Write your password."

old_tty_setting=$(stty -g)
stty -icanon -echo
gmail_password=""
key="s"
while [ "$key" != '' ];
do
key=$(dd bs=1 count=1 2>/dev/null)
gmail_password+=$key;
done;
stty "$old_tty_setting"
}

function main
{
get_login_pass
while true;
do
check_mail
connection_check
while [ "$mails" -gt "0" ];
do
show_info
if [ "$mails" -gt "1" ];
then
echo "You've got $mails new messages from: $from"
espeak -g 5 -p 30 -a 200 -s 120 -w $audiofile "You've got $mails new messages from:" && mplayer -really-quiet -volume $vol $audiofile && rm $audiofile
else
echo "You've got new message from $from"
espeak -g 5 -p 30 -a 200 -s 120 -w $audiofile "You've got new message from:" && mplayer -really-quiet -volume $vol $audiofile && rm $audiofile
fi
espeak -v ru -g 5 -p 30 -a 200 -s 120 -w $audiofile "$from" && mplayer -really-quiet -volume $vol $audiofile && rm $audiofile
process $repeat
check_mail
done
show_info
process $refresh
done
exit
}

main

Tags:
Hubs:
You can’t comment this publication because its author is not yet a full member of the community. You will be able to contact the author only after he or she has been invited by someone in the community. Until then, author’s username will be hidden by an alias.