+paramètre clé pour encode/decode +récupérer le contenu du dernier mail concerné +A FAIRE:gérer SMTP+POP+IMAP + ERREUR: Importation depuis IMAP mais erreur au niveau d'encode/decode caractère erroné qui ne s'affiche pas {???} [stable~50]
This commit is contained in:
parent
7a92932493
commit
0d628eb157
|
@ -1,4 +1,9 @@
|
|||
smtp_server = smtp.gmail.com
|
||||
smtp_port = 587
|
||||
smtp_login = equal_mailadress_or_different_login
|
||||
smtp_server = smtp.gmail.com
|
||||
smtp_port = 587
|
||||
|
||||
imap_server = imap.gmail.com
|
||||
imap_port = 993
|
||||
|
||||
mail_address = test@mail.com
|
||||
|
||||
login = equal_mailadress_or_different_login
|
||||
|
|
|
@ -2,24 +2,38 @@
|
|||
|
||||
path=$(readlink -f $(dirname $0))
|
||||
|
||||
if [ $# -eq 1 ]
|
||||
then # si 1 paramètre
|
||||
if [ $# -ge 1 ]
|
||||
then # si 1 paramètre au moins
|
||||
|
||||
if [ $# -ge 2 ] # si au moins 2 paramètres
|
||||
then
|
||||
param=$2;
|
||||
else
|
||||
param="";
|
||||
fi;
|
||||
|
||||
case $1 in
|
||||
'help') cat "$path/source/help"|less;;
|
||||
'init') # initialise le contenu du fichier de config
|
||||
echo "smtp_server = smtp.gmail.com" > "$path/.config"
|
||||
echo "smtp_port = 587" >> "$path/.config"
|
||||
echo "smtp_login = equal_mailadress_or_different_login" >> "$path/.config"
|
||||
echo "smtp_server = smtp.gmail.com" > "$path/.config"
|
||||
echo "smtp_port = 587" >> "$path/.config"
|
||||
echo "" >> "$path/.config"
|
||||
echo "imap_server = imap.gmail.com" >> "$path/.config"
|
||||
echo "imap_port = 993" >> "$path/.config"
|
||||
echo "" >> "$path/.config"
|
||||
echo "mail_address = test@mail.com" >> "$path/.config"
|
||||
echo "" >> "$path/.config"
|
||||
echo "login = equal_mailadress_or_different_login" >> "$path/.config"
|
||||
;;
|
||||
'config') nano "$path/.config";; # ouvre en modification le fichier de config
|
||||
'write') nano "$path/bucket-file";; # ouvre en modification le bucket file
|
||||
'empty') echo "">"$path/bucket-file";; # vide le bucket file
|
||||
# ouvre en lecture le bucket file
|
||||
'read') echo "\n======================================="; cat "$path/bucket-file"|less; echo "\n=======================================";;
|
||||
'encode') python "$path/source/encode.py";;
|
||||
'decode') python "$path/source/decode.py";;
|
||||
'send') python "$path/source/send.py";;
|
||||
'read') echo "\n======================================="; cat "$path/bucket-file"; echo "\n=======================================";;
|
||||
'encode') python "$path/source/encode.py" $param;;
|
||||
'decode') python "$path/source/decode.py" $param;;
|
||||
'receive') python "$path/source/receive.py" $param;;
|
||||
'send') python "$path/source/send.py" $param;;
|
||||
*) echo "Erreur";
|
||||
esac;
|
||||
else
|
||||
|
|
|
@ -6,6 +6,10 @@ import getpass, sys, os
|
|||
# RECUPERATION DU CHEMIN ABSOLU
|
||||
path = os.path.abspath( os.path.dirname(sys.argv[0]) )
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# OUVERTURE ET LECTURE DU FICHIER
|
||||
inFile = open(path + '/../bucket-file', 'r');
|
||||
m = inFile.read().decode('utf-8');
|
||||
|
@ -15,8 +19,10 @@ inFile.close();
|
|||
# DEFINITION DE L'ALPHABET
|
||||
SIGMA = getSigma();
|
||||
|
||||
# CHOIX DE LA CLE
|
||||
userkey = int( raw_input('Cle (hex ou int): '), 0);
|
||||
if( len(sys.argv) >= 2 ): # si clé en argument
|
||||
userkey = int( sys.argv[1], 0 );
|
||||
else: # sinon saisie
|
||||
userkey = int( raw_input('Cle (hex ou int): '), 0 );
|
||||
|
||||
# CALCUL de LEVEL en fonction de la clé (LEVEL = nombre de rotors)
|
||||
LEVEL = calcLevel(userkey, SIGMA);
|
||||
|
|
|
@ -15,8 +15,10 @@ inFile.close();
|
|||
# DEFINITION DE L'ALPHABET
|
||||
SIGMA = getSigma();
|
||||
|
||||
# CHOIX DE LA CLE
|
||||
userkey = int( raw_input('Cle (hex ou int): '), 0);
|
||||
if( len(sys.argv) >= 2 ): # si clé en argument
|
||||
userkey = int( sys.argv[1], 0 );
|
||||
else: # sinon saisie
|
||||
userkey = int( raw_input('Cle (hex ou int): '), 0 );
|
||||
|
||||
# CALCUL de LEVEL en fonction de la clé (LEVEL = nombre de rotors)
|
||||
LEVEL = calcLevel(userkey, SIGMA);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import email
|
||||
import imaplib
|
||||
import smtplib
|
||||
from email.MIMEMultipart import MIMEMultipart
|
||||
from email.MIMEText import MIMEText
|
||||
|
@ -16,11 +18,14 @@ def getConf(pPath):
|
|||
conf = {};
|
||||
|
||||
for i in lines:
|
||||
confKey = i[:i.index('=')].replace(' ', '');
|
||||
confVal = i[i.index('=')+1:].replace(' ', '').replace('\n', '');
|
||||
conf[confKey] = confVal;
|
||||
try:
|
||||
confKey = i[:i.index('=')].replace(' ', '');
|
||||
confVal = i[i.index('=')+1:].replace(' ', '').replace('\n', '');
|
||||
conf[confKey] = confVal;
|
||||
except ValueError:
|
||||
pass;
|
||||
|
||||
if( len(conf) == 4 ): # si le fichier de config est bien récupéré et qu'il est complet
|
||||
if( len(conf) == 6 ): # si le fichier de config est bien récupéré et qu'il est complet
|
||||
return conf;
|
||||
else:
|
||||
return False;
|
||||
|
@ -34,7 +39,7 @@ def sendMail(pConf, pPass, pTo, pSubject, pMessage):
|
|||
pMsg = MIMEMultipart();
|
||||
pMsg['From'] = pConf['mail_address'];
|
||||
pMsg['To'] = pTo;
|
||||
pMsg['Subject'] = pSubject;
|
||||
pMsg['Subject'] = "[ENIGMAIL] "+pSubject;
|
||||
|
||||
pMsg.attach( MIMEText(pMessage.encode('utf-8')) );
|
||||
|
||||
|
@ -44,7 +49,7 @@ def sendMail(pConf, pPass, pTo, pSubject, pMessage):
|
|||
srv.starttls();
|
||||
srv.ehlo();
|
||||
|
||||
srv.login(pConf['smtp_login'], pPass);
|
||||
srv.login(pConf['login'], pPass);
|
||||
srv.sendmail( pConf['mail_address'], pTo, pMsg.as_string() );
|
||||
|
||||
print "> Mail envoye !";
|
||||
|
@ -53,6 +58,27 @@ def sendMail(pConf, pPass, pTo, pSubject, pMessage):
|
|||
finally:
|
||||
srv.quit();
|
||||
|
||||
# cette fonction récupère les mails
|
||||
def getMail(pConf, pPass):
|
||||
mail = imaplib.IMAP4_SSL(pConf['imap_server'], pConf['imap_port']);
|
||||
mail.login(pConf['login'], pPass); # identification
|
||||
|
||||
mail.list();
|
||||
mail.select("inbox"); # On choisit le dossier INBOX.
|
||||
|
||||
result, data = mail.uid('search', None, '(HEADER Subject "[ENIGMAIL]")'); # on cherche les mails contenant [ENIGMAIL] dans le sujet
|
||||
latest_email_uid = data[0].split()[-1];
|
||||
result, data = mail.uid('fetch', latest_email_uid, '(RFC822)');
|
||||
m = data[0][-1];
|
||||
|
||||
# Pour le dernier mail contenant [ENIGMAIL] dans le sujet, on met le contenu dans bucket file
|
||||
body = '';
|
||||
b = email.message_from_string(m);
|
||||
if( b.is_multipart() ):
|
||||
for p in b.get_payload():
|
||||
body += p.get_payload()
|
||||
return body;
|
||||
|
||||
|
||||
|
||||
# fonction qui renvoie l'alphabet
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,26 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from enigmail import *
|
||||
import getpass, sys, os
|
||||
|
||||
# RECUPERATION DU CHEMIN ABSOLU
|
||||
path = os.path.abspath( os.path.dirname(sys.argv[0]) );
|
||||
|
||||
# paramètres utilisateurs
|
||||
conf = getConf(path);
|
||||
|
||||
if( conf == False ): # si manque des paramètres
|
||||
print "parametres manquants";
|
||||
raise SystemExit(0);
|
||||
|
||||
Pass = str( getpass.getpass('Mot de passe : ') );
|
||||
print '...';
|
||||
|
||||
# si il existe bien un mail et qu'il n'y a pas d'erreurs
|
||||
body = getMail(conf, Pass);
|
||||
if( body != '' ):
|
||||
# ECRITURE FICHIER
|
||||
outFile = open(path + '/../bucket-file', 'w');
|
||||
outFile.write( body );
|
||||
outFile.close();
|
||||
else:
|
||||
print "Erreur";
|
Loading…
Reference in New Issue