2020-05-13 11:45:11 +02:00
|
|
|
import xmlrpclib
|
|
|
|
import json
|
|
|
|
import time
|
2020-05-13 17:49:21 +02:00
|
|
|
import time
|
2020-05-13 11:45:11 +02:00
|
|
|
from datetime import timedelta
|
2020-05-13 17:49:21 +02:00
|
|
|
import configparser
|
|
|
|
seconds=300
|
2020-05-13 11:45:11 +02:00
|
|
|
|
2020-05-13 17:49:21 +02:00
|
|
|
class BitmessageAutoresponder():
|
2020-05-13 11:45:11 +02:00
|
|
|
|
2020-05-13 17:49:21 +02:00
|
|
|
config = configparser.ConfigParser()
|
|
|
|
config.read('/home/cis/PyBitmessage/examples/credentials.ini')
|
|
|
|
apiusername = config['sqlite3']['apiusername']
|
|
|
|
apipassword = config['sqlite3']['apipassword']
|
|
|
|
api = xmlrpclib.ServerProxy("http://%s:%s@localhost:8442/" % (apiusername, apipassword))
|
|
|
|
|
|
|
|
def send_autorepond_inbox_message(self):
|
2020-05-13 11:45:11 +02:00
|
|
|
"""Sending Auto Message To The Recipient"""
|
|
|
|
track={}
|
|
|
|
while True:
|
|
|
|
inboxMessages=json.loads(self.api.getAllInboxMessages())
|
|
|
|
inbox_var=inboxMessages.get('inboxMessages')
|
|
|
|
for values in inbox_var:
|
|
|
|
msgid=values.get('msgid')
|
2020-05-13 17:49:21 +02:00
|
|
|
toaddress=values.get('fromAddress')
|
|
|
|
fromaddress=values.get('toAddress')
|
2020-05-13 11:45:11 +02:00
|
|
|
subject=values.get('subject')
|
|
|
|
message=values.get('message')
|
|
|
|
try:
|
2020-05-13 17:49:21 +02:00
|
|
|
if time.time() < track[toaddress]:
|
2020-05-13 11:45:11 +02:00
|
|
|
continue
|
|
|
|
except KeyError:
|
|
|
|
pass
|
2020-05-13 17:49:21 +02:00
|
|
|
ackData=self.api.sendMessage(toaddress,fromaddress,subject,message)
|
2020-05-13 11:45:11 +02:00
|
|
|
print 'The ackData is:', ackData
|
|
|
|
self.api.trashMessage(msgid)
|
2020-05-13 17:49:21 +02:00
|
|
|
global seconds
|
|
|
|
currenttime = time.time()
|
|
|
|
track[toaddress]= currenttime + seconds
|
|
|
|
list_of_time_track = list(key for (key,value) in track.items() if value < currenttime)
|
2020-05-13 11:45:11 +02:00
|
|
|
for t in list_of_time_track:
|
|
|
|
track.pop(t)
|
|
|
|
time.sleep(10)
|
|
|
|
|
2020-05-13 17:49:21 +02:00
|
|
|
def delete_outbox_message(self):
|
2020-05-13 11:45:11 +02:00
|
|
|
"""Deleting Messages from Outbox Having Status ackreceived or msgsentnoackexpected"""
|
|
|
|
SentMessage=json.loads(self.api.getAllSentMessages())
|
|
|
|
sent_var=SentMessage.get('sentMessages')
|
|
|
|
for values in sent_var:
|
|
|
|
status_ack_rcvd=values.get('status')
|
|
|
|
ackData=values.get('ackData')
|
2020-05-13 17:49:21 +02:00
|
|
|
if status_ack_rcvd in ('ackreceived','msgsentnoackexpected'):
|
2020-05-13 11:45:11 +02:00
|
|
|
self.api.trashSentMessageByAckData(ackData)
|
|
|
|
else:
|
|
|
|
print("--------********----------")
|
2020-05-13 17:49:21 +02:00
|
|
|
|
2020-05-13 11:45:11 +02:00
|
|
|
if __name__ == '__main__':
|
2020-05-13 17:49:21 +02:00
|
|
|
BitmessageAutoresponder().send_autorepond_inbox_message()
|
|
|
|
# Bitmessage_Autorespond_To_Recipient().delete_outbox_message()
|
2020-05-13 11:45:11 +02:00
|
|
|
|
|
|
|
|