Bas van der Vlies wrote:
Hello,
I am doing something wrong with the email2trac package. When i
convert an email to ticket all fields are converted properly, but when
i update
the converted ticket via the web interface it always says that the
description is changed.
This is very annoying if notification is enabled. There is always an
email that says the description has been changed. But there is no
change at all.
Is there a proper way to convert the email ascci text message to the
ticket['description'] field?
This is short what i am doing now:
==================================================================
if part.get_content_type() == 'text/plain':
# Try to decode, if fails then do not decode
#
body_text = part.get_payload(decode=1)
if not body_text:
body_text = part.get_payload(decode=0)
# Get contents charset (iso-8859-15 if not defined in mail headers)
# UTF-8 encode body_text
#
charset = part.get_content_charset('iso-8859-15')
try:
temp = unicode(body_text, charset)
except (UnicodeError,LookupError):
temp = unicode(body_text, 'iso-8859-15')
ubody_text = temp.encode('utf-8')
tkt['description'] = '\n{{{\n%s\n}}}\n' %(ubody_txt)
Are you talking about 0.9? For 0.10, you should use unicode internally.
I tried to reproduce this:
>>> from trac.ticket.model import Ticket
>>> from trac.env import Environment
>>> env = Environment(os.environ['TRAC_ENV'])
>>> t38 = Ticket(env, 38)
>>> t38['description']
u"It '''''works for me'''''.\r\n\r\nTesting notify description changes..."
>>> t38['description'] = '\n{{{\n%s\n}}}\n' %('this is a test')
>>> t38['description']
'\n{{{\nthis is a test\n}}}\n'
>>> t38.save_changes('cmdline', 'testing email2trac')
>>> ^Z
Then, I went to the web interface, simply added a comment, and got:
* *description* changed.
Now a simple change, without touching at the description...
----
Going back to the command line:
>>> t38 = Ticket(env, 38)
>>> t38['description']
u'{{{\r\nthis is a test\r\n}}}\r\n'
Two things happened:
1. the initial '\n' has been lost
2. all the other ones where replaced by '\r\n'
1. is a funny bug, if you create a description in the web ui
containing many leading empty lines, then successive changes
will each time modify the description, as each time the first
empty line will be removed from the description.
2. is to be expected, as the HTML spec recommends this:
''User agents should canonicalize line endings to CR, LF
(ASCII decimal 13, 10) when submitting the field's contents.''
So, in 0.10, you should do:
tkt['description'] = u'{{{\r\n%s\r\n}}}\n' % \
('\r\n'.join(temp.splitlines()))
Concerning the issue 1., this seems to be a common issue, e.g.
http://twiki.org/cgi-bin/view/Codev/SomeBrowsersLoseInitialNewlineInTextArea
I've fixed this in r3496.
-- Christian
_______________________________________________
Trac mailing list
[email protected]
http://lists.edgewall.com/mailman/listinfo/trac