aboutsummaryrefslogtreecommitdiffstats
path: root/src/mail2news.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mail2news.py')
-rw-r--r--src/mail2news.py27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/mail2news.py b/src/mail2news.py
index dc05c1d..087ad7c 100644
--- a/src/mail2news.py
+++ b/src/mail2news.py
@@ -62,8 +62,7 @@ class mail2news(object):
with open(options.input, 'r') as inp_stream:
self.message = self.__readfile(options, inp_stream)
- self.message['X-Gateway'] = 'pyg {0} {1}'.format(__version__,
- __description__)
+ self.message['X-Gateway']=f'pyg {__version__} {__description__}'
def __add_header(self, header, value, msg=None):
if msg is None:
@@ -72,14 +71,16 @@ class mail2news(object):
msg[header] = value.strip()
def __readfile(self, opt, input_stream):
- message = email.message_from_file(input_stream, policy=email.policy.SMTP)
+ message = email.message_from_file(input_stream,
+ policy=email.policy.SMTP)
if (len(message) == 0) \
and message.get_payload().startswith('/'):
msg_file_name = message.get_payload().strip()
del message
with open(msg_file_name, 'r') as msg_file:
- message = email.message_from_file(msg_file, policy=email.policy.SMTP)
+ message = email.message_from_file(msg_file,
+ policy=email.policy.SMTP)
# introduce nntpheads
self.__add_header('Newsgroups', opt.newsgroup, message)
@@ -116,7 +117,7 @@ class mail2news(object):
# if found, keep first element that seems a Msg-ID.
if (ref and len(ref)):
- self.message['References'] = '%s\n' % ref[0]
+ self.message['References'] = f'{ref[0]}\n'
except KeyError as message:
print(message)
@@ -142,7 +143,7 @@ class mail2news(object):
del self.message['Message-Id']
self.message['Message-Id'] = msgid
else:
- msgid = '<pyg.%d@tuchailepuppapera.org>\n' % (os.getpid())
+ msgid = '<pyg.{os.getpid()}@tuchailepuppapera.org>\n'
self.message['Message-Id'] = msgid
except KeyError as message:
@@ -195,15 +196,15 @@ class mail2news(object):
with tempfile.NamedTemporaryFile(suffix="eml", prefix="failed_msg",
delete=False) as tmpf:
tmpf.write(msg_bytes)
- logging.info(f"failed file name = {tmpf.name}")
+ logging.info("failed file name = %s", tmpf.name)
logging.exception("Failed to convert message!")
server.quit()
-def parse_cmdline(args):
+def parse_cmdline(arg_in):
parser = argparse.ArgumentParser(
- description='%s version %s - Copyright 2000 Cosimo Alfarano\n%s' %
- ('pyg', __version__, __description__))
+ description=f'pyg version {__version__} - Copyright 2000 Cosimo Alfarano' + \
+ f'\n{__description__}')
parser.add_argument('-s', '--newsserver', default='')
parser.add_argument('-a', '--approver', default='',
@@ -226,7 +227,7 @@ def parse_cmdline(args):
help='verbose output ' +
'(usefull with -T option for debugging)')
- args = parser.parse_args(args)
+ args = parser.parse_args(arg_in)
if not args.newsgroup:
raise argparse.ArgumentError('Error: Missing Newsgroups\n')
@@ -252,7 +253,7 @@ def main(args_in=None):
opt = parse_cmdline(args_in)
m2n = mail2news(opt)
- owner = None
+ # owner = None
"""phase 3:
format rfc 822 headers from input article
@@ -270,7 +271,7 @@ def main(args_in=None):
# wl.logmsg(m2n.heads_dict,wl.ACCEPT,owner)
if not opt.test:
try:
- resp = m2n.sendemail()
+ m2n.sendemail()
except nntplib.NNTPError as ex:
logging.exception(ex)
except KeyboardInterrupt: