Gmail acess via bash - IMAP

I wrote this script to make a way to read you emails from gmail via BASH, some time after I remake it to a hack script to remote control any O.S. that use bash:

Of course I cut out the dangerous part.

This time only the gmail access... may be I'll post the powerful script someday.
#!/bin/bash
GMAIL_USER="your_gmail_user";
GMAIL_PW="Y0urGMA1LPassw0rd";
AUTH_HASH="$(echo -en "${GMAIL_USER} ${GMAIL_USER} ${GMAIL_PW}" | base64)";
SLEEP_TIME=2;
TOTAL_MESSAGES="$(
openssl s_client -crlf -connect imap.gmail.com:993 < <(
sleep ${SLEEP_TIME}; echo "A01 LOGIN $GMAIL_USER $GMAIL_PW";
sleep ${SLEEP_TIME}; echo "A02 SELECT INBOX";
sleep ${SLEEP_TIME}; echo "A02 LOGOUT";
sleep ${SLEEP_TIME}; echo "";
) 2>&1 | tr -d "\r" | grep -E "^[*] [0-9]* EXISTS$"| sed "s/^[*] \([0-9]*\) EXISTS.*$/\1/g";
)";

LAST_MAIL="$(
openssl s_client -crlf -connect imap.gmail.com:993 < <(
sleep ${SLEEP_TIME}; echo "A01 LOGIN $GMAIL_USER $GMAIL_PW";
sleep ${SLEEP_TIME}; echo "A02 SELECT INBOX";
sleep ${SLEEP_TIME}; echo "A05 FETCH $TOTAL_MESSAGES ALL";
sleep ${SLEEP_TIME}; echo "A06 FETCH $TOTAL_MESSAGES:$TOTAL_MESSAGES BODY[TEXT]";
sleep ${SLEEP_TIME}; echo "A02 LOGOUT";
sleep ${SLEEP_TIME}; echo "";
) 2>&1 | tr -d "\r"
)"

SUBJECT="RES: $(echo -e "$LAST_MAIL" | grep ENVELOPE | sed 's/^* [0-9]* FETCH (ENVELOPE ("[^"]*"[ ]"\([^"]*\)".*/\1/g')";
DEST_ADDR="$(echo -e "$LAST_MAIL" | grep ENVELOPE | sed 's/^* [0-9]* FETCH (ENVELOPE .* (("[^"]*" NIL "\([^ ]*\)" "\([^"]*\)".*/\1@\2/g')";


MAIL_BODY="$({
echo -e "
# ---------------------------------------------------------- #
# this is a automatic response from
# BASH GMAIL #
# --------------------- ORIGINAL MESSAGE ------------------- #
\n${LAST_MAIL}
";
})";

openssl s_client -crlf -connect smtp.gmail.com:465 < <(
sleep $SLEEP_TIME; echo "ehlo ${GMAIL_USER}";
sleep $SLEEP_TIME; echo "AUTH PLAIN ${AUTH_HASH}";
sleep $SLEEP_TIME; echo "mail from:<${GMAIL_USER}@gmail.com>";
sleep $SLEEP_TIME; echo "rcpt to:";
sleep $SLEEP_TIME; echo "rcpt to:<${DEST_ADDR}>";
sleep $SLEEP_TIME; echo "DATA";
sleep $SLEEP_TIME; echo "From: ${GMAIL_USER}";
sleep $SLEEP_TIME; echo "Subject: $SUBJECT";
sleep $SLEEP_TIME; echo "To: ${GMAIL_USER}.postmail@blogger.com";
sleep $SLEEP_TIME; echo "";
sleep $SLEEP_TIME; echo -e "${MAIL_BODY}";
sleep $SLEEP_TIME; echo "";
sleep $SLEEP_TIME; echo ".";
sleep $SLEEP_TIME; echo "quit";
sleep $SLEEP_TIME;
) 2>&1 | cat - > /dev/null
done;
done;

Postar um comentário

Postagens mais visitadas