Edgewall Software
Modify

Opened 8 years ago

Closed 8 years ago

Last modified 2 years ago

#9494 closed defect (fixed)

[PATCH] $ticket_props doesn't wrap long field values in notification emails

Reported by: Andrew C Martin <andrew.c.martin@…> Owned by: Andrew C Martin <andrew.c.martin@…>
Priority: high Milestone: 0.12.1
Component: notification Version: 0.12dev
Severity: normal Keywords: email ticket_props notification
Cc: jun66j5@…
Release Notes:
API Changes:

Description

When the value of a text field of a ticket is sufficiently long, the $ticket_props portion of the TracNotification email becomes quite unreadable. The table at the top of the email (which lists all the non-textarea fields) expands in width beyond the 75 char limit. Issues:

  • There is no attempt to wrap long fields so that the width of $ticket_props is limited to the 75 chars maximum email width.
  • The separator lines (——-+——-) will not extend to the right cell of the table if the left cell is 75 chars or more (but will not limit the extent to which it outlines the left cell).
  • There is no symmetry between the table's 2 cells in terms of left and right cellpadding

This is probably most frequently a problem with custom text fields, but even in the default installation a long owner, reporter, or keywords field could cause the formatting issue.

I have attached two images. attachment:ticket_props_formatting_1.png demonstrates the issue with when a text field is only slightly longer could fit within the 75 char table. attachment:ticket_props_formatting_2.png demonstrates the issue with the text field is significantly longer than 75 char. Both images also show how my patch formats the email.

I have attached attachment:ticket_props_formatting.patch which I believe properly sets the cellpadding and correctly wraps long fields. It doesn't wrap long fields without spaces, but with the patch, one continuous value (like a url) will not corrupt the entire table.

Example (note where the separator dashes stop):

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  Reporter:  anonymous                                                                                                                                                                                                                                                                                                                                                                                                                                                       |       Owner:  somebody  
      Type:  defect                                                                                                                                                                                                                                                                                                                                                                                                                                                          |      Status:  closed    
  Priority:  major                                                                                                                                                                                                                                                                                                                                                                                                                                                           |   Milestone:  milestone1
 Component:  component1                                                                                                                                                                                                                                                                                                                                                                                                                                                      |     Version:  2.0       
Resolution:  fixed                                                                                                                                                                                                                                                                                                                                                                                                                                                           |    Keywords:            
Text Field:  Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.  |  
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

After Patch:

-------------------------------------------------+-------------------------
  Reporter:  anonymous                           |      Owner:  somebody
      Type:  defect                              |     Status:  closed
  Priority:  major                               |  Milestone:  milestone1
 Component:  component1                          |    Version:  2.0
Resolution:  fixed                               |   Keywords:
Text Field:  Lorem ipsum dolor sit amet,         |
  consectetur adipisicing elit, sed do eiusmod   |
  tempor incididunt ut labore et dolore magna    |
  aliqua. Ut enim ad minim veniam, quis nostrud  |
  exercitation ullamco laboris nisi ut aliquip   |
  ex ea commodo consequat. Duis aute irure       |
  dolor in reprehenderit in voluptate velit      |
  esse cillum dolore eu fugiat nulla pariatur.   |
  Excepteur sint occaecat cupidatat non          |
  proident, sunt in culpa qui officia deserunt   |
  mollit anim id est laborum.                    |
-------------------------------------------------+-------------------------

Before the patch, in this example the table width is 487 chars wide. After the patch, it is 75.

Attachments (4)

ticket_props_formatting_1.png (24.2 KB ) - added by Andrew C Martin <andrew.c.martin@…> 8 years ago.
ticket_props_formatting_2.png (33.9 KB ) - added by Andrew C Martin <andrew.c.martin@…> 8 years ago.
ticket_props_formatting.patch (2.9 KB ) - added by Andrew C Martin <andrew.c.martin@…> 8 years ago.
trac_12.1_email.png (154.6 KB ) - added by sue.lueder@… 7 years ago.
trac fields are split into multiple lines and cannot be parsed

Download all attachments as: .zip

Change History (13)

Changed 8 years ago by Andrew C Martin <andrew.c.martin@…>

