Page 1 of 2

e-mail template creates weird error-report

Posted: March 8th, 2011, 12:51 pm
by ReinholD
Hey guys. I have a problem.

I recently edited my e-mail template, because i needed to use multiple mails. I made it so, that if it was a tv-show that was downloaded, it would only send a mail to me. this is what the headers looks like:

Code: Select all

<!--#if $cat == "tv" && $to == "my@mail.com" #--><!--#slurp#-->
to: $to
from: $from
date: $date
subject: $name has <!--#if $status then "completed" else "failed" #--> 
the code worked just fine before i added the && $to == "my@mail.com"
when a download finishes, it always fails with the message: PostProcessing Crashed, see logfile.

Looking into the logfile, I see this:

Code: Select all

2011-03-08 03:11:42,282::INFO::[postproc:592] Removing unwanted file /volume1/downloaded/_UNPACK_MY NZB JOB.sfv
2011-03-08 03:11:43,808::ERROR::[postproc:437] Post Processing Failed for MY NZB JOB
2011-03-08 03:11:43,816::INFO::[postproc:440] Traceback: 
Traceback (most recent call last):
  File "/volume1/@appstore/sab2/SABnzbd-0.5.4/sabnzbd/postproc.py", line 409, in run
    nzo.get_unpack_info(), script, TRANS(script_log), script_ret)
  File "/volume1/@appstore/sab2/SABnzbd-0.5.4/sabnzbd/emailer.py", line 171, in endjob
    'directiveEndToken': '#-->'})
  File "/var/packages/sab2/target/utils/lib/python2.5/site-packages/Cheetah/Template.py", line 1254, in __init__
    self._compile(source, file, compilerSettings=compilerSettings)
  File "/var/packages/sab2/target/utils/lib/python2.5/site-packages/Cheetah/Template.py", line 1548, in _compile
    keepRefToGeneratedCode=True)
  File "/var/packages/sab2/target/utils/lib/python2.5/site-packages/Cheetah/Template.py", line 793, in compile
    raise parseError
ParseError: 

Error in the Python code which Cheetah generated for this template:
================================================================================

invalid syntax (cheetah_DynamicallyCompiledCheetahTemplate_1299550303_31_84908.py, line 89)

Line|Python Code
----|-------------------------------------------------------------
87  |        # 
88  |        #  These are the email headers
89  |        if VFFSL(SL,"cat",True) == "tv" && VFFSL(SL,"to",True) == "my@mail.com": # generated from line 8, col 1
                                             ^
