Modify

Opened 7 years ago

Last modified 7 years ago

#13252 new defect

Xmail filter did not execute

Reported by: ntmlod Owned by: Franz
Priority: normal Component: MailPlugin
Severity: normal Keywords:
Cc: Trac Release: 1.0

Description

On our Trac 1.0.1, I ran into a first issue during installation

2017-07-31 21:21:06,196 Trac[loader] ERROR: Skipping "xmail = xmail": 
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/trac/loader.py", line 68, in _load_eggs
    entry.load(require=True)
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2260, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "build/bdist.linux-x86_64/egg/xmail/__init__.py", line 2, in <module>
  File "build/bdist.linux-x86_64/egg/xmail/XMailEMailModule.py", line 22, in <module>
ImportError: cannot import name Locale

I followed the fix suggested by rjollos on comment:2:ticket:12580

  • xmail/XMailEMailModule.py

     
    1919from trac.notification import NotifyEmail
    2020from trac.util import translation
    2121from trac.util.datefmt import format_datetime
    22 from trac.util.translation import Locale, activate, domain_functions
     22from trac.util.translation import activate, domain_functions
    2323from trac.web.api import ITemplateStreamFilter
     24from trac.prefs.web_ui import Locale
    2425from xmail.XMailFilterObject import FilterObject
    2526from trac.core import Component, implements
    2627

Then everything seemed to go well, for testing I configured a first filter, checked the tickets list, activated it and set the execution for few minutes later but nothing happened even in the log. On Xmail page, lastsuccessexe is !void.

The date format used by Xmail MM/DD/YY hh:mm:ss is not the one configured for Trac (ISO8601) but I tested I can use both. Also I found that our DB is not at the same time zone as Trac but if it was an issue we would have been in trouble for a long time.

Attachments (0)

Change History (4)

comment:1 Changed 7 years ago by Jun Omae

It must not import Locale symbol from any module under trac.*.

comment:2 Changed 7 years ago by Jun Omae

It would be simple to use req.locale rather than Locale.negotiate (untested).

However, it should not store to _locale_string property of Component instance. Only single instance of Component is created for all threads.

  • mailplugin/trunk/xmail/XMailEMailModule.py

    diff --git a/mailplugin/trunk/xmail/XMailEMailModule.py b/mailplugin/trunk/xmail/XMailEMailModule.py
    index 1caffe5df..bcb7281d2 100644
    a b from pkg_resources import resource_filename # @UnresolvedImport 
    1717from trac.config import IntOption
    1818from trac.loader import get_plugin_info
    1919from trac.notification import NotifyEmail
    20 from trac.util import translation
    2120from trac.util.datefmt import format_datetime
    22 from trac.util.translation import Locale, activate, domain_functions
     21from trac.util.translation import activate, domain_functions
    2322from trac.web.api import ITemplateStreamFilter
    2423from xmail.XMailFilterObject import FilterObject
    2524from trac.core import Component, implements
    class XMailEventHandler(Component): 
    4948        add_domain(self.env.path, locale_dir)
    5049
    5150    def filter_stream(self, req, method, filename, stream, data):
    52         if Locale and not self._TimerIsStillAlive():
    53             # copied from main.py:310ff
    54             available = [locale_id.replace('_', '-') for locale_id in
    55                          translation.get_available_locales()]
    56 
    57             preferred = req.session.get('language', req.languages)
    58             if not isinstance(preferred, list):
    59                 preferred = [preferred]
    60             self._locale_string = Locale.negotiate(
    61                 preferred, available, sep='-')
    62             self.log.debug("Negotiated locale: %s -> %s",
    63                            preferred, self._locale_string)
    64 
     51        if not self._TimerIsStillAlive():
     52            self._locale_string = str(req.locale) if req.locale else 'en_US'
    6553        return stream
    6654
    6755    #=========================================================================
Last edited 7 years ago by Jun Omae (previous) (diff)

comment:3 Changed 7 years ago by Jun Omae

Other issue, db api should be used for username in the following:

xmail/XMailEMailModule.py:

242     def _get_user_data(self, username):
243         sql = ("select name, value from session_attribute where name in ('language', 'email')"
244                " and sid='%s'" % username)

xmail/XMailMainView.py:

215         sql = "select " + \
216             get_col_list(['username', 'selectfields', 'whereclause'])
217         sql += " from " + XMAIL_TABLE.name + " where username='" + \
218             req.authname + "' order by filtername"

comment:4 in reply to:  2 Changed 7 years ago by ntmlod

Replying to Jun Omae:

It would be simple to use req.locale rather than Locale.negotiate (untested).

However, it should not store to _locale_string property of Component instance. Only single instance of Component is created for all threads.

  • mailplugin/trunk/xmail/XMailEMailModule.py

    diff --git a/mailplugin/trunk/xmail/XMailEMailModule.py b/mailplugin/trunk/xmail/XMailEMailModule.py
    index 1caffe5df..bcb7281d2 100644
    a b from pkg_resources import resource_filename # @UnresolvedImport 
    1717from trac.config import IntOption
    1818from trac.loader import get_plugin_info
    1919from trac.notification import NotifyEmail
    20 from trac.util import translation
    2120from trac.util.datefmt import format_datetime
    22 from trac.util.translation import Locale, activate, domain_functions
     21from trac.util.translation import activate, domain_functions
    2322from trac.web.api import ITemplateStreamFilter
    2423from xmail.XMailFilterObject import FilterObject
    2524from trac.core import Component, implements
    class XMailEventHandler(Component): 
    4948        add_domain(self.env.path, locale_dir)
    5049
    5150    def filter_stream(self, req, method, filename, stream, data):
    52         if Locale and not self._TimerIsStillAlive():
    53             # copied from main.py:310ff
    54             available = [locale_id.replace('_', '-') for locale_id in
    55                          translation.get_available_locales()]
    56 
    57             preferred = req.session.get('language', req.languages)
    58             if not isinstance(preferred, list):
    59                 preferred = [preferred]
    60             self._locale_string = Locale.negotiate(
    61                 preferred, available, sep='-')
    62             self.log.debug("Negotiated locale: %s -> %s",
    63                            preferred, self._locale_string)
    64 
     51        if not self._TimerIsStillAlive():
     52            self._locale_string = str(req.locale) if req.locale else 'en_US'
    6553        return stream
    6654
    6755    #=========================================================================

I applied your patch but now the Xmail page loads indefinitely... Nothing in the log

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The owner will remain Franz.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.