def test_unit__email_address_address__ok__from_rfc_email_address__nominal_case( self): john_address = EmailAddress.from_rfc_email_address( "John Doe <*****@*****.**>") assert john_address.domain == "domainame.ndl" assert john_address.label == "John Doe" assert john_address.email == "*****@*****.**" assert john_address.force_angle_bracket is False assert john_address.address == "John Doe <*****@*****.**>"
def test_unit__email_address_address__ok__from_rfc_email_address__with_label_quotation( self): john_address = EmailAddress.from_rfc_email_address( '"John Doe" <*****@*****.**>') assert john_address.domain == "domainame.ndl" assert john_address.label == "John Doe" assert john_address.email == "*****@*****.**" assert john_address.force_angle_bracket is False assert john_address.address == "John Doe <*****@*****.**>"
def test_unit__email_address_address__ok__from_rfc_email_address__no_label_with_bracket( self): john_address = EmailAddress.from_rfc_email_address( "<*****@*****.**>") assert john_address.domain == "domainame.ndl" assert john_address.label == "" assert john_address.email == "*****@*****.**" assert john_address.force_angle_bracket is False assert john_address.address == "*****@*****.**"
def _notify_receiver( self, emitter: User, workspace: Workspace, upload_permission: UploadPermissionInContext, upload_permission_password_enabled: bool, translator: Translator, ) -> Message: logger.info( self, 'preparing email from user "{}" for the upload permission on workspace "{}" to "{}"' .format(emitter.user_id, workspace.workspace_id, upload_permission.email), ) translated_subject = translator.get_translation( self.config. EMAIL__NOTIFICATION__UPLOAD_PERMISSION_TO_RECEIVER__SUBJECT) subject = translated_subject.format( website_title=self.config.WEBSITE__TITLE, emitter_name=emitter.display_name) from_header = self._get_sender(emitter) to_header = EmailAddress.from_rfc_email_address( upload_permission.email) html_template_file_path = ( self.config. EMAIL__NOTIFICATION__UPLOAD_PERMISSION_TO_RECEIVER__TEMPLATE__HTML) receiver = EmailUser(user_email=upload_permission.email) context = { "emitter": emitter, "workspace": workspace, "upload_permission": upload_permission, "receiver": receiver, "upload_permission_password_enabled": upload_permission_password_enabled, } body_html = self._render_template( mako_template_filepath=html_template_file_path, context=context, translator=translator) message = EmailNotificationMessage( subject=subject, from_header=from_header, to_header=to_header, body_html=body_html, lang=translator.default_lang, ) return message
def _notify_receiver( self, emitter: User, shared_content: ContentInContext, content_share: ContentShareInContext, share_password_enabled: bool, translator: Translator, ) -> Message: logger.info( self, 'preparing email from user "{}" for the share on content "{}" to "{}"' .format(emitter.user_id, shared_content.content_id, content_share.email), ) translated_subject = translator.get_translation( self.config.EMAIL__NOTIFICATION__SHARE_CONTENT_TO_RECEIVER__SUBJECT ) subject = translated_subject.format( website_title=self.config.WEBSITE__TITLE, content_filename=shared_content.filename, emitter_name=emitter.display_name, ) from_header = self._get_sender(emitter) to_header = EmailAddress.from_rfc_email_address(content_share.email) username, address = email.utils.parseaddr(content_share.email) html_template_file_path = ( self.config. EMAIL__NOTIFICATION__SHARE_CONTENT_TO_RECEIVER__TEMPLATE__HTML) receiver = EmailUser(user_email=content_share.email) context = { "emitter": emitter, "shared_content": shared_content, "content_share": content_share, "share_password_enabled": share_password_enabled, "receiver": receiver, } body_html = self._render_template( mako_template_filepath=html_template_file_path, context=context, translator=translator) message = EmailNotificationMessage( subject=subject, from_header=from_header, to_header=to_header, body_html=body_html, lang=translator.default_lang, ) return message