trac 0.11.ja1のチケットメール(再挑戦)
以前、trac 0.11.ja1のチケットメールで挑戦してうまくいかなかった、Tracのチケットメールのiso-2022-jp化。
Tracを0.11.1.ja1にアップしたので(今まで0.11.ja1だった)、再度挑戦してみた。
こちらとこちらのページを参考に、というか、そのまま設定したら、できた。
でも前回も同じようにやったんだよなー。Tracのバージョンしか違いはないんだけど。
その続きで、送信されるメールの内容もちょっと変えてみた。
まず、TracのWikiの文法でチケットの説明文などが書かれていると、BRがそのまま出てしまう。
そこで、こちらを参考に、trac/notification.pyを修正。
+ import string
(略)
def send(self, torcpts, ccrcpts, mime_headers={}):
from email.MIMEText import MIMEText
from email.Utils import formatdate, formataddr
body = self.hdf.render(self.template_name)
+ body = string.replace(body, 'BR', '\r\n')
次に、メール本文のチケット情報表示のところを、ケータイWebからも見やすく変更。
これはこちらを参考に、trac/ticket/notification.pyを変更。
def format_props(self):
tkt = self.ticket
fields = [f for f in tkt.fields if f['name'] not in ('summary', 'cc')]
- width = [0, 0, 0, 0]
- i = 0
- for f in [f['name'] for f in fields if f['type'] != 'textarea']:
- if not tkt.values.has_key(f):
- continue
- fval = tkt[f]
- if fval.find('\n') != -1:
- continue
- idx = 2 * (i % 2)
- if len(f) > width[idx]:
- width[idx] = len(f)
- if len(fval) > width[idx + 1]:
- width[idx + 1] = len(fval)
- i += 1
- format = ('%%%is: %%-%is | ' % (width[0], width[1]),
- ' %%%is: %%-%is%s' % (width[2], width[3], CRLF))
- l = (width[0] + width[1] + 5)
- sep = l * '-' + '+' + (self.COLS - l) * '-'
- txt = sep + CRLF
+ txt = ''
big = []
i = 0
for f in [f for f in fields if f['name'] != 'description']:
fname = f['name']
if not tkt.values.has_key(fname):
continue
fval = tkt[fname]
if f['type'] == 'textarea' or '\n' in unicode(fval):
big.append((fname.capitalize(), CRLF.join(fval.splitlines())))
else:
- txt += format[i % 2] % (fname.capitalize(), fval)
- i += 1
+ txt += ' ' + fname.capitalize() + ' : ' + fval + CRLF
- if i % 2:
- txt += CRLF
if big:
- txt += sep
for name, value in big:
txt += CRLF.join(['', ' ' + name + ':', value, '', ''])
- txt += sep
return txt
これでチケットメールがかなり見やすくなった。