Changeset 45 for emailtotracscript/trunk/email2trac.py.in
- Timestamp:
- 01/30/06 19:16:27 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
emailtotracscript/trunk/email2trac.py.in
r44 r45 238 238 239 239 def set_owner(self, ticket): 240 """ 241 Select default owner for ticket component 242 """ 240 243 cursor = self.db.cursor() 241 244 sql = "SELECT owner FROM component WHERE name='%s'" % ticket['component'] … … 245 248 246 249 def set_reply_fields(self, ticket, message): 247 250 """ 251 Bla Bla 252 """ 248 253 author, email_addr = email.Utils.parseaddr(message['from']) 249 254 email_str = self.to_unicode(message['from']) 250 255 251 ticket['reporter'] = email_str 252 ticket['cc'] = None 253 254 # Put all addresses in ticket CC field 256 # Look for email address in registered trac users 257 # 258 if self.VERSION > 0.8: 259 users = [ u for (u, n, e) in self.env.get_known_users(self.db) 260 if e == email_addr ] 261 else: 262 users = [] 263 264 if len(users) == 1: 265 ticket['reporter'] = users[0] 266 else: 267 ticket['reporter'] = email_str 268 269 # Put all CC-addresses in ticket CC field 255 270 # 256 271 if self.REPLY_ALL: 257 tos = message.get_all('to', [])272 #tos = message.get_all('to', []) 258 273 ccs = message.get_all('cc', []) 259 274 260 addrs = email.Utils.getaddresses( tos +ccs)275 addrs = email.Utils.getaddresses(ccs) 261 276 262 277 # Remove reporter email address if notification is … … 269 284 pass 270 285 271 for a,m in addrs: 272 if not ticket['cc']: 273 ticket['cc'] = m 274 else: 275 ticket['cc'] = '%s,%s' %(ticket['cc'], m) 276 277 # Put authors email addess in CC field only if notification is off 278 # 279 elif self.CC and not self.notification: 280 ticket['cc'] = email_str 281 286 for name,mail in addrs: 287 try: 288 ticket['cc'] = '%s,%s' %(ticket['cc'], mail) 289 except: 290 ticket['cc'] = mail 282 291 return author, email_addr 283 292 … … 339 348 author, email_addr = self.set_reply_fields(tkt, msg) 340 349 341 # produce e-mail like header 350 # produce e-mail like header 351 # 342 352 head = '' 343 353 if self.EMAIL_HEADER > 0: … … 347 357 self.debug_attachments(msg) 348 358 349 # 350 # put the message text in the ticket description 351 # message text can be plain text or html or something else 352 # 359 self.description(msg,tkt, head, author, email_addr) 360 361 # Insert ticket in database 362 # 363 if self.VERSION > 0.8: 364 tkt['id'] = tkt.insert() 365 else: 366 tkt['id'] = tkt.insert(self.db) 367 368 # 369 # Just how to show to update description 370 # 371 #tkt['description'] = '\n{{{\n\n Bas is op nieuw bezig\n\n }}}\n' 372 #tkt.save_changes(self.db, author, "Lekker bezig") 373 # 374 375 self.attachments(msg, tkt, author) 376 if self.notification: 377 self.notify(tkt) 378 379 380 def description(self, msg, tkt, head, author, email): 381 """ 382 put the message text in the ticket description 383 message text can be plain text or html or something else 384 """ 353 385 has_description = 0 354 386 for part in msg.walk(): 355 if part.get_content_maintype() == 'multipart': # 'multipart/*' is a container for multipart messages 387 388 # 'multipart/*' is a container for multipart messages 389 # 390 if part.get_content_maintype() == 'multipart': 356 391 continue 357 392 358 393 if part.get_content_type() == 'text/plain': 359 body_text = part.get_payload(decode=1) # try to decode 360 if not body_text: # decode failed 361 body_text = part.get_payload(decode=0) # do not decode 362 363 tkt['description'] = '\n{{{\n\n%s\n}}}\n' % body_text 394 # Try to decode, if fails then do not decode 395 # 396 body_text = part.get_payload(decode=1) 397 if not body_text: 398 body_text = part.get_payload(decode=0) 399 400 # Get contents charset (iso-8859-15 if not defined in mail headers) 401 # UTF-8 encode body_text 402 # 403 charset = msg.get_content_charset('iso-8859-15') 404 ubody_text = unicode(body_text, charset).encode('utf-8') 405 406 tkt['description'] = '\n{{{\n\n%s\n}}}\n' %(ubody_text) 364 407 365 408 elif part.get_content_type() == 'text/html': 366 tkt['description'] = '%s\n\n(see attachment for HTML mail message)\n' % head 409 tkt['description'] = '%s\n\n(see attachment for HTML mail message)\n' \ 410 %(head) 367 411 body_text = tkt['description'] 368 412 369 413 else: 370 tkt['description'] = '%s\n\n(see attachment for message)\n' % head414 tkt['description'] = '%s\n\n(see attachment for message)\n' %(head) 371 415 body_text = tkt['description'] 372 416 … … 379 423 380 424 if self.MAILTO: 381 mailto = self.html_mailto_link(author, email _addr, self.to_unicode(msg['subject']),body_text)425 mailto = self.html_mailto_link(author, email, self.to_unicode(msg['subject']), ubody_text) 382 426 tkt['description'] = '%s\n%s %s' %(head, mailto, tkt['description']) 383 427 384 if self.VERSION > 0.8:385 tkt['id'] = tkt.insert()386 else:387 tkt['id'] = tkt.insert(self.db)388 389 #390 # Just how to show to update description391 #392 #tkt['description'] = '\n{{{\n\n Bas is op nieuw bezig\n\n }}}\n'393 #tkt.save_changes(self.db, author, "Lekker bezig")394 #395 396 self.attachments(msg, tkt, author)397 if self.notification:398 self.notify(tkt)399 428 400 429 def notify(self, tkt): … … 429 458 #arr = string.split(body, '\n') 430 459 #arr = map(self.mail_line, arr) 431 432 460 #body = string.join(arr, '\n') 433 461 #body = '%s wrote:\n%s' %(author, body) 434 462 435 # Obsolete for reference436 #437 #body = self.to_unicode(body)438 #body = urllib.quote(body)439 #body = Header.encode(body)440 #441 442 463 # Temporary fix 443 464 body = '> Type your reply' 444 str = 'mailto:%s?subject=%s&body=%s' % 465 str = 'mailto:%s?subject=%s&body=%s' %(urllib.quote(mail_addr), urllib.quote('Re: %s' % subject), urllib.quote(body)) 445 466 str = '\n{{{\n#!html\n<a href="%s">Reply to: %s</a>\n}}}\n' %(str, author) 446 467
Note: See TracChangeset
for help on using the changeset viewer.