Project

General

Profile

Bug #23436

9.10 Nightlies break SendMail

Added by Zoom Zoom over 4 years ago. Updated about 4 years ago.

Status:
Resolved
Priority:
Important
Assignee:
William Grzybowski
Category:
Middleware
Target version:
Severity:
New
Reason for Closing:
Reason for Blocked:
Needs QA:
Yes
Needs Doc:
Yes
Needs Merging:
Yes
Needs Automation:
No
Support Suite Ticket:
n/a
Hardware Configuration:

SilverStone DS380 | AsRock C2750D4I | Intel 2.4gHz 8C Avoton C2750
32GB Crucial CT5008061 U-ECC 1.35v | StarTech PEXESAT322I

SSD | Samsung 850 EVO 120GB
2.5" | { HGST: HTS721010A (3) } Z1
3.5" | { WD: WD60EFRX (2) | Seagate: ST5000DM00 (2) ; ST4000DM00 (3) } Z2 ; { ST4000VN000 (8) } Z2

FreeNAS 9.10 Nightlies | { PNY Turbo USB3 32GB (2) } Mirror

ChangeLog Required:
No

Description

Not sure of the genesis, but 9.10 Nightlies break SendMail, resulting from line 12 in /etc/find_alias_for_smtplib.py.

  • I first tried using SendMail on the 9.10 Nightlies 3 days ago, with the exact same error propagating on each Nightlies version from the past three days.
  • I have not tried the Nightly from today yet [base-os-9.10-MASTER-201704180409-764cce36310277abf98c25bd65fec795]
[root@Fractals] ~# sendmail jw0914@live.com < /tmp/smart_report.tmp
Traceback (most recent call last):
  File "/etc/find_alias_for_smtplib.py", line 12, in <module>
    from django.utils.translation import ugettext_lazy as _
ImportError: No module named django.utils.translation

[root@Fractals] ~# sendmail jw0914@live.com < /tmp/zpool_report.tmp
Traceback (most recent call last):
  File "/etc/find_alias_for_smtplib.py", line 12, in <module>
    from django.utils.translation import ugettext_lazy as _
ImportError: No module named django.utils.translation

[root@Fractals] ~# sendmail jw0914@live.com < /tmp/ups_report.tmp
Traceback (most recent call last):
  File "/etc/find_alias_for_smtplib.py", line 12, in <module>
    from django.utils.translation import ugettext_lazy as _
ImportError: No module named django.utils.translation
  • Line 12: from django.utils.translation import ugettext_lazy as _

/etc/find_alias_for_smtplib.py

#!/usr/local/bin/python2

import argparse
import email
import email.parser
import os
import re
import socket
import sys
import syslog

from django.utils.translation import ugettext_lazy as _

sys.path.extend(["/usr/local/www", "/usr/local/www/freenasUI"])

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'freenasUI.settings')

import django
django.setup()

from freenasUI.common.system import get_sw_name, send_mail
from freenasUI.system.models import Email

ALIASES = re.compile(r'^(?P<from>[^#]\S+?):\s*(?P<to>\S+)$')

def do_sendmail(msg, to_addrs=None, parse_recipients=False):

    if to_addrs is None:
        if not parse_recipients:
            syslog.syslog('Do not know who to send the message to.' + msg[0:140])
            raise ValueError('Do not know who to send the message to.')
        to_addrs = []

    # XXX: this should probably be a FeedParser because reading from sys.stdin
    # is blocking.
    em_parser = email.parser.Parser()
    em = em_parser.parsestr(msg)
    if parse_recipients:
        # Strip away the comma based delimiters and whitespace.
        to_addrs = list(map(str.strip, em.get('To').split(',')))

    if not to_addrs or not to_addrs[0]:
        to_addrs = ['root']

    if to_addrs:
        aliases = get_aliases()
        to_addrs_repl = []
        for to_addr in to_addrs:
            for to_addr in to_addr.split(','):
                if to_addr.find('@') == -1 and to_addr in aliases:
                    to_addr = aliases[to_addr]
                to_addrs_repl.append(to_addr)

    margs = {}
    margs['extra_headers'] = dict(em)
    margs['extra_headers'].update({
        'X-Mailer': get_sw_name(),
        'X-%s-Host' % get_sw_name(): socket.gethostname(),
        'To': to_addr,
    })
    margs['subject'] = em.get('Subject')

    # abusive use of querysets
    lemail = Email.objects.all()
    for obj in lemail:
        if obj.em_fromemail != '':
            margs['extra_headers'].update({
               'From': obj.em_fromemail
            })

    if em.is_multipart():
        margs['attachments'] = [part for part in em.walk() if part.get_content_maintype() != 'multipart']
        margs['text'] = "%s" % _(
            'This is a MIME formatted message.  If you see '
            'this text it means that your email software '
            'does not support MIME formatted messages.')
    else:
        margs['text'] = ''.join(email.iterators.body_line_iterator(em))

    if to_addrs_repl:
        margs['to'] = to_addrs_repl

    send_mail(**margs)

def get_aliases():
    with open('/etc/aliases', 'r') as f:
        aliases = {}

        for line in f.readlines():
            search = ALIASES.search(line)
            if search:
                _from, _to = search.groups()
                aliases[_from] = _to

        doround = True
        while True:
            if not doround:
                break
            else:
                doround = False
            for key, val in aliases.items():
                if val in aliases:
                    aliases[key] = aliases[val]
                    doround = True
        return aliases

def main():
    syslog.openlog(logoption=syslog.LOG_PID, facility=syslog.LOG_MAIL)
    parser = argparse.ArgumentParser(description='Process email')
    parser.add_argument('-i', dest='strip_leading_dot', action='store_false',
                        default=True, help='see sendmail(8) -i')
    parser.add_argument('-t', dest='parse_recipients', action='store_true',
                        default=False,
                        help='parse recipients from message')
    parser.usage = ' '.join(parser.format_usage().split(' ')[1:-1])
    parser.usage += ' [email_addr|user] ..'
    args, to = parser.parse_known_args()
    if not to and not args.parse_recipients:
        parser.exit(message=parser.format_usage())
    msg = sys.stdin.read()
    syslog.syslog("sending mail to " + ','.join(to) + msg[0:140])
    do_sendmail(msg, to_addrs=to, parse_recipients=args.parse_recipients)

if __name__ == "__main__":
    main()

History

#1 Updated by Zoom Zoom over 4 years ago

  • Description updated (diff)

#2 Updated by William Grzybowski over 4 years ago

  • Status changed from Unscreened to Resolved
  • Assignee set to William Grzybowski
  • Priority changed from No priority to Important
  • Target version set to 9.10.3

Should be fixed in 23b032352f915

Thanks

#3 Updated by Zoom Zoom over 4 years ago

Thanks for the extremely fast response and fix =]

#4 Avatar?id=14398&size=24x24 Updated by Kris Moore over 4 years ago

  • Target version changed from 9.10.3 to 11.0

#5 Updated by Vaibhav Chauhan about 4 years ago

  • Target version changed from 11.0 to 11.0-RC

Also available in: Atom PDF