Ubuntu Pastebin

Paste from jusss at Thu, 23 Apr 2015 02:37:29 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python3


import socket, ssl, os, io, time, sys

address=''
port=993
user=''
password=''
encoding='utf-8'
count=0
latest_recent_time=time.time()
write_file="/home/jusss/lab/mail.log"

a_socket = socket.socket()
ssl_socket = ssl.wrap_socket(a_socket)
try:
    ssl_socket.connect((address,port))
except socket.gaierror as e:
    log=open(write_file,'a')
    log.write(e.__str__())
    log.close()
    time.sleep(600)
    os.system("/home/jusss/lab/mail-notify-1.py")
    os._exit()
    

ssl_socket.write(('a_tag login ' + user + ' ' + password + '\r\n').encode(encoding))
ssl_socket.write('a_tag select inbox\r\n'.encode(encoding))
ssl_socket.write('a_tag idle\r\n'.encode(encoding))

while True:
    ssl_socket.settimeout(180)
    try:    
        recv_msg=ssl_socket.read().decode(encoding)[:-2]
    
    except socket.timeout as e:
        log1=open(write_file,'a')
        log1.write(e.__str__())
        log1.close()
        time.sleep(300)
        os.system("/home/jusss/lab/mail-notify-1.py")
        os._exit()

#   print(recv_msg)
    
    if recv_msg.find('RECENT') > -1:
        
        if count > 0:
            os.system("mplayer -noconsolecontrols -really-quiet /home/jusss/sounds/new-email.mp3 2>/dev/null")
            latest_recent_time=time.time()
        else:
            count=count+1

    if time.time() - latest_recent_time > 600:
        latest_recent_time=time.time()
        ssl_socket.write('done\r\n'.encode(encoding))
        recv_msg=ssl_socket.read().decode(encoding)[:-2]
#       print(recv_msg)
        ssl_socket.write('a_tag status inbox (unseen)\r\n'.encode(encoding))
        recv_msg=ssl_socket.read().decode(encoding)[:-2]
#       print(recv_msg)
        ssl_socket.write('a_tag idle\r\n'.encode(encoding))
        
        if recv_msg[recv_msg.find('UNSEEN')+7] != '0':
            os.system("mplayer -noconsolecontrols -really-quiet /home/jusss/sounds/new-email.mp3 2>/dev/null")


#    ssl_socket.write('a_tag status inbox (unseen)\r\n'.encode(encoding))
#    * STATUS "inbox" (UNSEEN 0)
#    idle need to be end with 'done'


[jusss@localhost lab]$ ps ax|grep mail
 8162 pts/0    S      0:00 python3 ./mail-notify-0.py
 8163 pts/0    S      0:00 python3 /home/jusss/lab/mail-notify-1.py
 8165 pts/0    S+     0:00 grep mail
[jusss@localhost lab]$ ps ax|grep mail
 8162 pts/0    S      0:00 python3 ./mail-notify-0.py
 8163 pts/0    S      0:00 python3 /home/jusss/lab/mail-notify-1.py
 8167 pts/0    S+     0:00 grep mail
[jusss@localhost lab]$ ps ax|grep mail
 8162 pts/0    S      0:00 python3 ./mail-notify-0.py
 8163 pts/0    S      0:00 python3 /home/jusss/lab/mail-notify-1.py
 8168 pts/0    S      0:00 python3 /home/jusss/lab/mail-notify-0.py
 8170 pts/0    S+     0:00 grep mail
[jusss@localhost lab]$ ps ax|grep mail
 8162 pts/0    S      0:00 python3 ./mail-notify-0.py
 8163 pts/0    S      0:00 python3 /home/jusss/lab/mail-notify-1.py
 8168 pts/0    S      0:00 python3 /home/jusss/lab/mail-notify-0.py
 8171 pts/0    S      0:00 python3 /home/jusss/lab/mail-notify-1.py
 8173 pts/0    S+     0:00 grep mail
Download as text