<commit_before># -*- coding: utf-8 -*-
#
# Copyright (C) 2003-2006 Edgewall Software
# Copyright (C) 2003-2005 <NAME> <<EMAIL>>
# Copyright (C) 2005-2006 <NAME> <<EMAIL>>
# All rights reserved.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at http://trac.edgewall.com/license.html.
#
# This software consists of voluntary contributions made by many
# individuals. For the exact contribution history, see the revision
# history and logs, available at http://projects.edgewall.com/trac/.
#
# Author: <NAME> <<EMAIL>>
#

import md5

from trac import __version__
from trac.core import *
from trac.config import *
from trac.util.text import CRLF, wrap
from trac.notification import NotifyEmail


class TicketNotificationSystem(Component):

    always_notify_owner = BoolOption('notification', 'always_notify_owner',
                                     'false',
        """Always send notifications to the ticket owner (''since 0.9'').""")

    always_notify_reporter = BoolOption('notification', 'always_notify_reporter',
                                        'false',
        """Always send notifications to any address in the ''reporter''
        field.""")

    always_notify_updater = BoolOption('notification', 'always_notify_updater',
                                       'true',
        """Always send notifications to the person who causes the ticket 
        property change.""")


class TicketNotifyEmail(NotifyEmail):
    """Notification of ticket changes."""

    template_name = "ticket_notify_email.cs"
    ticket = None
    newticket = None
    modtime = 0
    from_email = 'trac+ticket@localhost'
    COLS = 75

    def __init__(self, env):
        NotifyEmail.__init__(self, env)
        self.prev_cc = []

    def notify(self, ticket, req, newticket=True, modtime=0):
        self.ticket = ticket
        self.modtime = modtime
        self.newticket = newticket
        self.ticket['description'] = wrap(self.ticket.values.get('description', ''),
                                          self.COLS, initial_indent=' ',
                                          subsequent_indent=' ', linesep=CRLF)
        self.hdf.set_unescaped('email.ticket_props', self.format_props())
        self.hdf.set_unescaped('email.ticket_body_hdr', self.format_hdr())
        self.hdf['ticket.new'] = self.newticket
        subject = self.format_subj()
        link = req.abs_href.ticket(ticket.id)
        if not self.newticket:
            subject = 'Re: ' + subject
        self.hdf.set_unescaped('email.subject', subject)
        changes = ''
        if not self.newticket and modtime:  # Ticket change
            from trac.ticket.web_ui import TicketModule
            for change in TicketModule(self.env).grouped_changelog_entries(
                ticket, self.db, when=modtime):
                if not change['permanent']: # attachment with same time...
                    continue
                self.hdf.set_unescaped('ticket.change.author', 
                                       change['author'])
                self.hdf.set_unescaped('ticket.change.comment',
                                       change['comment'])
                link += '#comment:%d' % change['cnum']
                for field, values in change['fields'].iteritems():
                    old = values['old']
                    new = values['new']
                    pfx = 'ticket.change.%s' % field
                    newv = ''
                    if field == 'comment':
                        newv = wrap(new, self.COLS, ' ', ' ', CRLF)
                    elif field == 'description':
                        new_descr = wrap(new, self.COLS, ' ', ' ', CRLF)
                        old_descr = wrap(old, self.COLS, '> ', '> ', CRLF)
                        old_descr = old_descr.replace(2*CRLF, CRLF + '>' + CRLF)
                        cdescr = CRLF
                        cdescr += 'Old description:' + 2*CRLF + old_descr + 2*CRLF
                        cdescr += 'New description:' + 2*CRLF + new_descr + CRLF
                        self.hdf.set_unescaped('email.changes_descr', cdescr)
                    elif field == 'cc':
                        (addcc, delcc) = self.diff_cc(old, new)
                        chgcc = ''
                        if delcc:
                            chgcc += wrap(" * cc: %s (removed)" % ', '.join(delcc), 
                                          self.COLS, ' ', ' ', CRLF)
                            chgcc += CRLF<commit_msg>Follow-up to r3468: the comment should be wrapped.<commit_after># -*- coding: utf-8 -*-
