Changeset 342
- Timestamp:
- 03/24/10 15:39:41 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/email2trac.py.in
r341 r342 977 977 978 978 979 def attach_attachments(self, message_parts, update=False): 980 ''' 981 save any attachments as files in the ticket's directory 982 ''' 983 if self.VERBOSE: 984 print "VB: attach_attachments()" 985 986 if self.DRY_RUN: 987 print "DRY_RUN: no attachments attached to tickets" 988 return '' 989 990 count = 0 991 992 # Get Maxium attachment size 993 # 994 max_size = int(self.get_config('attachment', 'max_size')) 995 status = None 996 997 for item in message_parts: 998 # Skip body parts 999 if not isinstance(item, tuple): 1000 continue 1001 1002 (original, filename, part) = item 1003 # 1004 # Must be tuneables HvB 1005 # 1006 path, fd = util.create_unique_file(os.path.join(self.TMPDIR, filename)) 1007 text = part.get_payload(decode=1) 1008 if not text: 1009 text = '(None)' 1010 fd.write(text) 1011 fd.close() 1012 1013 # get the file_size 1014 # 1015 stats = os.lstat(path) 1016 file_size = stats[stat.ST_SIZE] 1017 1018 # Check if the attachment size is allowed 1019 # 1020 if (max_size != -1) and (file_size > max_size): 1021 status = '%s\nFile %s is larger then allowed attachment size (%d > %d)\n\n' \ 1022 %(status, original, file_size, max_size) 1023 1024 os.unlink(path) 1025 continue 1026 else: 1027 count = count + 1 1028 1029 # Insert the attachment 1030 # 1031 fd = open(path, 'rb') 1032 att = attachment.Attachment(self.env, 'ticket', self.id) 1033 1034 # This will break the ticket_update system, the body_text is vaporized 1035 # ;-( 1036 # 1037 if not update: 1038 att.author = self.author 1039 att.description = self.email_to_unicode('Added by email2trac') 1040 1041 att.insert(filename, fd, file_size) 1042 1043 #except util.TracError, detail: 1044 # print detail 1045 1046 # Remove the created temporary filename 1047 # 1048 fd.close() 1049 os.unlink(path) 1050 1051 ## return error 1052 # 1053 return status 1054 979 1055 ########## Fullblog functions ########################################################### 980 1056 … … 1021 1097 blog.create_post(req, post, self.author, u'Created by email2trac', False) 1022 1098 1099 1100 1101 ########## MAIN function ########################################################### 1023 1102 1024 1103 def parse(self, fp): … … 1534 1613 s = '\r\n{{{\r\n#!html\r\n<a\r\n href="%s">Reply to: %s\r\n</a>\r\n}}}\r\n' %(s, author) 1535 1614 return s 1536 1537 def attach_attachments(self, message_parts, update=False):1538 '''1539 save any attachments as files in the ticket's directory1540 '''1541 if self.VERBOSE:1542 print "VB: attach_attachments()"1543 1544 if self.DRY_RUN:1545 print "DRY_RUN: no attachments attached to tickets"1546 return ''1547 1548 count = 01549 1550 # Get Maxium attachment size1551 #1552 max_size = int(self.get_config('attachment', 'max_size'))1553 status = None1554 1555 for item in message_parts:1556 # Skip body parts1557 if not isinstance(item, tuple):1558 continue1559 1560 (original, filename, part) = item1561 #1562 # Must be tuneables HvB1563 #1564 path, fd = util.create_unique_file(os.path.join(self.TMPDIR, filename))1565 text = part.get_payload(decode=1)1566 if not text:1567 text = '(None)'1568 fd.write(text)1569 fd.close()1570 1571 # get the file_size1572 #1573 stats = os.lstat(path)1574 file_size = stats[stat.ST_SIZE]1575 1576 # Check if the attachment size is allowed1577 #1578 if (max_size != -1) and (file_size > max_size):1579 status = '%s\nFile %s is larger then allowed attachment size (%d > %d)\n\n' \1580 %(status, original, file_size, max_size)1581 1582 os.unlink(path)1583 continue1584 else:1585 count = count + 11586 1587 # Insert the attachment1588 #1589 fd = open(path, 'rb')1590 att = attachment.Attachment(self.env, 'ticket', self.id)1591 1592 # This will break the ticket_update system, the body_text is vaporized1593 # ;-(1594 #1595 if not update:1596 att.author = self.author1597 att.description = self.email_to_unicode('Added by email2trac')1598 1599 att.insert(filename, fd, file_size)1600 1601 #except util.TracError, detail:1602 # print detail1603 1604 # Remove the created temporary filename1605 #1606 fd.close()1607 os.unlink(path)1608 1609 ## return error1610 #1611 return status1612 1615 1613 1616
Note: See TracChangeset
for help on using the changeset viewer.