90  |            _v = VFFSL(SL,"to",True) # u'$to' on line 9, col 5
91  |            if _v is not None: write(_filter(_v, rawExpr=u'$to')) # from line 9, col 5.
92  |            write(u'''

================================================================================

Here is the corresponding Cheetah code:

Line 8, column 1

Line|Cheetah Code
----|-------------------------------------------------------------
5   |## Newlines and whitespace are significant!
6   |##
7   |## These are the email headers
8   |<!--#if $cat == "tv" && $to == "my@mail.com" #--><!--#slurp#-->
     ^
9   |to: $to
10  |from: $from
11  |date: $date

2011-03-08 03:11:44,268::INFO::[postproc:466] Cleaning up MY NZB JOB
2011-03-08 03:11:44,692::INFO::[__init__:702] /var/packages/sab2/target/sab/cache/SABnzbd_article_uDnrHV removed
.......
2011-03-08 03:11:44,785::INFO::[postproc:134] Saving postproc queue
2011-03-08 03:11:44,916::INFO::[downloader:357] Post-processing finished, resuming download
In the e-mail configuration page I've set the receiver to my@mail.com, friend@mail.com.
hardcoding the receiver in the e-mail header doesn't work, even though it is stated in the wiki (but I think the developers know that already).

I'm running SABnzbd+ version 0.5.4 on my Synology NAS.

thanks in advance.. :)

Re: e-mail template creates weird error-report

Posted: March 8th, 2011, 1:20 pm
by shypike
What's your assumption about the programming language of the email template?
You seem to assume you can use C or C++ constructions.
However it's a mix of Cheetah template macros and Python.
Documented here:
http://wiki.sabnzbd.org/email-templates
and here:
http://www.cheetahtemplate.org/docs/users_guide_html/

You probably should use this:

Code: Select all

<!--#if $cat == "tv" and $to == "my@mail.com" #--><!--#slurp#-->

Re: e-mail template creates weird error-report

Posted: March 8th, 2011, 1:24 pm
by ReinholD
shypike wrote: What's your assumption about the programming language of the email template?
You seem to assume you can use C or C++ constructions.
However it's a mix of Cheetah template macros and Python.
Documented here:
http://wiki.sabnzbd.org/email-templates
and here:
http://www.cheetahtemplate.org/docs/users_guide_html/

You probably should use this:

Code: Select all

<!--#if $cat == "tv" and $to == "my@mail.com" #--><!--#slurp#-->
hmm.. I tried searching through the Cheetah wiki and on google, and I remember coming across some && statements.. but I guess that was wrong.

I'll tryout your advice, and see what happens. Thanks! :)

Re: e-mail template creates weird error-report

Posted: March 9th, 2011, 2:54 am
by shypike
I must confess that I often find the Cheetah/Python combination bewildering too :)

Re: e-mail template creates weird error-report

Posted: March 9th, 2011, 7:45 am
by ReinholD
ReinholD wrote:
shypike wrote:
You probably should use this:

Code: Select all

<!--#if $cat == "tv" and $to == "my@mail.com" #--><!--#slurp#-->
hmm.. I tried searching through the Cheetah wiki and on google, and I remember coming across some && statements.. but I guess that was wrong.

I'll tryout your advice, and see what happens. Thanks! :)
well.. It solved the problem about the error. But now, I don't get any e-mail at all when downloading tv-shows.. as if the "$to" statements was false?

Using another template on movies with:

Code: Select all

<!--#if $cat == "movies" #--><!--#slurp#-->
to: $to
works just fine. (it sends an email to both me and my friend, which it is supposed to)

What am I doing wrong..? :S

Re: e-mail template creates weird error-report

Posted: March 9th, 2011, 9:53 am
by shypike
I'm not sure why you test for $to.
The recipient is always the same, so testing for $to serves no purpose.
Suppose you want to send an email to two parties,
you would need two templates, each with one hard-coded email address in the to: field.
If you want to send TV emails just to one recipient, you would
add a category test in one of the email templates.
All templates in a user defined template folder will be processed.

Re: e-mail template creates weird error-report

Posted: March 9th, 2011, 10:07 am
by ReinholD
shypike wrote: I'm not sure why you test for $to.
The recipient is always the same, so testing for $to serves no purpose.
Suppose you want to send an email to two parties,
you would need two templates, each with one hard-coded email address in the to: field.
If you want to send TV emails just to one recipient, you would
add a category test in one of the email templates.
All templates in a user defined template folder will be processed.
well.. I've tried hardcoding it, but it doesn't work.

let's say i write my@mail.com in the "to" field e-mail configuration panel. and then i make two templates: one with to: my@mail.com and one with to: friend@mail.com.
I will recieve both mails, but in the second mail, the receiver will be friend@mail.com in the headers. But I will still be the one receiving it, not my friend.

To clarify:

Code: Select all

## These are the email headers
<!--#if $cat == "movies" #--><!--#slurp#-->
to: my@mail.com
from: $from
date: $date
subject: $name has <!--#if $status then "completed" else "failed" #--> 
X-priority: 5
X-MS-priority: 5
## After this comes the body, the empty line is required!
and

Code: Select all

## These are the email headers
<!--#if $cat == "movies" #--><!--#slurp#-->
to: friend@mail.com
from: $from
date: $date
subject: $name has <!--#if $status then "completed" else "failed" #--> 
X-priority: 5
X-MS-priority: 5
## After this comes the body, the empty line is required!

will both be sent to me, even though the headers state otherwise in the received email.

writing my@mail.com, friend@mail.com in the configuration panel will send perfectly fine to both me and my friend.. but then the problem is, that he will be receiving the "tv-shows" emails aswell..

Re: e-mail template creates weird error-report

Posted: March 9th, 2011, 12:35 pm
by shypike
First of all, SABnzbd does not support lists of recipients.
OK, it puts the literal string into the $to field (like "a@b.com,c@d.com"),
but handling is done by your email provider. No guarantees.
Some use "," some use ";", some don't support lists at all.
This explains why you cannot test the $to field against an email address:
$to will contain a list, not a single address.

A hard-coded recipient in the template should work, but it doesn't.
The headers are sent, but actual library send command gets the
$to value as a parameter, which overrides the to: field in the templates.
I'll get back to you for a solution.

Re: e-mail template creates weird error-report

Posted: March 9th, 2011, 12:42 pm
by ReinholD
shypike wrote: First of all, SABnzbd does not support lists of recipients.
OK, it puts the literal string into the $to field (like "a@b.com,c@d.com"),
but handling is done by your email provider. No guarantees.
Some use "," some use ";", some don't support lists at all.
This explains why you cannot test the $to field against an email address:
$to will contain a list, not a single address.

A hard-coded recipient in the template should work, but it doesn't.
The headers are sent, but actual library send command gets the
$to value as a parameter, which overrides the to: field in the templates.
I'll get back to you for a solution.

awesome! I've never met such great developers/community with such great support. :)

Re: e-mail template creates weird error-report

Posted: March 9th, 2011, 2:10 pm
by shypike
I checked the code.
Some time ago, support for a recipient list was built in.
So email will be sent to all recipients, but only in one transaction.
This means that the $to variable will contain the full list of recipients,
making the implementation of your idea impossible.
I can fix this by sending the email for each recipient separately.
However, we will not create new 0.5.x releases.
You'll have to wait for 0.6.0 Beta4 (we're now at Beta3) for this to be implemented.

BTW: hard-coding the email address is not effective.

Re: e-mail template creates weird error-report

Posted: March 9th, 2011, 2:39 pm
by ReinholD
shypike wrote: I checked the code.
Some time ago, support for a recipient list was built in.
So email will be sent to all recipients, but only in one transaction.
This means that the $to variable will contain the full list of recipients,
making the implementation of your idea impossible.
I can fix this by sending the email for each recipient separately.
However, we will not create new 0.5.x releases.
You'll have to wait for 0.6.0 Beta4 (we're now at Beta3) for this to be implemented.

BTW: hard-coding the email address is not effective.


Arh, okay.. could be awesome!

Although I doubt that the SABnzbd+ package for Synology NAS will be updated in the near future anyway.. but still.. keep up the good work! :)

Re: e-mail template creates weird error-report

Posted: March 9th, 2011, 3:09 pm
by shypike
Does the package come with Python sources?
If you want, I can send you a patched emailer.py module.
Check first if you can find this file.

Re: e-mail template creates weird error-report

Posted: March 9th, 2011, 3:21 pm
by ReinholD
shypike wrote: Does the package come with Python sources?
If you want, I can send you a patched emailer.py module.
Check first if you can find this file.

The package runs solely python i think.. the emailer.py is there, along with an emailer.pyc(?). In fact all the .py files in the folder have a corresponding .pyc file.

Re: e-mail template creates weird error-report

Posted: March 9th, 2011, 5:45 pm
by shypike
Delete the emailer.pyc file and replace emailer.py with the attached file.
Good luck.

Re: e-mail template creates weird error-report

Posted: March 9th, 2011, 6:06 pm
by ReinholD
shypike wrote: Delete the emailer.pyc file and replace emailer.py with the attached file.
Good luck.
works like a charm! thank you so much!

Donation procedure initiating in 3.. 2.. 1....