Back to index

moin  1.9.0~rc2
Functions
MoinMoin.events.emailnotify Namespace Reference

Functions

def prep_page_changed_mail
def send_notification
def handle_page_change
def handle_user_created
def handle_file_attached
def handle_file_removed
def handle

Function Documentation

An event handler

Definition at line 201 of file emailnotify.py.

00201 
00202 def handle(event):
00203     """An event handler"""
00204 
00205     if not event.request.cfg.mail_enabled:
00206         return
00207 
00208     if isinstance(event, (ev.PageChangedEvent, ev.TrivialPageChangedEvent)):
00209         return handle_page_change(event)
00210     elif isinstance(event, ev.UserCreatedEvent):
00211         return handle_user_created(event)
00212     elif isinstance(event, ev.FileAttachedEvent):
00213         return handle_file_attached(event)
00214     elif isinstance(event, ev.FileRemovedEvent):
00215         return handle_file_removed(event)
00216 

Here is the call graph for this function:

Here is the caller graph for this function:

Sends an email to users that have subscribed to this event type

Definition at line 129 of file emailnotify.py.

00129 
00130 def handle_file_attached(event):
00131     """Sends an email to users that have subscribed to this event type"""
00132 
00133     names = set()
00134     from_address = event.request.cfg.mail_from
00135     request = event.request
00136     page = Page(request, event.pagename)
00137 
00138     subscribers = page.getSubscribers(request, return_users=1)
00139     notification.filter_subscriber_list(event, subscribers, False)
00140     recipients = []
00141 
00142     for lang in subscribers:
00143         recipients.extend(subscribers[lang])
00144 
00145     attachlink = request.getQualifiedURL(getAttachUrl(event.pagename, event.filename, request))
00146     pagelink = request.getQualifiedURL(page.url(request, {}))
00147 
00148     for lang in subscribers:
00149         emails = []
00150         _ = lambda text: request.getText(text, lang=lang)
00151 
00152         links = _("Attachment link: %(attach)s\n" \
00153                   "Page link: %(page)s\n") % {'attach': attachlink, 'page': pagelink}
00154 
00155         data = notification.attachment_added(request, _, event.pagename, event.filename, event.size)
00156         data['text'] = data['text'] + links
00157 
00158         emails = [usr.email for usr in subscribers[lang]]
00159 
00160         if send_notification(request, from_address, emails, data):
00161             names.update(recipients)
00162 
00163     return notification.Success(names)
00164 

Here is the call graph for this function:

Here is the caller graph for this function:

Sends an email to users that have subscribed to this event type

Definition at line 165 of file emailnotify.py.

00165 
00166 def handle_file_removed(event):
00167     """Sends an email to users that have subscribed to this event type"""
00168 
00169     names = set()
00170     from_address = event.request.cfg.mail_from
00171     request = event.request
00172     page = Page(request, event.pagename)
00173 
00174     subscribers = page.getSubscribers(request, return_users=1)
00175     notification.filter_subscriber_list(event, subscribers, False)
00176     recipients = []
00177 
00178     for lang in subscribers:
00179         recipients.extend(subscribers[lang])
00180 
00181     attachlink = request.getQualifiedURL(getAttachUrl(event.pagename, event.filename, request))
00182     pagelink = request.getQualifiedURL(page.url(request, {}))
00183 
00184     for lang in subscribers:
00185         emails = []
00186         _ = lambda text: request.getText(text, lang=lang)
00187 
00188         links = _("Attachment link: %(attach)s\n" \
00189                   "Page link: %(page)s\n") % {'attach': attachlink, 'page': pagelink}
00190 
00191         data = notification.attachment_removed(request, _, event.pagename, event.filename, event.size)
00192         data['text'] = data['text'] + links
00193 
00194         emails = [usr.email for usr in subscribers[lang]]
00195 
00196         if send_notification(request, from_address, emails, data):
00197             names.update(recipients)
00198 
00199     return notification.Success(names)
00200 

Here is the call graph for this function:

Here is the caller graph for this function:

Send email to all subscribers of given page.

@param event: event to notify about
@rtype: string
@return: message, indicating success or errors.

Definition at line 73 of file emailnotify.py.

