def get_email(recipients, sender='', msg='', subject='[No Subject]', text_content = None, footer=None, print_html=None, formatted=None, attachments=None, content=None, reply_to=None, cc=[], bcc=[], email_account=None, expose_recipients=None, inline_images=[], header=None): """ Prepare an email with the following format: - multipart/mixed - multipart/alternative - text/plain - multipart/related - text/html - inline image - attachment """ content = content or msg emailobj = EMail(sender, recipients, subject, reply_to=reply_to, cc=cc, bcc=bcc, email_account=email_account, expose_recipients=expose_recipients) if not content.strip().startswith("<"): content = markdown(content) emailobj.set_html(content, text_content, footer=footer, header=header, print_html=print_html, formatted=formatted, inline_images=inline_images) if isinstance(attachments, dict): attachments = [attachments] for attach in (attachments or []): # cannot attach if no filecontent if attach.get('fcontent') is None: continue emailobj.add_attachment(**attach) return emailobj
def show_attached_email_headers_in_content(self, part): # get the multipart/alternative message try: from html import escape # python 3.x except ImportError: from cgi import escape # python 2.x message = list(part.walk())[1] headers = [] for key in ('From', 'To', 'Subject', 'Date'): value = cstr(message.get(key)) if value: headers.append('{label}: {value}'.format(label=_(key), value=escape(value))) self.text_content += '\n'.join(headers) self.html_content += '<hr>' + '\n'.join('<p>{0}</p>'.format(h) for h in headers) if not message.is_multipart() and message.get_content_type( ) == 'text/plain': # email.parser didn't parse it! text_content = self.get_payload(message) self.text_content += text_content self.html_content += markdown(text_content)
def get_context(self, context): if is_markdown(context.content): context.content = markdown(context.content) context.login_required = True context.category = dataent.get_doc('Help Category', self.category) context.level_class = get_level_class(self.level) context.comment_list = get_comment_list(self.doctype, self.name) context.show_sidebar = True context.sidebar_items = get_sidebar_items() context.parents = self.get_parents(context)
def get_context(self, context): # this is for double precaution. usually it wont reach this code if not published if not cint(self.published): raise Exception("This blog has not been published yet!") # temp fields context.full_name = get_fullname(self.owner) context.updated = global_date_format(self.published_on) if self.blogger: context.blogger_info = dataent.get_doc("Blogger", self.blogger).as_dict() context.description = self.blog_intro or self.content[:140] context.metatags = { "name": self.title, "description": context.description, } if "<!-- markdown -->" in context.content: context.content = markdown(context.content) image = find_first_image(self.content) if image: context.metatags["image"] = image context.comment_list = get_comment_list(self.doctype, self.name) if not context.comment_list: context.comment_text = _('No comments yet') else: if (len(context.comment_list)) == 1: context.comment_text = _('1 comment') else: context.comment_text = _('{0} comments').format( len(context.comment_list)) context.category = dataent.db.get_value("Blog Category", context.doc.blog_category, ["title", "route"], as_dict=1) context.parents = [{ "name": _("Home"), "route": "/" }, { "name": "Blog", "route": "/blog" }, { "label": context.category.title, "route": context.category.route }]
def build_user_docs(self): """Build templates for user docs pages, if missing.""" #user_docs_path = os.path.join(self.docs_path, "user") # license with open(os.path.join(self.app_path, "..", "license.txt"), "r") as license_file: self.app_context["license_text"] = markdown(license_file.read()) html = dataent.render_template("templates/autodoc/license.html", context=self.app_context) with open(os.path.join(self.docs_path, "license.html"), "wb") as license_file: license_file.write(html.encode("utf-8")) # contents shutil.copy( os.path.join( dataent.get_app_path("dataent", "templates", "autodoc", "contents.html")), os.path.join(self.docs_path, "contents.html")) shutil.copy( os.path.join( dataent.get_app_path("dataent", "templates", "autodoc", "contents.py")), os.path.join(self.docs_path, "contents.py")) # install html = dataent.render_template("templates/autodoc/install.md", context=self.app_context) with open(os.path.join(self.docs_path, "install.md"), "w") as f: f.write(html) self.update_index_txt(self.docs_path)