#
# Copyright (C) 2003-2006 Edgewall Software
# Copyright (C) 2003-2005 <NAME> <<EMAIL>>
# Copyright (C) 2005-2006 <NAME> <<EMAIL>>
# All rights reserved.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at http://trac.edgewall.com/license.html.
#
# This software consists of voluntary contributions made by many
# individuals. For the exact contribution history, see the revision
# history and logs, available at http://projects.edgewall.com/trac/.
#
# Author: <NAME> <<EMAIL>>
#

import md5

from trac import __version__
from trac.core import *
from trac.config import *
from trac.util.text import CRLF, wrap
from trac.notification import NotifyEmail


class TicketNotificationSystem(Component):

    always_notify_owner = BoolOption('notification', 'always_notify_owner',
                                     'false',
        """Always send notifications to the ticket owner (''since 0.9'').""")

    always_notify_reporter = BoolOption('notification', 'always_notify_reporter',
                                        'false',
        """Always send notifications to any address in the ''reporter''
        field.""")

    always_notify_updater = BoolOption('notification', 'always_notify_updater',
                                       'true',
        """Always send notifications to the person who causes the ticket 
        property change.""")


class TicketNotifyEmail(NotifyEmail):
    """Notification of ticket changes."""

    template_name = "ticket_notify_email.cs"
    ticket = None
    newticket = None
    modtime = 0
    from_email = 'trac+ticket@localhost'
    COLS = 75

    def __init__(self, env):
        NotifyEmail.__init__(self, env)
        self.prev_cc = []

    def notify(self, ticket, req, newticket=True, modtime=0):
        self.ticket = ticket
        self.modtime = modtime
        self.newticket = newticket
        self.ticket['description'] = wrap(self.ticket.values.get('description', ''),
                                          self.COLS, initial_indent=' ',
                                          subsequent_indent=' ', linesep=CRLF)
        self.hdf.set_unescaped('email.ticket_props', self.format_props())
        self.hdf.set_unescaped('email.ticket_body_hdr', self.format_hdr())
        self.hdf['ticket.new'] = self.newticket
        subject = self.format_subj()
        link = req.abs_href.ticket(ticket.id)
        if not self.newticket:
            subject = 'Re: ' + subject
        self.hdf.set_unescaped('email.subject', subject)
        changes = ''
        if not self.newticket and modtime:  # Ticket change
            from trac.ticket.web_ui import TicketModule
            for change in TicketModule(self.env).grouped_changelog_entries(
                ticket, self.db, when=modtime):
                if not change['permanent']: # attachment with same time...
                    continue
                self.hdf.set_unescaped('ticket.change.author', 
                                       change['author'])
                self.hdf.set_unescaped('ticket.change.comment',
                                       wrap(change['comment'], self.COLS,
                                            ' ', ' ', CRLF))
                link += '#comment:%d' % change['cnum']
                for field, values in change['fields'].iteritems():
                    old = values['old']
                    new = values['new']
                    pfx = 'ticket.change.%s' % field
                    newv = ''
                    if field == 'description':
                        new_descr = wrap(new, self.COLS, ' ', ' ', CRLF)
                        old_descr = wrap(old, self.COLS, '> ', '> ', CRLF)
                        old_descr = old_descr.replace(2*CRLF, CRLF + '>' + CRLF)
                        cdescr = CRLF
                        cdescr += 'Old description:' + 2*CRLF + old_descr + 2*CRLF
                        cdescr += 'New description:' + 2*CRLF + new_descr + CRLF
                        self.hdf.set_unescaped('email.changes_descr', cdescr)
                    elif field == 'cc':
                        (addcc, delcc) = self.diff_cc(old, new)
                        chgcc = ''
                        if delcc:
                            chgcc += wrap(" * cc: %s (removed)" % ', '.join(delcc), 
                                          self.COLS, ' ', ' ', CRLF)
                            chgcc += CRLF
{'fraction_non_alphanumeric': 0.11322196746369691, 'fraction_numerical': 0.008297849110164865, 'mean_word_length': 1.7648656806519771, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4910199', 'n_tokens_mistral': 2631, 'n_tokens_neox': 2382, 'n_words': 613}