Beispiel #1
0
def construct_response(author, targets, subject, text, original, cc=None):
    r"""Build a multipart/mixed response email using `Person` instances

    >>> from pygrader.model.person import Person as Person
    >>> student = Person(name='Джон Доу', emails=['*****@*****.**'])
    >>> assistant = Person(name='Jill', emails=['*****@*****.**'])
    >>> cc = [assistant]
    >>> msg = construct_text_email(author=student, targets=[assistant],
    ...     subject='Assignment 1 submission', text='Bla bla bla...')
    >>> rsp = construct_response(author=assistant, targets=[student],
    ...     subject='Received assignment 1 submission', text='3 hours late',
    ...     original=msg)
    >>> print(rsp.as_string())  # doctest: +REPORT_UDIFF, +ELLIPSIS
    Content-Type: multipart/mixed; boundary="===============...=="
    MIME-Version: 1.0
    Date: ...
    From: Jill <*****@*****.**>
    Reply-to: Jill <*****@*****.**>
    To: =?utf-8?b?0JTQttC+0L0g0JTQvtGD?= <*****@*****.**>
    Subject: Received assignment 1 submission
    <BLANKLINE>
    --===============...==
    Content-Type: text/plain; charset="us-ascii"
    MIME-Version: 1.0
    Content-Transfer-Encoding: 7bit
    Content-Disposition: inline
    <BLANKLINE>
    3 hours late
    --===============...==
    Content-Type: message/rfc822
    MIME-Version: 1.0
    <BLANKLINE>
    Content-Type: text/plain; charset="us-ascii"
    MIME-Version: 1.0
    Content-Transfer-Encoding: 7bit
    Content-Disposition: inline
    Date: ...
    From: =?utf-8?b?0JTQttC+0L0g0JTQvtGD?= <*****@*****.**>
    Reply-to: =?utf-8?b?0JTQttC+0L0g0JTQvtGD?= <*****@*****.**>
    To: Jill <*****@*****.**>
    Subject: Assignment 1 submission
    <BLANKLINE>
    Bla bla bla...
    --===============...==--
    """
    message = _MIMEMultipart('mixed')
    message.attach(_pgp_mime.encodedMIMEText(text))
    message.attach(_MIMEMessage(original))
    return construct_email(
        author=author, targets=targets, subject=subject, message=message,
        cc=cc)
Beispiel #2
0
def _get_student_submission_email(basedir, course, person, assignments,
                                  student):
    _LOG.debug('construct student submission email about {} {} for {}'.format(
        student, assignments, person))
    subject = '{} assignment submissions for {}'.format(
        course.name, student.name)
    text = '{}:\n  * {}\n'.format(subject,
                                  '\n  * '.join(a.name for a in assignments))
    message = _MIMEMultipart('mixed')
    message.attach(_pgp_mime.encodedMIMEText(text))
    for assignment in assignments:
        grade = course.grade(student=student, assignment=assignment)
        if grade is not None:
            text = '{} grade: {}\n'.format(assignment.name, grade.points)
            if grade.comment:
                text += '\n{}\n'.format(grade.comment)
            message.attach(_pgp_mime.encodedMIMEText(text))
        assignment_path = _assignment_path(basedir, assignment, student)
        mpath = _os_path.join(assignment_path, 'mail')
        try:
            mbox = _mailbox.Maildir(mpath, factory=None, create=False)
        except _mailbox.NoSuchMailboxError as e:
            pass
        else:
            messages = []
            for key, msg in mbox.items():
                subpath = mbox._lookup(key)
                if subpath.endswith('.gitignore'):
                    _LOG.debug('skipping non-message {}'.format(subpath))
                    continue
                messages.append(msg)
            messages.sort(key=_message_time)
            for msg in messages:
                message.attach(_MIMEMessage(msg))
    return _construct_email(author=course.robot,
                            targets=[person],
                            subject=subject,
                            message=message)
Beispiel #3
0
def _get_student_submission_email(
    basedir, course, person, assignments, student):
    _LOG.debug('construct student submission email about {} {} for {}'.format(
            student, assignments, person))
    subject = '{} assignment submissions for {}'.format(
        course.name, student.name)
    text = '{}:\n  * {}\n'.format(
        subject, '\n  * '.join(a.name for a in assignments))
    message = _MIMEMultipart('mixed')
    message.attach(_pgp_mime.encodedMIMEText(text))
    for assignment in assignments:
        grade = course.grade(student=student, assignment=assignment)
        if grade is not None:
            text = '{} grade: {}\n'.format(assignment.name, grade.points)
            if grade.comment:
                text += '\n{}\n'.format(grade.comment)
            message.attach(_pgp_mime.encodedMIMEText(text))
        assignment_path = _assignment_path(basedir, assignment, student)
        mpath = _os_path.join(assignment_path, 'mail')
        try:
            mbox = _mailbox.Maildir(mpath, factory=None, create=False)
        except _mailbox.NoSuchMailboxError as e:
            pass
        else:
            messages = []
            for key,msg in mbox.items():
                subpath = mbox._lookup(key)
                if subpath.endswith('.gitignore'):
                    _LOG.debug('skipping non-message {}'.format(subpath))
                    continue
                messages.append(msg)
            messages.sort(key=_message_time)
            for msg in messages:
                message.attach(_MIMEMessage(msg))
    return _construct_email(
        author=course.robot, targets=[person], subject=subject,
        message=message)
Beispiel #4
0
 def _append_to_digest(self, digest, message):
     part = _MIMEMessage(message)
     part.add_header('Content-Disposition', 'attachment')
     digest.attach(part)
Beispiel #5
0
 def _append_to_digest(self, digest, message):
     part = _MIMEMessage(message)
     part.add_header('Content-Disposition', 'attachment')
     digest.attach(part)