Changed word e-mail to email in all log messages
This commit is contained in:
@@ -95,7 +95,7 @@ def list_quarantine_emails(config, args):
|
|||||||
# get quarantine object
|
# get quarantine object
|
||||||
quarantine = _get_quarantine_obj(config, args.quarantine)
|
quarantine = _get_quarantine_obj(config, args.quarantine)
|
||||||
if quarantine == None:
|
if quarantine == None:
|
||||||
raise RuntimeError("quarantine type is set to None, unable to list e-mails")
|
raise RuntimeError("quarantine type is set to None, unable to list emails")
|
||||||
|
|
||||||
# find emails and transform some metadata values to strings
|
# find emails and transform some metadata values to strings
|
||||||
emails = quarantine.find(mailfrom=args.mailfrom, recipients=args.recipients, older_than=args.older_than)
|
emails = quarantine.find(mailfrom=args.mailfrom, recipients=args.recipients, older_than=args.older_than)
|
||||||
@@ -198,7 +198,7 @@ def release_email(config, args):
|
|||||||
|
|
||||||
quarantine = _get_quarantine_obj(config, args.quarantine)
|
quarantine = _get_quarantine_obj(config, args.quarantine)
|
||||||
if quarantine == None:
|
if quarantine == None:
|
||||||
raise RuntimeError("quarantine type is set to None, unable to release e-mail")
|
raise RuntimeError("quarantine type is set to None, unable to release email")
|
||||||
|
|
||||||
quarantine.release(args.quarantine_id, args.recipient)
|
quarantine.release(args.quarantine_id, args.recipient)
|
||||||
if args.recipient:
|
if args.recipient:
|
||||||
@@ -212,13 +212,13 @@ def delete_email(config, args):
|
|||||||
|
|
||||||
quarantine = _get_quarantine_obj(config, args.quarantine)
|
quarantine = _get_quarantine_obj(config, args.quarantine)
|
||||||
if quarantine == None:
|
if quarantine == None:
|
||||||
raise RuntimeError("quarantine type is set to None, unable to delete e-mail")
|
raise RuntimeError("quarantine type is set to None, unable to delete email")
|
||||||
|
|
||||||
quarantine.delete(args.quarantine_id, args.recipient)
|
quarantine.delete(args.quarantine_id, args.recipient)
|
||||||
if args.recipient:
|
if args.recipient:
|
||||||
logger.info("successfully deleted e-mail [quarantine-id: {}] to '{}' from quarantine '{}'".format(args.quarantine_id, args.recipient, args.quarantine))
|
logger.info("successfully deleted email [quarantine-id: {}] to '{}' from quarantine '{}'".format(args.quarantine_id, args.recipient, args.quarantine))
|
||||||
else:
|
else:
|
||||||
logger.info("successfully deleted e-mail [quarantine-id: {}] from quarantine '{}'".format(args.quarantine_id, args.quarantine))
|
logger.info("successfully deleted email [quarantine-id: {}] from quarantine '{}'".format(args.quarantine_id, args.quarantine))
|
||||||
|
|
||||||
|
|
||||||
class StdErrFilter(logging.Filter):
|
class StdErrFilter(logging.Filter):
|
||||||
@@ -252,27 +252,27 @@ def main():
|
|||||||
quarantine_parser.add_argument("quarantine", metavar="QUARANTINE", help="Quarantine name.")
|
quarantine_parser.add_argument("quarantine", metavar="QUARANTINE", help="Quarantine name.")
|
||||||
quarantine_subparsers = quarantine_parser.add_subparsers()
|
quarantine_subparsers = quarantine_parser.add_subparsers()
|
||||||
# quarantine list command
|
# quarantine list command
|
||||||
quarantine_list_parser = quarantine_subparsers.add_parser("list", description="List e-mails in quarantines.", help="List e-mails in quarantine.", formatter_class=formatter_class)
|
quarantine_list_parser = quarantine_subparsers.add_parser("list", description="List emails in quarantines.", help="List emails in quarantine.", formatter_class=formatter_class)
|
||||||
quarantine_list_parser.add_argument("-f", "--from", dest="mailfrom", help="Filter e-mails by from address.", default=None, nargs="+")
|
quarantine_list_parser.add_argument("-f", "--from", dest="mailfrom", help="Filter emails by from address.", default=None, nargs="+")
|
||||||
quarantine_list_parser.add_argument("-t", "--to", dest="recipients", help="Filter e-mails by recipient address.", default=None, nargs="+")
|
quarantine_list_parser.add_argument("-t", "--to", dest="recipients", help="Filter emails by recipient address.", default=None, nargs="+")
|
||||||
quarantine_list_parser.add_argument("-o", "--older-than", dest="older_than", help="Filter e-mails by age (days).", default=None, type=float)
|
quarantine_list_parser.add_argument("-o", "--older-than", dest="older_than", help="Filter emails by age (days).", default=None, type=float)
|
||||||
quarantine_list_parser.add_argument("-b", "--batch", help="Print results using only e-mail quarantine IDs, each on a new line.", action="store_true")
|
quarantine_list_parser.add_argument("-b", "--batch", help="Print results using only email quarantine IDs, each on a new line.", action="store_true")
|
||||||
quarantine_list_parser.set_defaults(func=list_quarantine_emails)
|
quarantine_list_parser.set_defaults(func=list_quarantine_emails)
|
||||||
# quarantine release command
|
# quarantine release command
|
||||||
quarantine_release_parser = quarantine_subparsers.add_parser("release", description="Release e-mail from quarantine.", help="Release e-mail from quarantine.", formatter_class=formatter_class)
|
quarantine_release_parser = quarantine_subparsers.add_parser("release", description="Release email from quarantine.", help="Release email from quarantine.", formatter_class=formatter_class)
|
||||||
quarantine_release_parser.add_argument("quarantine_id", metavar="ID", help="Quarantine ID.")
|
quarantine_release_parser.add_argument("quarantine_id", metavar="ID", help="Quarantine ID.")
|
||||||
quarantine_release_parser.add_argument("-n", "--disable-syslog", dest="syslog", help="Disable syslog messages.", action="store_false")
|
quarantine_release_parser.add_argument("-n", "--disable-syslog", dest="syslog", help="Disable syslog messages.", action="store_false")
|
||||||
quarantine_release_parser_group = quarantine_release_parser.add_mutually_exclusive_group(required=True)
|
quarantine_release_parser_group = quarantine_release_parser.add_mutually_exclusive_group(required=True)
|
||||||
quarantine_release_parser_group.add_argument("-t", "--to", dest="recipient", help="Release e-mail for one recipient address.")
|
quarantine_release_parser_group.add_argument("-t", "--to", dest="recipient", help="Release email for one recipient address.")
|
||||||
quarantine_release_parser_group.add_argument("-a", "--all", help="Release e-mail for all recipients.", action="store_true")
|
quarantine_release_parser_group.add_argument("-a", "--all", help="Release email for all recipients.", action="store_true")
|
||||||
quarantine_release_parser.set_defaults(func=release_email)
|
quarantine_release_parser.set_defaults(func=release_email)
|
||||||
# quarantine delete command
|
# quarantine delete command
|
||||||
quarantine_delete_parser = quarantine_subparsers.add_parser("delete", description="Delete e-mail from quarantine.", help="Delete e-mail from quarantine.", formatter_class=formatter_class)
|
quarantine_delete_parser = quarantine_subparsers.add_parser("delete", description="Delete email from quarantine.", help="Delete email from quarantine.", formatter_class=formatter_class)
|
||||||
quarantine_delete_parser.add_argument("quarantine_id", metavar="ID", help="Quarantine ID.")
|
quarantine_delete_parser.add_argument("quarantine_id", metavar="ID", help="Quarantine ID.")
|
||||||
quarantine_delete_parser.add_argument("-n", "--disable-syslog", dest="syslog", help="Disable syslog messages.", action="store_false")
|
quarantine_delete_parser.add_argument("-n", "--disable-syslog", dest="syslog", help="Disable syslog messages.", action="store_false")
|
||||||
quarantine_delete_parser_group = quarantine_delete_parser.add_mutually_exclusive_group(required=True)
|
quarantine_delete_parser_group = quarantine_delete_parser.add_mutually_exclusive_group(required=True)
|
||||||
quarantine_delete_parser_group.add_argument("-t", "--to", dest="recipient", help="Delete e-mail for one recipient address.")
|
quarantine_delete_parser_group.add_argument("-t", "--to", dest="recipient", help="Delete email for one recipient address.")
|
||||||
quarantine_delete_parser_group.add_argument("-a", "--all", help="Delete e-mail for all recipients.", action="store_true")
|
quarantine_delete_parser_group.add_argument("-a", "--all", help="Delete email for all recipients.", action="store_true")
|
||||||
quarantine_delete_parser.set_defaults(func=delete_email)
|
quarantine_delete_parser.set_defaults(func=delete_email)
|
||||||
|
|
||||||
# whitelist command group
|
# whitelist command group
|
||||||
@@ -283,7 +283,7 @@ def main():
|
|||||||
whitelist_list_parser = whitelist_subparsers.add_parser("list", description="List whitelist entries.", help="List whitelist entries.", formatter_class=formatter_class)
|
whitelist_list_parser = whitelist_subparsers.add_parser("list", description="List whitelist entries.", help="List whitelist entries.", formatter_class=formatter_class)
|
||||||
whitelist_list_parser.add_argument("-f", "--from", dest="mailfrom", help="Filter entries by from address.", default=None, nargs="+")
|
whitelist_list_parser.add_argument("-f", "--from", dest="mailfrom", help="Filter entries by from address.", default=None, nargs="+")
|
||||||
whitelist_list_parser.add_argument("-t", "--to", dest="recipients", help="Filter entries by recipient address.", default=None, nargs="+")
|
whitelist_list_parser.add_argument("-t", "--to", dest="recipients", help="Filter entries by recipient address.", default=None, nargs="+")
|
||||||
whitelist_list_parser.add_argument("-o", "--older-than", dest="older_than", help="Filter e-mails by last used date (days).", default=None, type=float)
|
whitelist_list_parser.add_argument("-o", "--older-than", dest="older_than", help="Filter emails by last used date (days).", default=None, type=float)
|
||||||
whitelist_list_parser.set_defaults(func=list_whitelist)
|
whitelist_list_parser.set_defaults(func=list_whitelist)
|
||||||
# whitelist add command
|
# whitelist add command
|
||||||
whitelist_add_parser = whitelist_subparsers.add_parser("add", description="Add whitelist entry.", help="Add whitelist entry.", formatter_class=formatter_class)
|
whitelist_add_parser = whitelist_subparsers.add_parser("add", description="Add whitelist entry.", help="Add whitelist entry.", formatter_class=formatter_class)
|
||||||
|
|||||||
@@ -34,24 +34,24 @@ class BaseQuarantine(object):
|
|||||||
self.logger = logging.getLogger(__name__)
|
self.logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
def add(self, queueid, mailfrom, recipients, fp):
|
def add(self, queueid, mailfrom, recipients, fp):
|
||||||
"Add e-mail to quarantine."
|
"Add email to quarantine."
|
||||||
fp.seek(0)
|
fp.seek(0)
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def find(self, mailfrom=None, recipients=None, older_than=None):
|
def find(self, mailfrom=None, recipients=None, older_than=None):
|
||||||
"Find e-mails in quarantine."
|
"Find emails in quarantine."
|
||||||
return
|
return
|
||||||
|
|
||||||
def get_metadata(self, quarantine_id):
|
def get_metadata(self, quarantine_id):
|
||||||
"Return metadata of quarantined e-mail."
|
"Return metadata of quarantined email."
|
||||||
return
|
return
|
||||||
|
|
||||||
def delete(self, quarantine_id, recipient=None):
|
def delete(self, quarantine_id, recipient=None):
|
||||||
"Delete e-mail from quarantine."
|
"Delete email from quarantine."
|
||||||
return
|
return
|
||||||
|
|
||||||
def release(self, quarantine_id, recipient=None):
|
def release(self, quarantine_id, recipient=None):
|
||||||
"Release e-mail from quarantine."
|
"Release email from quarantine."
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ class FileQuarantine(BaseQuarantine):
|
|||||||
raise RuntimeError("unable to remove data file: {}".format(e))
|
raise RuntimeError("unable to remove data file: {}".format(e))
|
||||||
|
|
||||||
def add(self, queueid, mailfrom, recipients, fp):
|
def add(self, queueid, mailfrom, recipients, fp):
|
||||||
"Add e-mail to file quarantine and return quarantine-id."
|
"Add email to file quarantine and return quarantine-id."
|
||||||
super(FileQuarantine, self).add(queueid, mailfrom, recipients, fp)
|
super(FileQuarantine, self).add(queueid, mailfrom, recipients, fp)
|
||||||
quarantine_id = "{}_{}".format(datetime.now().strftime("%Y%m%d%H%M%S"), queueid)
|
quarantine_id = "{}_{}".format(datetime.now().strftime("%Y%m%d%H%M%S"), queueid)
|
||||||
|
|
||||||
@@ -128,7 +128,7 @@ class FileQuarantine(BaseQuarantine):
|
|||||||
return quarantine_id
|
return quarantine_id
|
||||||
|
|
||||||
def get_metadata(self, quarantine_id):
|
def get_metadata(self, quarantine_id):
|
||||||
"Return metadata of quarantined e-mail."
|
"Return metadata of quarantined email."
|
||||||
super(FileQuarantine, self).get_metadata(quarantine_id)
|
super(FileQuarantine, self).get_metadata(quarantine_id)
|
||||||
|
|
||||||
metafile = os.path.join(self.directory, "{}{}".format(quarantine_id, self._metadata_suffix))
|
metafile = os.path.join(self.directory, "{}{}".format(quarantine_id, self._metadata_suffix))
|
||||||
@@ -146,7 +146,7 @@ class FileQuarantine(BaseQuarantine):
|
|||||||
return metadata
|
return metadata
|
||||||
|
|
||||||
def find(self, mailfrom=None, recipients=None, older_than=None):
|
def find(self, mailfrom=None, recipients=None, older_than=None):
|
||||||
"Find e-mails in quarantine."
|
"Find emails in quarantine."
|
||||||
super(FileQuarantine, self).find(mailfrom, recipients, older_than)
|
super(FileQuarantine, self).find(mailfrom, recipients, older_than)
|
||||||
if type(mailfrom) == str: mailfrom = [mailfrom]
|
if type(mailfrom) == str: mailfrom = [mailfrom]
|
||||||
if type(recipients) == str: recipients = [recipients]
|
if type(recipients) == str: recipients = [recipients]
|
||||||
@@ -177,13 +177,13 @@ class FileQuarantine(BaseQuarantine):
|
|||||||
return emails
|
return emails
|
||||||
|
|
||||||
def delete(self, quarantine_id, recipient=None):
|
def delete(self, quarantine_id, recipient=None):
|
||||||
"Delete e-mail in quarantine."
|
"Delete email in quarantine."
|
||||||
super(FileQuarantine, self).delete(quarantine_id, recipient)
|
super(FileQuarantine, self).delete(quarantine_id, recipient)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
metadata = self.get_metadata(quarantine_id)
|
metadata = self.get_metadata(quarantine_id)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
raise RuntimeError("unable to delete e-mail: {}".format(e))
|
raise RuntimeError("unable to delete email: {}".format(e))
|
||||||
|
|
||||||
if recipient == None:
|
if recipient == None:
|
||||||
self._remove(quarantine_id)
|
self._remove(quarantine_id)
|
||||||
@@ -198,13 +198,13 @@ class FileQuarantine(BaseQuarantine):
|
|||||||
self._save_metafile(quarantine_id, metadata)
|
self._save_metafile(quarantine_id, metadata)
|
||||||
|
|
||||||
def release(self, quarantine_id, recipient=None):
|
def release(self, quarantine_id, recipient=None):
|
||||||
"Release e-mail from quarantine."
|
"Release email from quarantine."
|
||||||
super(FileQuarantine, self).release(quarantine_id, recipient)
|
super(FileQuarantine, self).release(quarantine_id, recipient)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
metadata = self.get_metadata(quarantine_id)
|
metadata = self.get_metadata(quarantine_id)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
raise RuntimeError("unable to release e-mail: {}".format(e))
|
raise RuntimeError("unable to release email: {}".format(e))
|
||||||
|
|
||||||
datafile = os.path.join(self.directory, quarantine_id)
|
datafile = os.path.join(self.directory, quarantine_id)
|
||||||
if recipient != None:
|
if recipient != None:
|
||||||
@@ -224,7 +224,7 @@ class FileQuarantine(BaseQuarantine):
|
|||||||
try:
|
try:
|
||||||
mailer.smtp_send(self.config["smtp_host"], self.config["smtp_port"], metadata["from"], recipient, mail)
|
mailer.smtp_send(self.config["smtp_host"], self.config["smtp_port"], metadata["from"], recipient, mail)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise RuntimeError("error while sending e-mail to '{}': {}".format(recipient, e))
|
raise RuntimeError("error while sending email to '{}': {}".format(recipient, e))
|
||||||
|
|
||||||
self.delete(quarantine_id, recipient)
|
self.delete(quarantine_id, recipient)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user