Changed 8 years ago by Andrew C Martin <andrew.c.martin@…>

Changed 8 years ago by Andrew C Martin <andrew.c.martin@…>

comment:1 Changed 8 years ago by Remy Blank

Milestone: 0.13
Owner: set to Remy Blank

Thanks for the patch!

comment:2 Changed 8 years ago by Jun Omae

Cc: jun66j5@… added

comment:3 Changed 8 years ago by Remy Blank

Priority: normalhigh

comment:4 Changed 8 years ago by Remy Blank

Milestone: 0.130.12.1
Resolution: fixed
Status: newclosed

I don't claim to fully understand what that code does, but it was the same with the previous implementation, and at least this one works :)

Patch applied in [10051]. Thanks!

comment:5 Changed 8 years ago by Remy Blank

Owner: changed from Remy Blank to Andrew C Martin <andrew.c.martin@…>

comment:6 Changed 7 years ago by sue.lueder@…

So, I've been digging and digging, and I think this is the change that is causing my emails to be unreadable in my 0.12.1 installation. I have fairly long custom field names and some long possible values in my select list. In my 0.12 installation (i have two installations), even though the text exceeded some (arbitrary?) 75 character limit, the emails looked ok. Now, in 0.12.1, my fields look quite bad in outlook (see attachment:trac_12.1_email.png). Unfortunately, I cant even use the suggested solution here: http://trac.edgewall.org/wiki/TracNotification because the $ticket_props no longer parses properly for me to split on the fields because there are new lines and it's not building the array of values properly:

{% with
   pv = [(a[0].strip(), a[1].strip()) for a in [b.split(':') for b in
         [c.strip() for c in 
          ticket_props.replace('|', '\n').splitlines()[1:-1]] if ':' in b]];
   sel = ['Reporter', 'Owner', 'Type', 'Status', 'Priority', 'Milestone', 
          'Component', 'Severity', 'Resolution', 'Keywords'] %}\
${'\n'.join('%s\t%s' % (format(p[0]+':', ' <12'), p[1]) for p in pv if p[0] in sel)}
{% end %}\

Is it possible for someone to update the above code to parse the $ticket_props after this change so that I can format my emails in a way that works? How else can I fix my installation? We used easy_install, and I'm not sure how to patch it when I dont know how to find the source for notification.py.

Last edited 2 years ago by Jun Omae (previous) (diff)

Changed 7 years ago by sue.lueder@…

Attachment: trac_12.1_email.png added

trac fields are split into multiple lines and cannot be parsed

comment:7 in reply to:  6 ; Changed 7 years ago by Andrew C Martin <andrew.c.martin@…>

Replying to sue.lueder@…:

Is it possible for someone to update the above code to parse the $ticket_props after this change so that I can format my emails in a way that works? How else can I fix my installation? We used easy_install, and I'm not sure how to patch it when I dont know how to find the source for notification.py.

Sue, the $ticket_props definitely doesn't do the best job formatting when you have custom fields with very long names. As a workaround, you might want to use something like the code snippet below (in place of $ticket_props). I've modified mine to only show a subset of all the ticket's fields. They are fields that we think are worth sending in every email.

---------------------------------------------------------------------------
   Reporter: $ticket.reporter
#if ticket.owner
      Owner: $ticket.owner
#end
#if ticket.resolution
     Status: $ticket.status ($ticket.resolution)
#end
#if not ticket.resolution
     Status: $ticket.status
#end
       Type: $ticket.type
   Priority: $ticket.priority
#if ticket.product
    Product: $ticket.product
#end
---------------------------------------------------------------------------

comment:8 Changed 7 years ago by sue.lueder@…

Thanks so much Andrew. This is exactly the kind of example I needed!

comment:9 in reply to:  7 Changed 5 years ago by brian@…

Replying to Andrew C Martin <andrew.c.martin@…>:

As a workaround, you might want to use something like the code snippet below (in place of $ticket_props).

Perfect! I tried the workaround for fixing variable font issues, but lengthy fields were causing problems. This approach is so much better and simpler. Thanks again for sharing.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Andrew C Martin <andrew.c.martin@…>.
The resolution will be deleted.
to The owner will be changed from Andrew C Martin <andrew.c.martin@…> to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.