| 143 | | class NotifyEmail(Notify): |
| | 144 | class NotifyCIA(Notify): |
| | 145 | """Baseclass for notification via CIA.""" |
| | 146 | |
| | 147 | def notify(self, resid): |
| | 148 | """Send message to recipients.""" |
| | 149 | |
| | 150 | # stupid code logic... |
| | 151 | if self.config.getbool('notification', 'smtp_enabled'): |
| | 152 | Notify.notify(self, resid) |
| | 153 | |
| | 154 | if not self.config.getbool('notification', 'cia_enabled'): |
| | 155 | return |
| | 156 | |
| | 157 | project = self.config['notification'].get('cia_project') |
| | 158 | server = self.config['notification'].get('cia_server') |
| | 159 | |
| | 160 | if not project or not server: |
| | 161 | raise TracError(Markup('Unable to notify CIA server: ' |
| | 162 | 'neither cia project nor server specified.'), |
| | 163 | 'CIA Notification error') |
| | 164 | |
| | 165 | if self.newticket: |
| | 166 | updater = self.hdf["ticket.reporter"] |
| | 167 | else: |
| | 168 | updater = self.hdf["ticket.change.author"] |
| | 169 | |
| | 170 | if self.newticket: |
| | 171 | action = "opened" |
| | 172 | else: |
| | 173 | oldvalue = self.hdf.get("ticket.change.status.oldvalue") |
| | 174 | newvalue = self.hdf.get("ticket.change.status.newvalue") |
| | 175 | if oldvalue == "closed": |
| | 176 | action = "reopened" |
| | 177 | elif newvalue == "closed": |
| | 178 | action = "closed (%s)" % self.ticket["resolution"] |
| | 179 | else: |
| | 180 | return |
| | 181 | |
| | 182 | cia = CIA(project=project, server=server, module="ticket " + action) |
| | 183 | cia(resid, updater, |
| | 184 | "[%s] %s %s" % |
| | 185 | (self.hdf["ticket.component"], |
| | 186 | self.hdf["ticket.summary"], |
| | 187 | self.hdf['ticket.link'])) |
| | 188 | |
| | 189 | |
| | 190 | class NotifyEmail(NotifyCIA): |
| 198 | | if not self.config.getbool('notification', 'smtp_enabled'): |
| 199 | | return |
| 200 | | self.smtp_server = self.config['notification'].get('smtp_server') |
| 201 | | self.smtp_port = self.config['notification'].getint('smtp_port') |
| 202 | | self.from_email = self.config['notification'].get('smtp_from') |
| 203 | | self.replyto_email = self.config['notification'].get('smtp_replyto') |
| 204 | | self.from_email = self.from_email or self.replyto_email |
| 205 | | if not self.from_email and not self.replyto_email: |
| 206 | | raise TracError(Markup('Unable to send email due to identity ' |
| 207 | | 'crisis.<p>Neither <b>notification.from</b> ' |
| 208 | | 'nor <b>notification.reply_to</b> are ' |
| 209 | | 'specified in the configuration.</p>'), |
| 210 | | 'SMTP Notification Error') |
| | 245 | if self.config.getbool('notification', 'smtp_enabled'): |
| | 246 | self.smtp_server = self.config['notification'].get('smtp_server') |
| | 247 | self.smtp_port = self.config['notification'].getint('smtp_port') |
| | 248 | self.from_email = self.config['notification'].get('smtp_from') |
| | 249 | self.replyto_email = self.config['notification'].get('smtp_replyto') |
| | 250 | self.from_email = self.from_email or self.replyto_email |
| | 251 | if not self.from_email and not self.replyto_email: |
| | 252 | raise TracError(Markup('Unable to send email due to identity ' |
| | 253 | 'crisis.<p>Neither <b>notification.from</b> ' |
| | 254 | 'nor <b>notification.reply_to</b> are ' |
| | 255 | 'specified in the configuration.</p>'), |
| | 256 | 'SMTP Notification Error') |