X-Git-Url: https://git.sthu.org/?p=smailq.git;a=blobdiff_plain;f=smailq;h=d719d43a283e916d2a15299ba3a5218242eee328;hp=7d5286ac122f3cf6d838d20e5f60c9a5917e24a4;hb=4fbe052b37ddedb7ae917916f6670ce6242e3b01;hpb=6cb15cebfa30c025d5996bc3015b4285b25a59cf diff --git a/smailq b/smailq index 7d5286a..d719d43 100755 --- a/smailq +++ b/smailq @@ -163,8 +163,8 @@ class MailQueue: info['to'] = "" info['subject'] = "" - with open(mailfn, "r") as f: - mail = f.readlines() + with open(mailfn, "rb") as f: + mail = f.read().decode('utf8', 'replace').splitlines() for l in mail: if l.startswith("Subject:"): @@ -234,7 +234,7 @@ class MailQueue: # Read the mail mailfn = self.conf.getmailfn(id) - mailf = open(mailfn, "r") + mailf = open(mailfn, "rb") # Read the options msaargsfn = self.conf.getmsaargsfn(id) @@ -284,7 +284,7 @@ class MailQueue: # Write the mail mailfn = self.conf.getmailfn(id) - with open(mailfn, "w") as f: + with open(mailfn, "wb") as f: f.write(mail) # Write the options @@ -395,7 +395,7 @@ OPTIONS: if __name__ == "__main__": - conffn = os.path.expanduser("~/.smailq.conf") + conffn_list = [os.path.expanduser("~/.smailq.conf"), "/etc/smailq.conf"] cmd = "--list" nooptargs = [] @@ -416,7 +416,7 @@ if __name__ == "__main__": '--deliver']: cmd = opt elif opt in ['-C', '--config']: - conffn = arg + conffn_list = [arg] elif opt in ['-v', '--verbose']: verbose = True quiet = False @@ -432,8 +432,9 @@ if __name__ == "__main__": sys.exit(os.EX_USAGE) # Reading config file - if not os.path.isfile(conffn): - printerr("No such config file:", conffn) + conffn = next((f for f in conffn_list if os.path.isfile(f)), None) + if conffn is None: + printerr("No config file found: " + str(conffn_list)) sys.exit(os.EX_IOERR) conf = None try: @@ -458,7 +459,7 @@ if __name__ == "__main__": mq = MailQueue(conf) if cmd == "--send": - mail = sys.stdin.read() + mail = sys.stdin.buffer.read() mq.sendmail(mail, nooptargs) elif cmd == "--list": mq.listqueue()