Open tumashu opened 10 years ago
On Fri, Apr 11, 2014 at 05:57:14AM -0700, tumashu wrote:
Is is possible using a post hook function?
That's what I would do. You'll want a post-processing hook that looks like:
import rss2email.email
def convert_to_pinyin(string): ... return pinyin
def add_subject_pinyin(message, **kwargs): subject = rss2email.email._decode_header(message['Subject']) message['X-Subject-Pinyin'] = convert_to_pinyin(subject)
If that works for you, let me know and I can make rss2email.email._decode_header public (by removing the underscore prefix).
"W. Trevor King" notifications@github.com writes:
On Fri, Apr 11, 2014 at 05:57:14AM -0700, tumashu wrote:
Is is possible using a post hook function?
That's what I would do. You'll want a post-processing hook that looks like:
import rss2email.email
def convert_to_pinyin(string): ... return pinyin
def add_subject_pinyin(message, **kwargs): subject = rss2email.email._decode_header(message['Subject']) message['X-Subject-Pinyin'] = convert_to_pinyin(subject)
If that works for you, let me know and I can make rss2email.email._decode_header public (by removing the underscore prefix).
— Reply to this email directly or view it on GitHub. Thanks for you reply!
The below hook works well, I suggest it can be included into master, for it is very useful for Chinese user.
import rss2email.email import pinyin
def remove_non_ascii(string): """remove no ascii char in string""" return "".join([i for i in string if ord(i)<128])
def add_pinyin_header(message, **kwargs): header_subject = rss2email.email._decode_header(message['Subject']) header_from = rss2email.email._decode_header(message['From']) message['X-Pinyin-Subject'] = remove_non_ascii(pinyin.get(header_subject)) message['X-Pinyin-From'] = remove_non_ascii(pinyin.get(header_from)) return message
On Sat, Apr 12, 2014 at 08:16:19PM -0700, tumashu wrote:
def remove_non_ascii(string): """remove no ascii char in string""" return "".join([i for i in string if ord(i)<128])
Can you give an example of a subject or from header that doesn't convert to all ASCII?
message['X-Pinyin-From'] = remove_non_ascii(pinyin.get(header_from))
I'd prefer either encoding the Pinyin string (with any non-ASCII characters) using the usual email.header.Header, but procmail has (at least, it had in 2010 1) the same sort of problem with RFC-2047-encoded Pinyin as it had with the original hanzi.
I'm still not wild about the ord() stuff. How about:
message['X-Pinyin-From'] = pinyin.get(header_from).encode( 'ASCII', errors='ignore')
?
Can you give an example of a subject or from header that doesn't convert to all ASCII?
I use pinyin to filter email, so chars which is not Chinese and ascii are useless for filter chinese subject and i remove them.
Hello,
This repository has been deprecated for a few years now, and has been replaced by https://github.com/rss2email/rss2email .
If this issue is still relevant to you, and not fixed with v3.12.2, could you please reopen the issue there?
Cheers, Leo
Before send mail, UTF-8 char will be encode with base64, which is difficult filted by procmail.
I want to add a field: X-Subject-Pinyin, which can be generate from Subject fields, for example:
generate a field:
Now I hack the rss2email source to get this feature , Is is possible using a post hook function?