You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.8 KiB
68 lines
2.8 KiB
"""Bitmessage AutoResponder""" |
|
import configparser |
|
import json |
|
import os |
|
import time |
|
import xmlrpclib |
|
|
|
class BitmessageAutoresponder(): |
|
"""Sending and receiving messages through autoresponder""" |
|
config = configparser.ConfigParser() |
|
db_var = os.path.join(os.environ["HOME"], '.config/PyBitmessage/credentials.ini') |
|
config.read(db_var) |
|
apiport = config['sqlite3']['apiport'] |
|
apiinterface = config['sqlite3']['apiinterface'] |
|
apiusername = config['sqlite3']['apiusername'] |
|
apipassword = config['sqlite3']['apipassword'] |
|
api = xmlrpclib.ServerProxy("http://%s:%s@%s:%s/"%(apiusername, apipassword, apiinterface, apiport)) |
|
expire = 300 |
|
myaddress_path = os.path.join(os.environ["HOME"],'.config/PyBitmessage/keys.dat') |
|
|
|
def send_autorepond_inbox_message(self): |
|
"""Sending Auto Message To The Recipient""" |
|
track = {} |
|
open_file = open(self.myaddress_path) |
|
get_file = open_file.read() |
|
split_file = get_file.split("\n") |
|
for lines in split_file: |
|
if len(lines) == 39: |
|
if "[" in lines: |
|
set_address=lines.strip("[]") |
|
while True: |
|
inboxmessages = json.loads(self.api.getAllInboxMessages()) |
|
inbox_var = inboxmessages.get('inboxMessages') |
|
currenttime = time.time() |
|
for values in inbox_var: |
|
msgid = values.get('msgid') |
|
toaddress = values.get('fromAddress') |
|
fromaddress = values.get('toAddress') |
|
subject = values.get('subject') |
|
message = values.get('message') |
|
try: |
|
if time.time() < track[toaddress]: |
|
continue |
|
except KeyError: |
|
pass |
|
if set_address == toaddress: |
|
continue |
|
self.api.sendMessage(toaddress, fromaddress, subject, message) |
|
self.api.trashMessage(msgid) |
|
track[toaddress] = currenttime + self.expire |
|
list_of_time_track = list(key for (key, value) in track.items() if value < currenttime) |
|
for address in list_of_time_track: |
|
track.pop(address) |
|
self.delete_outbox_message() |
|
time.sleep(10) |
|
|
|
def delete_outbox_message(self): |
|
"""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') |
|
if status_ack_rcvd in ('ackreceived', 'msgsentnoackexpected'): |
|
self.api.trashSentMessageByAckData(ackdata) |
|
|
|
if __name__ == '__main__': |
|
BitmessageAutoresponder().send_autorepond_inbox_message() |