def show_part(self, msg): curviewer = self.richpaned.get_child2() if not curviewer is None: self.richpaned.remove(curviewer) if msg is None: return charset = msg.get_charset() type = msg.get_content_type() payload = msg.get_payload(decode=True) if type.startswith('text/'): payload = payload.decode( msg.get_content_charset() or (charset.input_codec if charset else 'iso-8859-1'), 'replace') if type == 'text/html': text = payload text = re.sub('\\s+', ' ', text) text = re.sub('(?i)<head[^>]*>.*?</head>', '', text) text = re.sub('(?i)<style[^>]*>.*?</style>', '', text) text = re.sub('(?i)<a ([^>]* )?href="([^"]*)"[^>]*>', lambda m: ' [ ' + m.group(2) + ' ] ', text) text = re.sub('(?i)<(br|div|blockquote|table|p|tr)[^>]*>', '\n', text) text = re.sub('<[^>]*>', '', text) text = util.decode_entities(text) text = re.sub('\n\\s*\n(\\s*\n)+', '\n\n', text) self.richbuf.props.text = text.strip() else: text = payload text = re.sub('\n\\s*\n(\\s*\n)+', '\n\n', text) self.richbuf.props.text = text.strip() self.richpaned.pack2(self.viewer_text)
def show_part(self, msg): curviewer = self.richpaned.get_child2() if not curviewer is None: self.richpaned.remove(curviewer) if msg is None: return charset = msg.get_charset() type = msg.get_content_type() payload = msg.get_payload(decode=True) if type.startswith('text/'): payload = payload.decode(msg.get_content_charset() or (charset.input_codec if charset else 'iso-8859-1'), 'replace') if type == 'text/html': text = payload text = re.sub('\\s+', ' ', text) text = re.sub('(?i)<head[^>]*>.*?</head>', '', text) text = re.sub('(?i)<style[^>]*>.*?</style>', '', text) text = re.sub('(?i)<a ([^>]* )?href="([^"]*)"[^>]*>', lambda m: ' [ ' + m.group(2) + ' ] ', text) text = re.sub('(?i)<(br|div|blockquote|table|p|tr)[^>]*>', '\n', text) text = re.sub('<[^>]*>', '', text) text = util.decode_entities(text) text = re.sub('\n\\s*\n(\\s*\n)+', '\n\n', text) self.richbuf.props.text = text.strip() else: text = payload text = re.sub('\n\\s*\n(\\s*\n)+', '\n\n', text) self.richbuf.props.text = text.strip() self.richpaned.pack2(self.viewer_text)
def decode_payload(msg): charset = msg.get_charset() text = msg.get_payload(decode=True).decode(charset.input_codec if charset else "iso-8859-1", "replace") if msg.get_content_type() == "text/html": for tag in ("head", "style", "blockquote"): text = re.sub("(?i)<" + tag + "[^>]*>.*?</" + tag + ">", " ", text) text = util.decode_entities(re.sub("<[^>]*>", " ", text)) return text
def decode_payload(msg): charset = msg.get_charset() text = msg.get_payload(decode=True).decode( charset.input_codec if charset else 'iso-8859-1', 'replace') if msg.get_content_type() == 'text/html': for tag in ('head', 'style', 'blockquote'): text = re.sub('(?i)<' + tag + '[^>]*>.*?</' + tag + '>', ' ', text) text = util.decode_entities(re.sub('<[^>]*>', ' ', text)) return text