|
Pierre-Yves Chibon |
d8781e |
#-*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
d8781e |
|
|
Pierre-Yves Chibon |
d8781e |
"""
|
|
Pierre-Yves Chibon |
d8781e |
(c) 2014 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
d8781e |
|
|
Pierre-Yves Chibon |
d8781e |
Authors:
|
|
Pierre-Yves Chibon |
d8781e |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
d8781e |
|
|
Pierre-Yves Chibon |
d8781e |
progit notifications.
|
|
Pierre-Yves Chibon |
d8781e |
"""
|
|
Pierre-Yves Chibon |
d8781e |
|
|
Pierre-Yves Chibon |
d8781e |
import smtplib
|
|
Pierre-Yves Chibon |
d8781e |
|
|
Pierre-Yves Chibon |
d8781e |
import progit
|
|
Pierre-Yves Chibon |
d8781e |
|
|
Pierre-Yves Chibon |
d8781e |
from email.mime.text import MIMEText
|
|
Pierre-Yves Chibon |
d8781e |
|
|
Pierre-Yves Chibon |
d8781e |
|
|
Pierre-Yves Chibon |
67cc89 |
def send_email(text, subject, to_mail, from_mail=None, mail_id=None,
|
|
Pierre-Yves Chibon |
67cc89 |
in_reply_to=None):
|
|
Pierre-Yves Chibon |
d8781e |
''' Send an email with the specified information.
|
|
Pierre-Yves Chibon |
d8781e |
|
|
Pierre-Yves Chibon |
d8781e |
:arg text: the content of the email to send
|
|
Pierre-Yves Chibon |
d8781e |
:arg subject: the subject of the email
|
|
Pierre-Yves Chibon |
d8781e |
:arg to_mail: a string representing a list of recipient separated by a
|
|
Pierre-Yves Chibon |
d8781e |
coma
|
|
Pierre-Yves Chibon |
d8781e |
:kwarg from_mail: the email address the email is sent from.
|
|
Pierre-Yves Chibon |
d8781e |
Defaults to nobody@progit
|
|
Pierre-Yves Chibon |
67cc89 |
:kwarg mail_id: if defined, the header `mail-id` is set with this value
|
|
Pierre-Yves Chibon |
67cc89 |
:kwarg in_reply_to: if defined, the header `In-Reply-To` is set with
|
|
Pierre-Yves Chibon |
67cc89 |
this value
|
|
Pierre-Yves Chibon |
d8781e |
|
|
Pierre-Yves Chibon |
d8781e |
'''
|
|
Pierre-Yves Chibon |
d8781e |
msg = MIMEText(text.encode('utf-8'), 'plain', 'utf-8')
|
|
Pierre-Yves Chibon |
d8781e |
msg['Subject'] = '[Progit] %s' % subject
|
|
Pierre-Yves Chibon |
d8781e |
if not from_mail:
|
|
Pierre-Yves Chibon |
d8781e |
from_email = 'progit@fedoraproject.org'
|
|
Pierre-Yves Chibon |
d8781e |
msg['From'] = from_email
|
|
Pierre-Yves Chibon |
977702 |
msg['Bcc'] = to_mail.replace(',', ', ')
|
|
Pierre-Yves Chibon |
d8781e |
|
|
Pierre-Yves Chibon |
67cc89 |
if mail_id:
|
|
Pierre-Yves Chibon |
67cc89 |
msg['mail-id'] = mail_id
|
|
Pierre-Yves Chibon |
67cc89 |
|
|
Pierre-Yves Chibon |
67cc89 |
if in_reply_to:
|
|
Pierre-Yves Chibon |
67cc89 |
msg['In-Reply-To'] = '<%s>' % in_reply_to
|
|
Pierre-Yves Chibon |
67cc89 |
|
|
Pierre-Yves Chibon |
d8781e |
# Send the message via our own SMTP server, but don't include the
|
|
Pierre-Yves Chibon |
d8781e |
# envelope header.
|
|
Pierre-Yves Chibon |
d8781e |
smtp = smtplib.SMTP(progit.APP.config['SMTP_SERVER'])
|
|
Pierre-Yves Chibon |
d8781e |
smtp.sendmail(
|
|
Pierre-Yves Chibon |
d8781e |
from_email,
|
|
Pierre-Yves Chibon |
d8781e |
to_mail.split(','),
|
|
Pierre-Yves Chibon |
d8781e |
msg.as_string())
|
|
Pierre-Yves Chibon |
d8781e |
smtp.quit()
|
|
Pierre-Yves Chibon |
d8781e |
return msg
|
|
Pierre-Yves Chibon |
d8781e |
|
|
Pierre-Yves Chibon |
d8781e |
|
|
Pierre-Yves Chibon |
d8781e |
def notify_new_comment(comment):
|
|
Pierre-Yves Chibon |
d8781e |
''' Notify the people following an issue that a new comment was added
|
|
Pierre-Yves Chibon |
d8781e |
to the issue.
|
|
Pierre-Yves Chibon |
d8781e |
'''
|
|
Pierre-Yves Chibon |
d8781e |
text = """
|
|
Pierre-Yves Chibon |
20ba4e |
%s added a new comment to an issue you are following.
|
|
Pierre-Yves Chibon |
d8781e |
|
|
Pierre-Yves Chibon |
d8781e |
New comment:
|
|
Pierre-Yves Chibon |
d8781e |
|
|
Pierre-Yves Chibon |
d8781e |
``
|
|
Pierre-Yves Chibon |
d8781e |
%s
|
|
Pierre-Yves Chibon |
d8781e |
``
|
|
Pierre-Yves Chibon |
d8781e |
|
|
Pierre-Yves Chibon |
d8781e |
%s
|
|
Pierre-Yves Chibon |
d8781e |
""" % (
|
|
Pierre-Yves Chibon |
d8781e |
comment.user.user,
|
|
Pierre-Yves Chibon |
d8781e |
comment.comment,
|
|
Pierre-Yves Chibon |
d8781e |
'%s/%s/issue/%s' % (
|
|
Pierre-Yves Chibon |
d8781e |
progit.APP.config['APP_URL'],
|
|
Pierre-Yves Chibon |
d8781e |
comment.issue.project.name,
|
|
Pierre-Yves Chibon |
d8781e |
comment.issue.id,
|
|
Pierre-Yves Chibon |
d8781e |
),
|
|
Pierre-Yves Chibon |
d8781e |
)
|
|
Pierre-Yves Chibon |
d8781e |
mail_to = set([cmt.user.emails[0].email for cmt in comment.issue.comments])
|
|
Pierre-Yves Chibon |
d8781e |
mail_to.add(comment.issue.project.user.emails[0].email)
|
|
Pierre-Yves Chibon |
d8781e |
send_email(
|
|
Pierre-Yves Chibon |
d8781e |
text,
|
|
Pierre-Yves Chibon |
d8781e |
'Update to issue `%s`' % comment.issue.title,
|
|
Pierre-Yves Chibon |
5d4b74 |
','.join(mail_to),
|
|
Pierre-Yves Chibon |
5d4b74 |
in_reply_to=comment.issue.mail_id,
|
|
Pierre-Yves Chibon |
d8781e |
)
|
|
Pierre-Yves Chibon |
cf312a |
|
|
Pierre-Yves Chibon |
cf312a |
|
|
Pierre-Yves Chibon |
cf312a |
def notify_new_issue(issue):
|
|
Pierre-Yves Chibon |
cf312a |
''' Notify the people following a project that a new issue was added
|
|
Pierre-Yves Chibon |
cf312a |
to it.
|
|
Pierre-Yves Chibon |
cf312a |
'''
|
|
Pierre-Yves Chibon |
cf312a |
text = """
|
|
Pierre-Yves Chibon |
cf312a |
%s reported a new issue against the project: `%s` that you are following.
|
|
Pierre-Yves Chibon |
cf312a |
|
|
Pierre-Yves Chibon |
cf312a |
New issue:
|
|
Pierre-Yves Chibon |
cf312a |
|
|
Pierre-Yves Chibon |
cf312a |
``
|
|
Pierre-Yves Chibon |
cf312a |
%s
|
|
Pierre-Yves Chibon |
cf312a |
``
|
|
Pierre-Yves Chibon |
cf312a |
|
|
Pierre-Yves Chibon |
cf312a |
%s
|
|
Pierre-Yves Chibon |
cf312a |
""" % (
|
|
Pierre-Yves Chibon |
cf312a |
issue.user.user,
|
|
Pierre-Yves Chibon |
cf312a |
issue.project.name,
|
|
Pierre-Yves Chibon |
cf312a |
issue.content,
|
|
Pierre-Yves Chibon |
cf312a |
'%s/%s/issue/%s' % (
|
|
Pierre-Yves Chibon |
cf312a |
progit.APP.config['APP_URL'],
|
|
Pierre-Yves Chibon |
cf312a |
issue.project.name,
|
|
Pierre-Yves Chibon |
cf312a |
issue.id,
|
|
Pierre-Yves Chibon |
cf312a |
),
|
|
Pierre-Yves Chibon |
cf312a |
)
|
|
Pierre-Yves Chibon |
cf312a |
mail_to = set([cmt.user.emails[0].email for cmt in issue.comments])
|
|
Pierre-Yves Chibon |
cf312a |
mail_to.add(issue.project.user.emails[0].email)
|
|
Pierre-Yves Chibon |
a1c51a |
for prouser in issue.project.user:
|
|
Pierre-Yves Chibon |
a1c51a |
if prouser.user.emails:
|
|
Pierre-Yves Chibon |
a1c51a |
mail_to.add(prouser.user.emails[0].email)
|
|
Pierre-Yves Chibon |
a1c51a |
|
|
Pierre-Yves Chibon |
cf312a |
send_email(
|
|
Pierre-Yves Chibon |
cf312a |
text,
|
|
Pierre-Yves Chibon |
cf312a |
'New issue `%s`' % issue.title,
|
|
Pierre-Yves Chibon |
6fb585 |
','.join(mail_to),
|
|
Pierre-Yves Chibon |
6fb585 |
mail_id=issue.mail_id,
|
|
Pierre-Yves Chibon |
cf312a |
)
|