def all_same_charset(mlist, msgdata, subject, prefix, prefix_pattern, ws): list_charset = mlist.preferred_language.charset chunks = [] for chunk, charset in decode_header(subject.encode()): if charset is None: charset = 'us-ascii' chunks.append(chunk.decode(charset)) if charset != list_charset: return None subject_text = EMPTYSTRING.join(chunks) rematch = re.match(RE_PATTERN, subject_text, re.I) if rematch: subject_text = subject_text[rematch.end():] recolon = 'Re: ' else: recolon = '' # At this point, the subject may become null if someone posted mail # with "Subject: [subject prefix]". if subject_text.strip() == '': with _.push(mlist.preferred_language.code): subject_text = _('(no subject)') else: subject_text = re.sub(prefix_pattern, '', subject_text) msgdata['stripped_subject'] = subject_text lines = subject_text.splitlines() first_line = [lines[0]] if recolon: first_line.insert(0, recolon) if prefix: first_line.insert(0, prefix) subject_text = EMPTYSTRING.join(first_line) return Header(subject_text, charset=list_charset, continuation_ws=ws)
def mixed_charsets(mlist, msgdata, subject, prefix, prefix_pattern, ws): list_charset = mlist.preferred_language.charset chunks = decode_header(subject.encode()) if len(chunks) == 0: with _.push(mlist.preferred_language.code): subject_text = _('(no subject)') chunks = [ (prefix, list_charset), (subject_text, list_charset), ] return make_header(chunks, continuation_ws=ws) # Only search the first chunk for Re and existing prefix. chunk_text, chunk_charset = chunks[0] if chunk_charset is None: chunk_charset = 'us-ascii' if isinstance(chunk_text, str): first_text = chunk_text else: try: first_text = chunk_text.decode(chunk_charset) except LookupError: # The chunk_charset is unknown. Add a dummy first_text. chunks.insert(0, ('', 'us-ascii')) first_text = '' first_text = re.sub(prefix_pattern, '', first_text).lstrip() rematch = re.match(RE_PATTERN, first_text, re.I) if rematch: first_text = 'Re: ' + first_text[rematch.end():] chunks[0] = (first_text, chunk_charset) # The subject text stripped of the prefix, for use in the NNTP gateway. msgdata['stripped_subject'] = str(make_header(chunks, continuation_ws=ws)) chunks.insert(0, (prefix, list_charset)) return make_header(chunks, continuation_ws=ws)
def all_same_charset(mlist, msgdata, subject, prefix, prefix_pattern, ws): list_charset = mlist.preferred_language.charset chunks = [] for chunk, charset in decode_header(subject.encode()): if charset is None: charset = 'us-ascii' chunks.append(chunk.decode(charset)) if charset != list_charset: return None subject_text = EMPTYSTRING.join(chunks) # At this point, the subject may become null if someone posted mail # with "Subject: [subject prefix]". if subject_text.strip() == '': with _.push(mlist.preferred_language.code): subject_text = _('(no subject)') else: subject_text = re.sub(prefix_pattern, '', subject_text) msgdata['stripped_subject'] = subject_text rematch = re.match(RE_PATTERN, subject_text, re.I) if rematch: subject_text = subject_text[rematch.end():] recolon = 'Re: ' else: recolon = '' lines = subject_text.splitlines() first_line = [lines[0]] if recolon: first_line.insert(0, recolon) if prefix: first_line.insert(0, prefix) subject_text = EMPTYSTRING.join(first_line) return Header(subject_text, charset=list_charset, continuation_ws=ws)
def mixed_charsets(mlist, msgdata, subject, prefix, prefix_pattern, ws): list_charset = mlist.preferred_language.charset chunks = decode_header(subject.encode()) if len(chunks) == 0: with _.push(mlist.preferred_language.code): subject_text = _('(no subject)') chunks = [(prefix, list_charset), (subject_text, list_charset), ] return make_header(chunks, continuation_ws=ws) # Only search the first chunk for Re and existing prefix. chunk_text, chunk_charset = chunks[0] if chunk_charset is None: chunk_charset = 'us-ascii' first_text = chunk_text.decode(chunk_charset) first_text = re.sub(prefix_pattern, '', first_text).lstrip() rematch = re.match(RE_PATTERN, first_text, re.I) if rematch: first_text = 'Re: ' + first_text[rematch.end():] chunks[0] = (first_text, chunk_charset) # The subject text stripped of the prefix, for use in the NNTP gateway. msgdata['stripped_subject'] = str(make_header(chunks, continuation_ws=ws)) chunks.insert(0, (prefix, list_charset)) return make_header(chunks, continuation_ws=ws)