How can I modify the ticket link in notifications

24 views
Skip to first unread message

Christopher Nelson

unread,
Nov 25, 2020, 12:44:03 PM11/25/20
to trac-...@googlegroups.com
I'm using SendGrid as my mail relay for Trac 1.0.1 notifications.  It adds click tracking to URls so the footer of the notification looks a mess.  I can suppress this by adding "clicktracking=off" before "href" in the <a> tab but I can't figure out how to do that.  I've edited  ticket_notify_email.txt to end:

${_('Ticket URL: <%(link.replace("href", "clicktracking=off href"))s>', link=ticket.link}

And a couple of other alternatives but the changes I thought were promising seem to be syntax errors which break the template and I don't get notified at all.  Genshi is not my strong suit so I'm kind of blindly trying things that seem like they might work but I could use some guidance.  Thanks.

--
Christopher Nelson, PE
Professional Software Engineer
@ChrisNelsonPE
LinkedIn.com/in/ChrisNelsonPE
NoPerfectProgram.Wordpress.com

RjOllos

unread,
Nov 25, 2020, 1:12:48 PM11/25/20
to Trac Users
On Wednesday, November 25, 2020 at 9:44:03 AM UTC-8 Chris Nelson wrote:
I'm using SendGrid as my mail relay for Trac 1.0.1 notifications.  It adds click tracking to URls so the footer of the notification looks a mess.  I can suppress this by adding "clicktracking=off" before "href" in the <a> tab but I can't figure out how to do that.  I've edited  ticket_notify_email.txt to end:

${_('Ticket URL: <%(link.replace("href", "clicktracking=off href"))s>', link=ticket.link}

And a couple of other alternatives but the changes I thought were promising seem to be syntax errors which break the template and I don't get notified at all.  Genshi is not my strong suit so I'm kind of blindly trying things that seem like they might work but I could use some guidance.  Thanks.

Try this:

${_('Ticket URL: <%(link)s>', link=ticket.link.replace("href", "clicktracking=off href")} 

If that doesn't work, then:

{% with link=ticket.link.replace("href", "clicktracking=off href") %}\
${_('Ticket URL: <%(link)s>', link=link} 
{% end %}\


Ryan

Chris Nelson

unread,
Dec 3, 2020, 9:52:31 AM12/3/20
to Trac Users
Thanks.  I'll try that.  But I realize I'm going to need to also handle links in the body of the notification (e.g., if a comment or ticket description change includes a link).

RjOllos

unread,
Dec 3, 2020, 2:03:47 PM12/3/20
to Trac Users
On Thursday, December 3, 2020 at 6:52:31 AM UTC-8 Chris Nelson wrote:
Thanks.  I'll try that.  But I realize I'm going to need to also handle links in the body of the notification (e.g., if a comment or ticket description change includes a link).

I use SendGrid for my Trac development instances. How are the <a> elements formatted when click tracking is enabled? The emails I receive to gmail have a "data-saferedirecturl" attribute that looks like it might be related to the click tracking, but I don't know how click tracking works.

Ryan 

Christopher Nelson

unread,
Dec 4, 2020, 3:20:26 PM12/4/20
to trac-...@googlegroups.com
My email notifications come in with URLs that start like 


then wrap to four more lines which look like gibberish.  Clicking goes to SendGrid, records my click, then redirects to Trac.  It'd be nice if SendGrid let you turn off click tracking by API key so one defaulted to on and another defaulted to off but I don't seem to be able to find that, if it exists.

I've edited every instance of `ticket_notify_email.txt` on my server (even just to change "URL" to "url") but the change doesn't show up on notifications, even after restarting `tracd`.  My Trac admin skills are really stale. :-(

RjOllos

unread,
Dec 4, 2020, 7:43:18 PM12/4/20
to Trac Users
That's weird, I've never seen it, and I'm just using the free account.

To customize `ticket_notify_email.txt`, put a copy in $env/templates. It should be picked up by a server restart.

Ryan 

RjOllos

unread,
Dec 4, 2020, 7:54:24 PM12/4/20
to Trac Users
Actually, just reproduced. Will investigate.

RjOllos

unread,
Dec 4, 2020, 9:01:30 PM12/4/20
to Trac Users
I didn't think this through. The emails are plain text, and "ticket.link" is just a unicode string, not an HTML element.
>>> env.abs_href.ticket(1)

However, I did find that click tracking can be turned off, and it worked on my end.

Screen Shot 2020-12-04 at 17.59.39.jpg 

Christopher Nelson

unread,
Dec 4, 2020, 10:45:45 PM12/4/20
to trac-...@googlegroups.com
We are on Silver Tier (I think), the lowest paid level.
To customize `ticket_notify_email.txt`, put a copy in $env/templates. It should be picked up by a server restart.
I'll try that.  Thanks.

Is there a way to restart `tracd` other than killing and running it again?  I looked for a signal to send it or something but didn't find any documentation. 

RjOllos

unread,
Dec 4, 2020, 10:47:40 PM12/4/20
to Trac Users
I'm not aware of way, other than killing the process. 

Christopher Nelson

unread,
Dec 4, 2020, 10:48:52 PM12/4/20
to trac-...@googlegroups.com
On Fri, Dec 4, 2020 at 9:01 PM RjOllos <rjo...@gmail.com> wrote:
I didn't think this through. The emails are plain text, and "ticket.link" is just a unicode string, not an HTML element.
>>> env.abs_href.ticket(1)

Ah, so there's not "href" to replace!  I think that to affect the body (e.g., a comment or changed description), I need to do it in code.  I'll look into that.
However, I did find that click tracking can be turned off, and it worked on my end.


Yes, but that is for the whole account. We use this for three different applications and Trac is the only one where I know I don't want tracking.

RjOllos

unread,
Dec 4, 2020, 10:55:54 PM12/4/20
to Trac Users
On Friday, December 4, 2020 at 7:48:52 PM UTC-8 Chris Nelson wrote:
On Fri, Dec 4, 2020 at 9:01 PM RjOllos <rjo...@gmail.com> wrote:
I didn't think this through. The emails are plain text, and "ticket.link" is just a unicode string, not an HTML element.
>>> env.abs_href.ticket(1)

Ah, so there's not "href" to replace!  I think that to affect the body (e.g., a comment or changed description), I need to do it in code.  I'll look into that.
However, I did find that click tracking can be turned off, and it worked on my end.


Yes, but that is for the whole account. We use this for three different applications and Trac is the only one where I know I don't want tracking.

I'm surprised SendGrid is modifying the plain text emails. You might have to ask them if there's a way to do the equivalent of clicktracking=off for plain text emails.

Christopher Nelson

unread,
Dec 5, 2020, 7:41:31 AM12/5/20
to trac-...@googlegroups.com
What confused me was there was no template there to start with.  When I put one there, it is used.  I'm not sure where it gets the default if there isn't one in the environment <shrug>. 

I'm guessing that the <%(link)s> in the template's footer is handled by Genshi so just changing Trac source (which I'd have to do for links in the body) isn't going to fix that. :-(  I guess I'll go see what SendGrid can do for me.

                 Chris

Ryan Ollos

unread,
Dec 5, 2020, 1:28:57 PM12/5/20
to Trac Users
On Sat, Dec 5, 2020 at 4:41 AM Christopher Nelson <chris.ne...@gmail.com> wrote:
On Fri, Dec 4, 2020 at 10:45 PM Christopher Nelson <chris.ne...@gmail.com> wrote:
On Fri, Dec 4, 2020 at 7:43 PM RjOllos <rjo...@gmail.com> wrote:
To customize `ticket_notify_email.txt`, put a copy in $env/templates. It should be picked up by a server restart. 
I'll try that.  Thanks.

What confused me was there was no template there to start with.  When I put one there, it is used.  I'm not sure where it gets the default if there isn't one in the environment <shrug>. 

The default is contained in the egg or wheel.
$ ls ~/.pyenv/versions/trac-2.7/lib/python2.7/site-packages/Trac-1.4.2-py2.7.egg/trac/ticket/templates/ticket_notify_email.txt
/Users/rjollos/.pyenv/versions/trac-2.7/lib/python2.7/site-packages/Trac-1.4.2-py2.7.egg/trac/ticket/templates/ticket_notify_email.txt

A template in $env/templates with the same name as a Trac or plugin templates will override Trac or the plugin, but in general, it's not recommended because you need to re-apply your changes each time the template changes in an upgrade.

ticket_notify_email.txt, is a special case in that it doesn't change very often. But good to keep a diff or your changes so you can apply them to a copy of a new template after upgrade.

I'm working this week on upgrading a Trac site in which the previous maintainer had made copies of various templates like wiki_view.html in an earlier version of Trac, probably 1.0.3. The templates were all customized. Now they are on Trac 1.0.9 and several features are broken because they are serving modified versions of 1.0.3 templates. I'm talking them to 1.0.20, then hopefully 1.2.6 and 1.4.2 eventually. Things would get worse and worse if we continued using 1.0.3 templates through those upgrade steps. 

The next step is to go through all those templates and diff them, figure out what the customizations are, and hopefully implement those the right way: via ITemplateStreamFilter (deprecated in Trac 1.4) or JavaScript.

Customizing the notification template is probably the most typical use case for $env/templates. You are right, the tricky thing is to know how to get the template and copy it there. You can fetch it from the Trac repository or copy it from the install location if you know where to find it.

We could consider adding a trac-admin command.

trac-admin $env extract_template ticket_notify_email.txt

But per my example, we don't want to make it too easy for users to customize templates, at least without making the warnings about the risks much more prominent and frequent.

I'm guessing that the <%(link)s> in the template's footer is handled by Genshi so just changing Trac source (which I'd have to do for links in the body) isn't going to fix that. :-(  I guess I'll go see what SendGrid can do for me.

                 Chris
--
Christopher Nelson, PE
Professional Software Engineer
@ChrisNelsonPE
LinkedIn.com/in/ChrisNelsonPE
NoPerfectProgram.Wordpress.com

--
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trac-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/trac-users/CAFFqYiAja%3DwvNiyvJvsp28PWTa9Ah11OK4L8RhpGNenNPBxNmg%40mail.gmail.com.

Chris Nelson

unread,
Jan 4, 2021, 3:37:50 PM1/4/21
to Trac Users
I got this resolved by creating a subuser in my SendGrid account, turning off tracking for that subuser, and creating an API key for that subuser which I could use to send email from Trac without click tracking.
Reply all
Reply to author
Forward
0 new messages