add pydoc comments, clean some useless tabs
This commit is contained in:
parent
8f0b4a38f1
commit
1a56faa145
@ -14,13 +14,14 @@ from email.header import decode_header
|
|||||||
from messaging.sms import SmsSubmit
|
from messaging.sms import SmsSubmit
|
||||||
|
|
||||||
def fetch_unread_mails():
|
def fetch_unread_mails():
|
||||||
|
"""Fetch unread emails on specific mailbox, and returns some fields"""
|
||||||
mail = imaplib.IMAP4_SSL(config.mailboxserver)
|
mail = imaplib.IMAP4_SSL(config.mailboxserver)
|
||||||
mail.login(config.mailboxlogin,config.mailboxpassword)
|
mail.login(config.mailboxlogin,config.mailboxpassword)
|
||||||
mail.list()
|
mail.list()
|
||||||
status,messages = mail.select("INBOX")
|
status,messages = mail.select("INBOX")
|
||||||
|
|
||||||
mails=[]
|
mails=[]
|
||||||
|
|
||||||
n=0
|
n=0
|
||||||
retcode, messages = mail.search(None, '(UNSEEN)')
|
retcode, messages = mail.search(None, '(UNSEEN)')
|
||||||
if retcode == 'OK':
|
if retcode == 'OK':
|
||||||
@ -41,6 +42,7 @@ def fetch_unread_mails():
|
|||||||
return mails
|
return mails
|
||||||
|
|
||||||
def clearallsms():
|
def clearallsms():
|
||||||
|
"""Clears all stored SMS on Portech like gateways"""
|
||||||
try:
|
try:
|
||||||
count=0
|
count=0
|
||||||
tn = telnetlib.Telnet(config.smshost,23)
|
tn = telnetlib.Telnet(config.smshost,23)
|
||||||
@ -58,18 +60,20 @@ def clearallsms():
|
|||||||
except:
|
except:
|
||||||
print("Unexpected error:", sys.exc_info()[0])
|
print("Unexpected error:", sys.exc_info()[0])
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
def formatsms(message):
|
def formatsms(message):
|
||||||
|
"""Strip SMS if longer than config.smssize"""
|
||||||
if len(message) > config.smssize:
|
if len(message) > config.smssize:
|
||||||
message = message[:config.smssize]
|
message = message[:config.smssize]
|
||||||
return message
|
return message
|
||||||
|
|
||||||
def imap2sms(sender,subject):
|
def imap2sms(sender,subject):
|
||||||
|
"""Uses a template to make a short message from email fields"""
|
||||||
sms=config.smstemplate % (sender,subject)
|
sms=config.smstemplate % (sender,subject)
|
||||||
return sms
|
return sms
|
||||||
|
|
||||||
def pduformat(phonenumber,message):
|
def pduformat(phonenumber,message):
|
||||||
|
"""Formats SMS using pdu encoding"""
|
||||||
sms = SmsSubmit(phonenumber, message)
|
sms = SmsSubmit(phonenumber, message)
|
||||||
pdu = sms.to_pdu()[0]
|
pdu = sms.to_pdu()[0]
|
||||||
pdustring=pdu.pdu
|
pdustring=pdu.pdu
|
||||||
@ -80,6 +84,7 @@ def pduformat(phonenumber,message):
|
|||||||
return pdustring,pdulength
|
return pdustring,pdulength
|
||||||
|
|
||||||
def sendsms(pdustring,pdulenght):
|
def sendsms(pdustring,pdulenght):
|
||||||
|
"""Send SMS using telnetlib, returns exception when issues with telnet communication"""
|
||||||
try:
|
try:
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
tn = telnetlib.Telnet(config.smshost,23)
|
tn = telnetlib.Telnet(config.smshost,23)
|
||||||
@ -103,6 +108,7 @@ def sendsms(pdustring,pdulenght):
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
|
"""Prints usage"""
|
||||||
usage="smsgateway.py subcommands : \n\n%s imap2sms\n%s sms <number> <message>\n%s clearallsms\n" % (sys.argv[0],sys.argv[0],sys.argv[0])
|
usage="smsgateway.py subcommands : \n\n%s imap2sms\n%s sms <number> <message>\n%s clearallsms\n" % (sys.argv[0],sys.argv[0],sys.argv[0])
|
||||||
return usage
|
return usage
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user