00073 
00074 def handle_page_change(event):
00075     """ Send email to all subscribers of given page.
00076 
00077     @param event: event to notify about
00078     @rtype: string
00079     @return: message, indicating success or errors.
00080 
00081     """
00082     comment = event.comment
00083     page = event.page
00084     request = event.request
00085     trivial = isinstance(event, ev.TrivialPageChangedEvent)
00086     subscribers = page.getSubscribers(request, return_users=1)
00087     mail_from = page.cfg.mail_from
00088 
00089     if subscribers:
00090         recipients = set()
00091 
00092         # get a list of old revisions, and append a diff
00093         revisions = page.getRevList()
00094 
00095         # send email to all subscribers
00096         for lang in subscribers:
00097             users = [u for u in subscribers[lang]
00098                      if event.name in u.email_subscribed_events]
00099             emails = [u.email for u in users]
00100             names = [u.name for u in users]
00101             data = prep_page_changed_mail(request, page, comment, lang, revisions, trivial)
00102 
00103             if send_notification(request, mail_from, emails, data):
00104                 recipients.update(names)
00105 
00106         if recipients:
00107             return notification.Success(recipients)
00108 

Here is the call graph for this function:

Here is the caller graph for this function:

Sends an email to super users that have subscribed to this event type

Definition at line 109 of file emailnotify.py.

00109 
00110 def handle_user_created(event):
00111     """Sends an email to super users that have subscribed to this event type"""
00112 
00113     request = event.request
00114     sitename = request.cfg.sitename
00115     from_address = request.cfg.mail_from
00116     event_name = event.name
00117     email = event.user.email or u"NOT SET"
00118     username = event.user.name
00119 
00120     user_ids = getUserList(request)
00121     for usr_id in user_ids:
00122         usr = User(request, id=usr_id)
00123         # Currently send this only to super users
00124         if usr.isSuperUser() and event_name in usr.email_subscribed_events:
00125             _ = lambda text: request.getText(text, lang=usr.language or 'en')
00126             data = notification.user_created_message(request, _, sitename, username, email)
00127             send_notification(request, from_address, [usr.email], data)
00128 

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.events.emailnotify.prep_page_changed_mail (   request,
  page,
  comment,
  email_lang,
  revisions,
  trivial 
)
Prepare information required for email notification about page change

@param page: the modified page instance
@param comment: editor's comment given when saving the page
@param email_lang: language of email
@param revisions: revisions of this page (newest first!)
@param trivial: the change is marked as trivial
@return: dict with email title and body
@rtype: dict

Definition at line 23 of file emailnotify.py.

00023 
00024 def prep_page_changed_mail(request, page, comment, email_lang, revisions, trivial):
00025     """ Prepare information required for email notification about page change
00026 
00027     @param page: the modified page instance
00028     @param comment: editor's comment given when saving the page
00029     @param email_lang: language of email
00030     @param revisions: revisions of this page (newest first!)
00031     @param trivial: the change is marked as trivial
00032     @return: dict with email title and body
00033     @rtype: dict
00034 
00035     """
00036     change = notification.page_change_message("page_changed", request, page, email_lang, comment=comment, revisions=revisions)
00037     _ = lambda text: request.getText(text, lang=email_lang)
00038 
00039     if len(revisions) >= 2:
00040         querystr = {'action': 'diff',
00041                     'rev2': str(revisions[0]),
00042                     'rev1': str(revisions[1])}
00043     else:
00044         querystr = {}
00045 
00046     pagelink = "%(link)s\n\n" % {'link': notification.page_link(request, page, querystr)}
00047 
00048     subject = _('[%(sitename)s] %(trivial)sUpdate of "%(pagename)s" by %(username)s') % {
00049             'trivial': (trivial and _("Trivial ")) or "",
00050             'sitename': page.cfg.sitename or "Wiki",
00051             'pagename': page.page_name,
00052             'username': page.uid_override or user.getUserIdentification(request),
00053         }
00054 
00055     if change.has_key('comment'):
00056         comment = _("Comment:") + "\n" + change['comment'] + "\n\n"
00057     else:
00058         comment = ''
00059 
00060     return {'subject': subject, 'text': change['text'] + pagelink + comment + change['diff']}
00061 

Here is the caller graph for this function:

def MoinMoin.events.emailnotify.send_notification (   request,
  from_address,
  emails,
  data 
)
Send notification email

@param emails: list of email addresses
@return: sendmail result
@rtype int

Definition at line 62 of file emailnotify.py.

00062 
00063 def send_notification(request, from_address, emails, data):
00064     """ Send notification email
00065 
00066     @param emails: list of email addresses
00067     @return: sendmail result
00068     @rtype int
00069 
00070     """
00071     return sendmail.sendmail(request, emails, data['subject'], data['text'], mail_from=from_address)
00072 

Here is the caller graph for this function: