File: /volume1/@appstore/MailPlus-Server/scripts/quota_warn.py
#!/usr/bin/env python3
# -*- encoding=utf8 -*-
# Copyright (c) 2000-2020 Synology Inc. All rights reserved.
import sys
sys.path.append("/var/packages/MailPlus-Server/target/scripts/common/")
from addr_util import getFullUsername, getUserAddress, writeLog
from c_lib import LibMailserver
from send_mail import send_mail
QUOTA_WARNING_MSG = u'''\
Dear user,
This notification indicate that the warning threshold for your mail has been reached. You are still able to receive or edit new mails but future mails may cause your mail to exceed the quota size limit resulting in delivery failure.
Quota policy of {user}:
Current usage: {usage}
Quota warning threshold: {threshold}
Quota size limit: {limit}
Sincerely,
Synology DiskStation\
'''
def main():
import argparse
parser = argparse.ArgumentParser(usage='%(prog)s [options]')
parser.add_argument('threshold_byte', type=int, help='Warning threshold byte')
parser.add_argument('user', help='User name')
args = parser.parse_args()
user = args.user
email_list = getUserAddress(getFullUsername(user))
if not email_list:
writeLog('Failed to send quota warning mail: user [{0}] has no email address.')
return
try:
lib = LibMailserver()
threshold = lib.get_readable_byte(args.threshold_byte)
(usage, limit) = lib.get_readable_usage_and_limit_info(user)
send_mail(
subject='Quota Warning Notification',
msg=QUOTA_WARNING_MSG.format(
user=user,
threshold=threshold,
usage=usage,
limit=limit
),
sender='MAILER-DAEMON',
recipients=email_list[0]
)
except Exception as e:
writeLog('Failed to send quota warning mail: {0}'.format(str(e)))
if __name__ == '__main__':
main()