'Handles message composition under /message/compose.'

@require_oauth2_scope('privatemessages')
@validatedForm(VCaptcha(), VUser(), VModhash(), from_sr=VSRByName('from_sr', required=False), to=VMessageRecipient('to'), subject=VLength('subject', 100, empty_error=errors.NO_SUBJECT), body=VMarkdownLength(['text', 'message'], max_length=10000))
@api_doc(api_section.messages)
def POST_compose(self, form, jquery, from_sr, to, subject, body):

    if (form.has_errors('to', errors.USER_DOESNT_EXIST, errors.NO_USER, errors.SUBREDDIT_NOEXIST, errors.USER_BLOCKED) or form.has_errors('subject', errors.NO_SUBJECT) or form.has_errors('subject', errors.TOO_LONG) or form.has_errors('text', errors.NO_TEXT, errors.TOO_LONG) or form.has_errors('message', errors.TOO_LONG) or form.has_errors('captcha', errors.BAD_CAPTCHA) or form.has_errors('from_sr', errors.SUBREDDIT_NOEXIST)):
        return
    if form.has_errors('to', errors.USER_MUTED):
        g.events.muted_forbidden_event('muted', target=to, request=request, context=c)
        form.set_inputs(to='', subject='', text='', captcha='')
        return
    if (from_sr and isinstance(to, Subreddit)):
        c.errors.add(errors.NO_SR_TO_SR_MESSAGE, field='from')
        form.has_errors('from', errors.NO_SR_TO_SR_MESSAGE)
        return
    if (from_sr and BlockedSubredditsByAccount.is_blocked(to, from_sr)):
        c.errors.add(errors.USER_BLOCKED_MESSAGE, field='to')
        form.has_errors('to', errors.USER_BLOCKED_MESSAGE)
        return
    if (from_sr and from_sr._spam):
        return
    if from_sr:
        if (not from_sr.is_moderator_with_perms(c.user, 'mail')):
            abort(403)
        elif (from_sr.is_muted(to) and (not c.user_is_admin)):
            c.errors.add(errors.MUTED_FROM_SUBREDDIT, field='to')
            form.has_errors('to', errors.MUTED_FROM_SUBREDDIT)
            g.events.muted_forbidden_event('muted    mod', subreddit=from_sr, target=to, request=request, context=c)
            form.set_inputs(to='', subject='', text='', captcha='')
            return
        VNotInTimeout().run(target=to, subreddit=from_sr)
        (m, inbox_rel) = Message._new(c.user, to, subject, body, request.ip, sr=from_sr, from_sr=True)
    else:
        if (to and (not (isinstance(to, Subreddit) and (('/r/%s' % to.name) == g.admin_message_acct)))):
            VNotInTimeout().run(target=to)
        (m, inbox_rel) = Message._new(c.user, to, subject, body, request.ip)
    form.set_text('.status', _('your    message    has    been    delivered'))
    form.set_inputs(to='', subject='', text='', captcha='')
    queries.new_message(m, inbox_rel)
