def send_notifications(app, fqname, **kwargs): """ Send mail notifications to subscribers on item change :param app: local proxy app :param fqname: fqname of the changed item :param kwargs: key/value pairs that contain extra information about the item required in order to create a notification """ action = kwargs.get('action') revs = get_item_last_revisions(app, fqname) if action not in [ DESTROY_REV, DESTROY_ALL, ] else [] notification = Notification(app, fqname, revs, **kwargs) try: content_diff = notification.get_content_diff() except Exception: # current user has likely corrupted an item or fixed a corrupted item # if current item is corrupt, another exception will occur in a downstream script content_diff = [u'- ' + _('An error has occurred, the current or prior revision of this item may be corrupt.')] meta_diff = notification.get_meta_diff() u = flaskg.user meta = kwargs.get('meta') if action in [DESTROY_REV, DESTROY_ALL, ] else revs[0].meta._meta subscribers = {subscriber for subscriber in get_subscribers(**meta) if subscriber.itemid != u.itemid} subscribers_locale = {subscriber.locale for subscriber in subscribers} for locale in subscribers_locale: with force_locale(locale): txt_msg, html_msg = notification.render_templates(content_diff, meta_diff) subject = L_('[%(moin_name)s] Update of "%(fqname)s" by %(user_name)s', moin_name=app.cfg.interwikiname, fqname=unicode(fqname), user_name=u.name0) subscribers_emails = [subscriber.email for subscriber in subscribers if subscriber.locale == locale] sendmail(subject, txt_msg, to=subscribers_emails, html=html_msg)
def send_notifications(app, item_name, **kwargs): """ Send mail notifications to subscribers on item change :param app: local proxy app :param item_name: name of the changed item :param kwargs: key/value pairs that contain extra information about the item required in order to create a notification """ action = kwargs.get('action') revs = get_item_last_revisions(app, item_name) if action not in [ DESTROY_REV, DESTROY_ALL, ] else [] notification = Notification(app, item_name, revs, **kwargs) content_diff = notification.get_content_diff() meta_diff = notification.get_meta_diff() u = flaskg.user meta = kwargs.get('meta') if action in [DESTROY_REV, DESTROY_ALL, ] else revs[0].meta._meta subscribers = {subscriber for subscriber in get_subscribers(**meta) if subscriber.itemid != u.itemid} subscribers_locale = {subscriber.locale for subscriber in subscribers} for locale in subscribers_locale: with force_locale(locale): txt_msg, html_msg = notification.render_templates(content_diff, meta_diff) subject = L_('[%(moin_name)s] Update of "%(item_name)s" by %(user_name)s', moin_name=app.cfg.interwikiname, item_name=item_name, user_name=u.name0) subscribers_emails = [subscriber.email for subscriber in subscribers if subscriber.locale == locale] sendmail(subject, txt_msg, to=subscribers_emails, html=html_msg)
def mail_password_recovery(self, cleartext_passwd=None, subject=None, text=None): """ Mail a user who forgot his password a message enabling him to login again. """ if not self.email: return False, "user has no E-Mail address in his profile." token = self.generate_recovery_token() if subject is None: subject = _('[%(sitename)s] Your wiki password recovery link', sitename='%(sitename)s') subject = subject % dict(sitename=self._cfg.sitename or "Wiki") if text is None: link = url_for('frontend.recoverpass', username=self.name0, token=token, _external=True) text = render_template('mail/password_recovery.txt', link=link) mailok, msg = sendmail.sendmail(subject, text, to=[self.email], mail_from=self._cfg.mail_from) return mailok, msg
def mainloop(self): self.init_request() request = self.request from_address = unicode(self.options.from_address or "*****@*****.**") subject = unicode(self.options.subject or "MoinMoin i18n notification") text_template = unicode(sys.stdin.read()) languages = i18n.wikiLanguages() langs = languages.keys() langs.remove('en') # nothing to do for english, so remove it #langs = ['de', ] # for testing if len(text_template) > 10: # do not send mails w/o real content for lang in langs: to_address = languages[lang]['last-translator'] rc = None if to_address and '***vacant***' not in to_address: text = text_template % locals() rc = sendmail(request, [to_address], subject, text, mail_from=from_address) print lang, repr(from_address), repr( to_address), subject, repr(rc)
def mailAccountData(self, cleartext_passwd=None): """ Mail a user who forgot his password a message enabling him to login again. """ from MoinMoin.mail import sendmail token = self.generate_recovery_token() text = _("""\ Somebody has requested to email you a password recovery link. Please use the link below to change your password to a known value: %(link)s If you didn't forget your password, please ignore this email. """, link=url_for('frontend.recoverpass', username=self.name, token=token, _external=True)) subject = _('[%(sitename)s] Your wiki password recovery link', sitename=self._cfg.sitename or "Wiki") mailok, msg = sendmail.sendmail([self.email], subject, text, mail_from=self._cfg.mail_from) return mailok, msg
def send_notification(request, from_address, emails, data): """ Send notification email @param emails: list of email addresses @return: sendmail result @rtype int """ return sendmail.sendmail(request, emails, data['subject'], data['text'], mail_from=from_address)
def send_notifications(app, fqname, **kwargs): """ Send mail notifications to subscribers on item change :param app: local proxy app :param fqname: fqname of the changed item :param kwargs: key/value pairs that contain extra information about the item required in order to create a notification """ action = kwargs.get('action') revs = get_item_last_revisions(app, fqname) if action not in [ DESTROY_REV, DESTROY_ALL, ] else [] notification = Notification(app, fqname, revs, **kwargs) content_diff = notification.get_content_diff() meta_diff = notification.get_meta_diff() u = flaskg.user meta = kwargs.get('meta') if action in [ DESTROY_REV, DESTROY_ALL, ] else revs[0].meta._meta subscribers = { subscriber for subscriber in get_subscribers(**meta) if subscriber.itemid != u.itemid } subscribers_locale = {subscriber.locale for subscriber in subscribers} for locale in subscribers_locale: with force_locale(locale): txt_msg, html_msg = notification.render_templates( content_diff, meta_diff) subject = L_( '[%(moin_name)s] Update of "%(fqname)s" by %(user_name)s', moin_name=app.cfg.interwikiname, fqname=unicode(fqname), user_name=u.name0) subscribers_emails = [ subscriber.email for subscriber in subscribers if subscriber.locale == locale ] sendmail(subject, txt_msg, to=subscribers_emails, html=html_msg)
def mail_email_verification(self): """ Mail a user a link to verify his email address. """ token = self.generate_recovery_token() link = url_for("frontend.verifyemail", username=self.name0, token=token, _external=True) text = render_template("mail/account_verification.txt", link=link) subject = _("[%(sitename)s] Please verify your email address", sitename=self._cfg.sitename or "Wiki") email = self.profile[EMAIL_UNVALIDATED] mailok, msg = sendmail.sendmail(subject, text, to=[email], mail_from=self._cfg.mail_from) return mailok, msg
def mail_email_verification(self): """ Mail a user a link to verify his email address. """ token = self.generate_recovery_token() link = url_for('frontend.verifyemail', username=self.name0, token=token, _external=True) text = render_template('mail/account_verification.txt', link=link) subject = _('[%(sitename)s] Please verify your email address', sitename=self._cfg.sitename or "Wiki") email = self.profile[EMAIL_UNVALIDATED] mailok, msg = sendmail.sendmail(subject, text, to=[email], mail_from=self._cfg.mail_from) return mailok, msg
def notify_subscribers(macro, comment): '''Notify page subscribers''' subscribed_notify = get_cfg(macro, 'comment_subscribed_notify', False) if not subscribed_notify: return request = macro.request _ = macro.request.getText page = Page(request, comment['page']) subscribers = page.getSubscribers(request) mailing_list = [] for lang in subscribers.keys(): for person in subscribers[lang]: mailing_list.append(person) if mailing_list: sendmail.sendmail( request, mailing_list, _('New comment was posted in page %(page)s' % comment), _('New comment was posted in page:\n\nPage: %(page)s\nFrom: %(user_name)s\nMessage:\n\n%(comment)s\n\n--' % comment ))
def mailAccountData(self, cleartext_passwd=None, subject=None, text_intro=None, text_msg=None, text_data=None): """ Mail a user who forgot his password a message enabling him to login again. """ from MoinMoin.mail import sendmail _ = self._request.getText if not self.email: return False, "user has no E-Mail address in his profile." tok = self.generate_recovery_token() if subject is None: subject = _('[%(sitename)s] Your wiki account data') subject = subject % dict(sitename=self._cfg.sitename or "Wiki") if text_intro is None: text_intro = '' if text_msg is None: text_msg = _("""\ Somebody has requested to email you a password recovery token. If you lost your password, please go to the password reset URL below or go to the password recovery page again and enter your username and the recovery token. """) if text_data is None: text_data = _("""\ Login Name: %s Password recovery token: %s Password reset URL: %s?action=recoverpass&name=%s&token=%s """) # note: text_intro is for custom stuff, we do not have i18n for it anyway text = text_intro + '\n' + _(text_msg) + '\n' + _(text_data) % ( self.name, tok, self._request.url, # use full url, including current page url_quote_plus(self.name), tok, ) mailok, msg = sendmail.sendmail(self._request, [self.email], subject, text, mail_from=self._cfg.mail_from) return mailok, msg
def send_notification(request, from_address, emails, data): """ Send notification email @param emails: list of email addresses @return: sendmail result @rtype int """ return sendmail.sendmail(request, emails, data['subject'], data['text'], mail_from=from_address)
def emit(self, record): """ Emit a record. Send the record to the specified addresses """ # the app config is accessible after logging is initialized, so set the # arguments and make the decision to send mail or not here from flask import current_app as app if not app.cfg.email_tracebacks: return global in_email_handler if in_email_handler: return in_email_handler = True toaddrs = self.toaddrs if self.toaddrs else app.cfg.admin_emails log_level = logging.getLevelName(self.level) subject = self.subject if self.subject else u'[{0}][{1}] Log message'.format( app.cfg.sitename, log_level) msg = self.format(record) from MoinMoin.mail.sendmail import sendmail sendmail(subject, msg, to=toaddrs) in_email_handler = False
def emit(self, record): """ Emit a record. Send the record to the specified addresses """ # the app config is accessible after logging is initialized, so set the # arguments and make the decision to send mail or not here from flask import current_app as app if not app.cfg.email_tracebacks: return if self.in_email_handler: return self.in_email_handler = True try: toaddrs = self.toaddrs if self.toaddrs else app.cfg.admin_emails log_level = logging.getLevelName(self.level) subject = self.subject if self.subject else u'[{0}][{1}] Log message'.format( app.cfg.sitename, log_level) msg = self.format(record) from MoinMoin.mail.sendmail import sendmail sendmail(subject, msg, to=toaddrs) finally: self.in_email_handler = False
def mailAccountData(self, cleartext_passwd=None, subject=None, text_intro=None, text_msg=None, text_data=None): """ Mail a user who forgot his password a message enabling him to login again. """ from MoinMoin.mail import sendmail _ = self._request.getText if not self.email: return False, "user has no E-Mail address in his profile." tok = self.generate_recovery_token() if subject is None: subject = _('[%(sitename)s] Your wiki account data') subject = subject % dict(sitename=self._cfg.sitename or "Wiki") if text_intro is None: text_intro = '' if text_msg is None: text_msg = _("""\ Somebody has requested to email you a password recovery token. If you lost your password, please go to the password reset URL below or go to the password recovery page again and enter your username and the recovery token. """) if text_data is None: text_data = _("""\ Login Name: %s Password recovery token: %s Password reset URL: %s?action=recoverpass&name=%s&token=%s """) # note: text_intro is for custom stuff, we do not have i18n for it anyway text = text_intro + '\n' + _(text_msg) + '\n' + _(text_data) % ( self.name, tok, self._request.url, # use full url, including current page url_quote_plus(self.name), tok, ) mailok, msg = sendmail.sendmail(self._request, [self.email], subject, text, mail_from=self._cfg.mail_from) return mailok, msg
def mail_password_recovery(self, cleartext_passwd=None, subject=None, text=None): """ Mail a user who forgot his password a message enabling him to login again. """ if not self.email: return False, "user has no E-Mail address in his profile." token = self.generate_recovery_token() if subject is None: subject = _('[%(sitename)s] Your wiki password recovery link', sitename='%(sitename)s') subject = subject % dict(sitename=self._cfg.sitename or "Wiki") if text is None: link = url_for('frontend.recoverpass', username=self.name0, token=token, _external=True) text = render_template('mail/password_recovery.txt', link=link) mailok, msg = sendmail.sendmail(subject, text, to=[self.email], mail_from=self._cfg.mail_from) return mailok, msg
def mail_email_verification(self): """ Mail a user a link to verify his email address. """ token = self.generate_recovery_token() text = _("""\ Somebody has created an account with this email address. Please use the link below to verify your email address: %(link)s If you didn't create this account, please ignore this email. """, link=url_for('frontend.verifyemail', username=self.name, token=token, _external=True)) subject = _('[%(sitename)s] Please verify your email address', sitename=self._cfg.sitename or "Wiki") mailok, msg = sendmail.sendmail(subject, text, to=[self.email], mail_from=self._cfg.mail_from) return mailok, msg
def mainloop(self): self.init_request() request = self.request from_address = unicode(self.options.from_address or "*****@*****.**") subject = unicode(self.options.subject or "MoinMoin i18n notification") text_template = unicode(sys.stdin.read()) languages = i18n.wikiLanguages() langs = languages.keys() langs.remove('en') # nothing to do for english, so remove it #langs = ['de', ] # for testing if len(text_template) > 10: # do not send mails w/o real content for lang in langs: to_address = languages[lang]['last-translator'] rc = None if to_address and '***vacant***' not in to_address: text = text_template % locals() rc = sendmail(request, [to_address], subject, text, mail_from=from_address) print lang, repr(from_address), repr(to_address), subject, repr(rc)
def mailAccountData(self, cleartext_passwd=None): """ Mail a user who forgot his password a message enabling him to login again. """ from MoinMoin.mail import sendmail from MoinMoin.wikiutil import getLocalizedPage _ = self._request.getText tok = self.generate_recovery_token() text = '\n' + _("""\ Login Name: %s Password recovery token: %s Password reset URL: %s?action=recoverpass&name=%s&token=%s """) % ( self.name, tok, self._request.url_root, url_quote_plus(self.name), tok, ) text = _("""\ Somebody has requested to email you a password recovery token. If you lost your password, please go to the password reset URL below or go to the password recovery page again and enter your username and the recovery token. """) + text subject = _('[%(sitename)s] Your wiki account data', ) % { 'sitename': self._cfg.sitename or "Wiki" } mailok, msg = sendmail.sendmail(self._request, [self.email], subject, text, mail_from=self._cfg.mail_from) return mailok, msg
def mail_password_recovery(self, cleartext_passwd=None): """ Mail a user who forgot his password a message enabling him to login again. """ token = self.generate_recovery_token() text = _("""\ Somebody has requested to email you a password recovery link. Please use the link below to change your password to a known value: %(link)s If you didn't forget your password, please ignore this email. """, link=url_for('frontend.recoverpass', username=self.name, token=token, _external=True)) subject = _('[%(sitename)s] Your wiki password recovery link', sitename=self._cfg.sitename or "Wiki") mailok, msg = sendmail.sendmail(subject, text, to=[self.email], mail_from=self._cfg.mail_from) return mailok, msg
def mailAccountData(self, cleartext_passwd=None): """ Mail a user who forgot his password a message enabling him to login again. """ from MoinMoin.mail import sendmail from MoinMoin.wikiutil import getLocalizedPage _ = self._request.getText tok = self.generate_recovery_token() text = '\n' + _("""\ Login Name: %s Password recovery token: %s Password reset URL: %s?action=recoverpass&name=%s&token=%s """) % ( self.name, tok, self._request.url_root, url_quote_plus(self.name), tok, ) text = _("""\ Somebody has requested to email you a password recovery token. If you lost your password, please go to the password reset URL below or go to the password recovery page again and enter your username and the recovery token. """) + text subject = _('[%(sitename)s] Your wiki account data', ) % {'sitename': self._cfg.sitename or "Wiki"} mailok, msg = sendmail.sendmail(self._request, [self.email], subject, text, mail_from=self._cfg.mail_from) return mailok, msg
def save_comment( self ): _ = self.macro.request.getText if get_input(self.macro, 'do' ) != u'comment_add': # This is not a comment post do nothing return if get_cfg(self.macro, 'comment_recaptcha', False ) and not self.passpartout: import captcha self.captcha = captcha.submit ( get_input(self.macro, 'recaptcha_challenge_field'), get_input(self.macro, 'recaptcha_response_field'), get_cfg(self.macro, 'comment_recaptcha_private_key'), self.macro.request.remote_addr ) self.get_comment() self.errors = self.errors_check() if not self.errors: # Save the comment # Find out where to save the comment: if self.moderate: # This commet will be added to the moderation queue page = Page(self.macro.request, get_cfg(self.macro, 'comment_approval_page', 'CommentsApproval')) comment_dir = page.getPagePath('', check_create=0) else: # The comment will be immediately posted page = Page(self.macro.request,self.page_name) comment_dir = page.getPagePath('comments', check_create=1) # Compose the comment structure and write it now = datetime.now() random_str = ''.join([choice(letters + digits) for i in range(20)]) comment_file = '%s-%s.txt' % (now.strftime("%s"), random_str) file_name = os.path.join(comment_dir, comment_file) comment = self.comment comment['page'] = self.page_name comment['time'] = now if get_cfg(self.macro, 'comment_store_addr', False): comment['remote_addr'] = self.macro.request.remote_addr if self.moderate: self.msg = _('Your comment awaits moderation. Thank you.') else: self.msg = _('Your comment has been posted. Thank you.') write_comment( file_name, comment ) if self.moderate: # If we have defined a list of moderators to notify and this user is # moderated then a message is sent to the moderator list moderators = get_cfg(self.macro, 'comment_moderators', None) if moderators: sendmail.sendmail( self.macro.request, moderators.split(','), _('New comment awaits moderation for page %(page)s' % self.comment ), _('New comment awaits moderation:\n\nPage: %(page)s\nFrom: %(user_name)s\nMessage:\n\n%(comment)s\n\n--' % self.comment )) else: # Send notification to page subscribers if the page notify_subscribers(self.macro, self.comment) # clean up the fields to display self.reset_comment()