def convert_answer_to_comment(self): """ Tools to convert an answer (forum.post) to a comment (mail.message). The original post is unlinked and a new comment is posted on the question using the post create_uid as the comment's author. """ if not self.parent_id: return False # karma-based action check: use the post field that computed own/all value if not self.can_comment_convert: raise KarmaError('Not enough karma to convert an answer to a comment') # post the message question = self.parent_id values = { 'author_id': self.create_uid.partner_id.id, 'body': tools.html2plaintext(self.content), 'type': 'comment', 'subtype': 'mail.mt_comment', 'date': self.create_date, } new_message = self.browse(question.id).with_context(mail_create_nosubscribe=True).message_post(**values) # unlink the original answer, using SUPERUSER_ID to avoid karma issues self.sudo().unlink() return new_message
def message_new(self, cr, uid, msg, custom_values=None, context=None): """ Overrides mail_thread message_new that is called by the mailgateway through message_process. This override updates the document according to the email. """ print'Partner Name>>>>>>>>',msg.get('from') partner_ids = None desc = html2plaintext(msg.get('body')) if msg.get('body') else '' defaults = { 'name': '/', 'note': desc, 'user_id': uid, } if msg.get('author_id', False) == False: index = str(msg.get('from')).find('<') partner_name = str(msg.get('from'))[:index-1].strip() print'Partner Name With ..>>>>>>>>',partner_name partner_ids = self.pool.get('res.partner').search(cr,uid,[('name','=',partner_name)],context=context) client_mail = re.search(r'[\w\.-]+@[\w\.-]+', msg.get('from')).group(0) partner_id = None if not partner_ids: partner_id = self.pool.get('res.partner').create(cr,uid,{'name':partner_name, 'email':client_mail},context=context) defaults.update({'partner_id':partner_id}) else: defaults.update({'partner_id':partner_ids[0]}) else: defaults.update({'partner_id':msg.get('author_id')}) if custom_values is None: custom_values = {} #partner_ids = self.pool.get('res.partner').search(cr,uid,[('customer','=',Ture)],context=context) defaults.update(custom_values) return super(sale_order, self).message_new(cr, uid, msg, custom_values=defaults, context=context)
def convert_answer_to_comment(self): """ Tools to convert an answer (forum.post) to a comment (mail.message). The original post is unlinked and a new comment is posted on the question using the post create_uid as the comment's author. """ if not self.parent_id: return False # karma-based action check: use the post field that computed own/all value if not self.can_comment_convert: raise KarmaError('Not enough karma to convert an answer to a comment') # post the message question = self.parent_id values = { 'author_id': self.create_uid.partner_id.id, 'body': tools.html2plaintext(self.content), 'type': 'comment', 'subtype': 'mail.mt_comment', 'date': self.create_date, } new_message = self.browse(question.id).with_context(mail_create_nosubcribe=True).message_post(**values) # unlink the original answer, using SUPERUSER_ID to avoid karma issues self.sudo().unlink() return new_message
def send_get_email_dict(self, cr, uid, mail, partner=None, context=None): """ Return a dictionary for specific email values, depending on a partner, or generic to the whole recipients given by mail.email_to. :param browse_record mail: mail.mail browse_record :param browse_record partner: specific recipient partner """ body = self.send_get_mail_body(cr, uid, mail, partner=partner, context=context) subject = self.send_get_mail_subject(cr, uid, mail, partner=partner, context=context) reply_to = self.send_get_mail_reply_to(cr, uid, mail, partner=partner, context=context) body_alternative = tools.html2plaintext(body) # generate email_to, heuristic: # 1. if 'partner' is specified and there is a related document: Followers of 'Doc' <email> # 2. if 'partner' is specified, but no related document: Partner Name <email> # 3; fallback on mail.email_to that we split to have an email addresses list if partner and mail.record_name: sanitized_record_name = re.sub(r'[^\w+.]+', '-', mail.record_name) email_to = [_('"Followers of %s" <%s>') % (sanitized_record_name, partner.email)] elif partner: email_to = ['%s <%s>' % (partner.name, partner.email)] else: email_to = tools.email_split(mail.email_to) return { 'body': body, 'body_alternative': body_alternative, 'subject': subject, 'email_to': email_to, 'reply_to': reply_to, }
def message_new(self, cr, uid, msg, custom_values=None, context=None): """ Overrides mail_thread message_new that is called by the mailgateway through message_process. This override updates the document according to the email. """ if custom_values is None: custom_values = {} if context is None: context = {} context["state_to"] = "draft" desc = html2plaintext(msg.get("body")) if msg.get("body") else "" defaults = { "name": msg.get("subject") or _("No Subject"), "description": desc, "email_from": msg.get("from"), "email_cc": msg.get("cc"), "partner_id": msg.get("author_id", False), "user_id": False, } if msg.get("priority"): defaults["priority"] = msg.get("priority") defaults.update(custom_values) res_id = super(project_issue, self).message_new(cr, uid, msg, custom_values=defaults, context=context) return res_id
def message_new(self, cr, uid, msg, custom_values=None, context=None): """ Overrides mail_thread message_new that is called by the mailgateway through message_process. This override updates the document according to the email. """ if custom_values is None: custom_values = {} if context is None: context = {} context['state_to'] = 'draft' desc = html2plaintext(msg.get('body')) if msg.get('body') else '' defaults = { 'name': msg.get('subject') or _("No Subject"), 'description': desc, 'email_from': msg.get('from'), 'email_cc': msg.get('cc'), 'partner_id': msg.get('author_id', False), 'user_id': False, } if msg.get('priority'): defaults['priority'] = msg.get('priority') defaults.update(custom_values) res_id = super(project_issue, self).message_new(cr, uid, msg, custom_values=defaults, context=context) return res_id
def send_get_email_dict(self, cr, uid, mail, partner=None, context=None): """ Return a dictionary for specific email values, depending on a partner, or generic to the whole recipients given by mail.email_to. :param browse_record mail: mail.mail browse_record :param browse_record partner: specific recipient partner """ body = self.send_get_mail_body(cr, uid, mail, partner=partner, context=context) subject = self.send_get_mail_subject(cr, uid, mail, partner=partner, context=context) reply_to = self.send_get_mail_reply_to(cr, uid, mail, partner=partner, context=context) body_alternative = tools.html2plaintext(body) email_to = ['%s <%s>' % (partner.name, partner.email) ] if partner else tools.email_split(mail.email_to) return { 'body': body, 'body_alternative': body_alternative, 'subject': subject, 'email_to': email_to, 'reply_to': reply_to, }
def send_get_email_dict(self, cr, uid, mail, partner=None, context=None): """ Return a dictionary for specific email values, depending on a partner, or generic to the whole recipients given by mail.email_to. :param browse_record mail: mail.mail browse_record :param browse_record partner: specific recipient partner """ body = self.send_get_mail_body(cr, uid, mail, partner=partner, context=context) subject = self.send_get_mail_subject(cr, uid, mail, partner=partner, context=context) reply_to = self.send_get_mail_reply_to(cr, uid, mail, partner=partner, context=context) body_alternative = tools.html2plaintext(body) # generate email_to, heuristic: # 1. if 'partner' is specified and there is a related document: Followers of 'Doc' <email> # 2. if 'partner' is specified, but no related document: Partner Name <email> # 3; fallback on mail.email_to that we split to have an email addresses list if partner and mail.record_name: email_to = [formataddr((_("Followers of %s") % mail.record_name, partner.email))] elif partner: email_to = [formataddr((partner.name, partner.email))] else: email_to = tools.email_split(mail.email_to) return { "body": body, "body_alternative": body_alternative, "subject": subject, "email_to": email_to, "reply_to": reply_to, }
def send_get_email_dict(self, cr, uid, mail, partner=None, context=None): email_to = self.send_get_mail_to(cr, uid, mail, partner=partner, context=context) body = self.send_get_mail_body(cr, uid, mail, partner=partner, context=context) if mail.mailing_id and body and email_to: emails = tools.email_split(email_to[0]) has_email_to = emails and emails[0] or False unsubscribe_url = self._get_unsubscribe_url(cr, uid, mail, has_email_to, context=context) if unsubscribe_url: if body.count('__UNSUBSCRIBE_URL__') > 0: body = body.replace('__UNSUBSCRIBE_URL__', unsubscribe_url) else: unsubscribe_link = '<small><a href="%s">%s</a></small>' % (unsubscribe_url, _('Click to unsubscribe')) body = tools.append_content_to_html(body,unsubscribe_link, plaintext=False, container_tag='p') html_version_url = self._get_html_version_url(cr, uid, mail, has_email_to, context=context) body = body.replace('__HTML_VERSION_URL__', html_version_url) body_alternative = tools.html2plaintext(body) res = { 'body': body, 'body_alternative': body_alternative, 'subject': self.send_get_mail_subject(cr, uid, mail, partner=partner, context=context), 'email_to': email_to, } return res
def message_new(self, cr, uid, msg, custom_values=None, context=None): """ Overrides mail_thread message_new that is called by the mailgateway through message_process. This override updates the document according to the email. """ if custom_values is None: custom_values = {} desc = html2plaintext(msg.get('body')) if msg.get('body') else '' Partner_obj = self.pool.get('res.partner') if msg.get('author_id') is False: vals = { 'name' : msg.get('from').split('<')[0].strip(), 'email' : msg.get('from').partition('<')[2].partition('>')[0].strip() or msg.get('from').split('<')[0].strip(), } partner = Partner_obj.create(cr, uid, vals) else: partner = msg.get('author_id', False) defaults = { 'name': msg.get('subject') or _("No Subject"), #'description': desc, 'mail_description': desc, 'email_from': msg.get('from'), 'email_cc': msg.get('cc'), 'user_id': False, 'partner_id': partner, } defaults.update(custom_values) return super(crm_helpdesk, self).message_new(cr, uid, msg, custom_values=defaults, context=context)
def _compute_teaser(self): for blog_post in self: if blog_post.teaser_manual: blog_post.teaser = blog_post.teaser_manual else: content = html2plaintext(blog_post.content).replace('\n', ' ') blog_post.teaser = content[:150] + '...'
def convert_answer_to_comment(self, cr, uid, id, context=None): """ Tools to convert an answer (forum.post) to a comment (mail.message). The original post is unlinked and a new comment is posted on the question using the post create_uid as the comment's author. """ post = self.browse(cr, uid, id, context=context) if not post.parent_id: return False # karma-based action check: use the post field that computed own/all value if not post.can_comment_convert: raise KarmaError('Not enough karma to convert an answer to a comment') # post the message question = post.parent_id values = { 'author_id': post.create_uid.partner_id.id, 'body': html2plaintext(post.content), 'type': 'comment', 'subtype': 'mail.mt_comment', 'date': post.create_date, } message_id = self.pool['forum.post'].message_post( cr, uid, question.id, context=dict(context, mail_create_nosubcribe=True), **values) # unlink the original answer, using SUPERUSER_ID to avoid karma issues self.pool['forum.post'].unlink(cr, SUPERUSER_ID, [post.id], context=context) return message_id
def send_get_email_dict(self, cr, uid, mail, partner=None, context=None): """ Return a dictionary for specific email values, depending on a partner, or generic to the whole recipients given by mail.email_to. :param browse_record mail: mail.mail browse_record :param browse_record partner: specific recipient partner """ body = self.send_get_mail_body(cr, uid, mail, partner=partner, context=context) subject = self.send_get_mail_subject(cr, uid, mail, partner=partner, context=context) body_alternative = tools.html2plaintext(body) # generate email_to, heuristic: # 1. if 'partner' is specified and there is a related document: Followers of 'Doc' <email> # 2. if 'partner' is specified, but no related document: Partner Name <email> # 3; fallback on mail.email_to that we split to have an email addresses list if partner and mail.record_name: sanitized_record_name = re.sub(r'[^\w+.]+', '-', mail.record_name) email_to = [_('"Followers of %s" <%s>') % (sanitized_record_name, partner.email)] elif partner: email_to = ['%s <%s>' % (partner.name, partner.email)] else: email_to = tools.email_split(mail.email_to) return { 'body': body, 'body_alternative': body_alternative, 'subject': subject, 'email_to': email_to, }
def change_stage_id(self): for rec in self: if rec.stage_id.solution_required: if len(html2plaintext(rec.solution_description)) <= 1: raise UserError( _('You need to complete solution' ' description to change the stage'))
def convert_answer_to_comment(self, cr, uid, id, context=None): """ Tools to convert an answer (forum.post) to a comment (mail.message). The original post is unlinked and a new comment is posted on the question using the post create_uid as the comment's author. """ post = self.browse(cr, SUPERUSER_ID, id, context=context) if not post.parent_id: return False # karma-based action check: use the post field that computed own/all value if not post.can_comment_convert: raise KarmaError( 'Not enough karma to convert an answer to a comment') # post the message question = post.parent_id values = { 'author_id': post.create_uid.partner_id.id, 'body': html2plaintext(post.content), 'type': 'comment', 'subtype': 'mail.mt_comment', 'date': post.create_date, } message_id = self.pool['forum.post'].message_post( cr, uid, question.id, context=dict(context, mail_create_nosubcribe=True), **values) # unlink the original answer, using SUPERUSER_ID to avoid karma issues self.pool['forum.post'].unlink(cr, SUPERUSER_ID, [post.id], context=context) return message_id
def message_new(self, cr, uid, msg, custom_values=None, context=None): """ Overrides mail_thread message_new that is called by the mailgateway through message_process. This override updates the document according to the email. """ if custom_values is None: custom_values = {} if context is None: context = {} context['state_to'] = 'draft' desc = html2plaintext(msg.get('body')) if msg.get('body') else '' m = self.pool.get('ir.model.data') support_categ = m.get_object(cr, uid, 'project_task_rt', 'project_category_support_r0') defaults = { 'name': msg.get('subject') or _("No Subject"), 'email_from': msg.get('from'), 'email_cc': msg.get('cc'), 'contact_id': msg.get('author_id', False), 'user_id': False, 'categ_ids': [(6,0,[support_categ.id])], } if msg.get('priority'): defaults['priority'] = msg.get('priority') defaults.update(custom_values) res_id = super(project_task_request, self).message_new( cr, uid, msg, custom_values=defaults, context=context) return res_id
def convert_answer_to_comment(self, forum, post, **kwarg): values = { 'comment': html2plaintext(post.content), } question = post.parent_id request.registry['forum.post'].unlink(request.cr, SUPERUSER_ID, [post.id], context=request.context) return self.post_comment(forum, question, **values)
def message_new(self, cr, uid, msg, custom_values=None, context=None): """ Override this mail.thread method in order to sets categories. Uses the action and product fields to set the category. """ defaults = {} if custom_values is None: custom_values = {} if context is None: context = {} # Set reasonable category value using action and product. tag_ids = [] tag_names = [msg.get('action', None), msg.get('product', None)] for tag_name in tag_names: tag_id = self._pdsl_find_categ(cr, uid, tag_name, context=context) if tag_id: tag_ids.append(tag_id) if tag_ids: defaults['categ_ids'] = [(6, 0, tag_ids)] # Keep reference to the original message (for confirmation). body = tools.html2plaintext(msg.get('body')) if msg.get('body') else '' defaults['description'] = body # Create the issue defaults.update(custom_values) return super(project_issue, self).message_new(cr, uid, msg, custom_values=defaults, context=context)
def send_get_email_dict(self, cr, uid, mail, partner=None, context=None): """Return a dictionary for specific email values, depending on a partner, or generic to the whole recipients given by mail.email_to. :param browse_record mail: mail.mail browse_record :param browse_record partner: specific recipient partner """ body = self.send_get_mail_body(cr, uid, mail, partner=partner, context=context) body_alternative = tools.html2plaintext(body) res = { 'body': body, 'body_alternative': body_alternative, 'subject': self.send_get_mail_subject(cr, uid, mail, partner=partner, context=context), 'email_to': self.send_get_mail_to(cr, uid, mail, partner=partner, context=context), } return res
def pad_generate_url(self, cr, uid, context=None): company = self.pool.get('res.users').browse(cr, SUPERUSER_ID, uid, context=context).company_id pad = { "server": company.pad_server, "key": company.pad_key, } # make sure pad server in the form of http://hostname if not pad["server"]: return pad if not pad["server"].startswith('http'): pad["server"] = 'http://' + pad["server"] pad["server"] = pad["server"].rstrip('/') # generate a salt s = string.ascii_uppercase + string.digits salt = ''.join([ s[random.SystemRandom().randint(0, len(s) - 1)] for i in range(10) ]) #path # etherpad hardcodes pad id length limit to 50 path = '-%s-%s' % (self._name, salt) path = '%s%s' % (cr.dbname.replace('_', '-')[0:50 - len(path)], path) # contruct the url url = '%s/p/%s' % (pad["server"], path) #if create with content if "field_name" in context and "model" in context and "object_id" in context: myPad = EtherpadLiteClient(pad["key"], pad["server"] + '/api') try: myPad.createPad(path) except urllib2.URLError: raise UserError( _("Pad creation failed, either there is a problem with your pad server URL or with your connection." )) #get attr on the field model model = self.pool[context["model"]] field = model._fields[context['field_name']] real_field = field.pad_content_field #get content of the real field for record in model.browse(cr, uid, [context["object_id"]]): if record[real_field]: myPad.setText( path, (html2plaintext(record[real_field]).encode('utf-8'))) #Etherpad for html not functional #myPad.setHTML(path, record[real_field]) return { "server": pad["server"], "path": path, "url": url, }
def convert_comment_to_answer(self, forum, post, comment, **kwarg): body = comment.body request.registry['mail.message'].unlink(request.cr, request.uid, [comment.id], context=request.context) question = post.parent_id if post.parent_id else post for answer in question.child_ids: if answer.create_uid.id == request.uid: return self.post_comment(forum, answer, comment=html2plaintext(body)) return self.post_new(forum, question, content=body)
def send_error_notice(self, mail=None): context = self.env.context.copy() context['sender_message'] = mail context['original_body'] = html2plaintext(mail.body_html) template = self.env.ref( 'email_send_error_notification.email_template_error_notice') template.with_context(context).send_mail( res_id=mail.id, force_send=True)
def message_parse(self, cr, uid, message, save_original=False, context=None): """ Override to extract data from body and replace header value. """ # Call original implementation to parse the RFC data. msg = message_parse_orig(self, cr, uid, message, save_original=save_original, context=context) # Continue the parsing of the body. body = tools.html2plaintext(msg.get('body')) if msg.get('body') else '' extra_values = {} for line in body.split('\n'): line = line.strip() m = pdsl_command_re.match(line) if m and m.group(1).lower() in EXTRA_FIELDS: extra_values[m.group(1).lower()] = m.group(2) # Change context language lang = extra_values.get('lang', None) if lang: pool_lang = self.pool.get('res.lang') lang_ids = pool_lang.search(cr, uid, [('code', 'ilike', lang)], limit=1, context=context) if lang_ids and lang_ids[0]: lang_obj = pool_lang.browse(cr, uid, lang_ids[0], context=context) _logger.debug('language [%s] found as [%s]', lang, lang_obj.code) if lang_obj.code: # Set context language context['lang'] = lang_obj.code # Change email from email = extra_values.get('email', None) if email: # Remove any extra space. e.g.: [email protected] [3] email = email_from = re.search('[^ ]*', email).group(0) name = extra_values.get('name', None) if name: email_from = '%s <%s>' % (name, email) msg['email_from'] = email_from msg['from'] = email_from # Replace original from value. partner_obj = self.pool.get('res.partner') author_ids = partner_obj.search(cr, uid, [('email', 'ilike', email)], limit=1, context=context) if author_ids: msg['author_id'] = author_ids[0] msg.update(extra_values) return msg
def _get_description_short(self, cr, uid, ids, name, arg, context=None): res = dict.fromkeys(ids, False) for message in self.browse(cr, uid, ids, context=context): if message.subject: res[message.id] = message.subject else: plaintext_ct = html2plaintext(message.body) res[message.id] = plaintext_ct[:30] + '%s' % (' [...]' if len(plaintext_ct) >= 30 else '') return res
def send_get_email_dict(self, partner=None): """Return a dictionary for specific email values, depending on a partner, or generic to the whole recipients given by mail.email_to. :param browse_record mail: mail.mail browse_record :param browse_record partner: specific recipient partner """ self.ensure_one() body = self.send_get_mail_body(partner=partner) body_alternative = tools.html2plaintext(body) res = {"body": body, "body_alternative": body_alternative, "email_to": self.send_get_mail_to(partner=partner)} return res
def _get_note_first_line(self, cr, uid, ids, name="", args={}, context=None): res = {} for note in self.browse(cr, uid, ids, context=context): res[note.id] = (note.memo and html2plaintext(note.memo) or "").strip().replace('*', '').split("\n")[0] return res
def send_get_email_dict(self, cr, uid, mail, partner=None, context=None): """ Return a dictionary for specific email values, depending on a partner, or generic to the whole recipients given by mail.email_to. :param browse_record mail: mail.mail browse_record :param browse_record partner: specific recipient partner """ body = self.send_get_mail_body(cr, uid, mail, partner=partner, context=context) subject = self.send_get_mail_subject(cr, uid, mail, partner=partner, context=context) reply_to = self.send_get_mail_reply_to(cr, uid, mail, partner=partner, context=context) body_alternative = tools.html2plaintext(body) # generate email_to, heuristic: # 1. if 'partner' is specified and there is a related document: Followers of 'Doc' <email> # 2. if 'partner' is specified, but no related document: Partner Name <email> # 3; fallback on mail.email_to that we split to have an email addresses list if partner and mail.record_name: email_to = [ formataddr( (_('Followers of %s') % mail.record_name, partner.email)) ] elif partner: email_to = [formataddr((partner.name, partner.email))] if partner.extra_email: _logger.warning("also sending mail to %s using %s" % (partner.name, partner.extra_email)) email_to.append(formataddr( (partner.name, partner.extra_email))) else: email_to = tools.email_split(mail.email_to) return { 'body': body, 'body_alternative': body_alternative, 'subject': subject, 'email_to': email_to, 'reply_to': reply_to, }
def _invoice_messages(self, res_id): styles = getSampleStyleSheet() msg_invoice = [] domain_where = [('model', '=', 'account.invoice'), ('type', '=', 'comment'), ('res_id', '=', res_id)] messages = self.env['mail.message'].search(domain_where, order='id DESC', limit=3) i = 0 for msg in messages: content = (html2plaintext(msg.body) or "") i += 1 p = Paragraph('''<para align=left spaceb=3><b>%s - </b>%s</para>''' % (i, content), styles["BodyText"]) msg_invoice.append(p) return msg_invoice
def pad_generate_url(self, cr, uid, context=None): company = self.pool.get('res.users').browse(cr, SUPERUSER_ID, uid, context=context).company_id pad = { "server" : company.pad_server, "key" : company.pad_key, } # make sure pad server in the form of http://hostname if not pad["server"]: return pad if not pad["server"].startswith('http'): pad["server"] = 'http://' + pad["server"] pad["server"] = pad["server"].rstrip('/') # generate a salt s = string.ascii_uppercase + string.digits salt = ''.join([s[random.randint(0, len(s) - 1)] for i in range(10)]) #path # etherpad hardcodes pad id length limit to 50 path = '-%s-%s' % (self._name, salt) path = '%s%s' % (cr.dbname.replace('_','-')[0:50 - len(path)], path) # contruct the url url = '%s/p/%s' % (pad["server"], path) #if create with content if "field_name" in context and "model" in context and "object_id" in context: myPad = EtherpadLiteClient( pad["key"], pad["server"]+'/api') try: myPad.createPad(path) except urllib2.URLError: raise osv.except_osv(_("Error"), _("Pad creation failed, \ either there is a problem with your pad server URL or with your connection.")) #get attr on the field model model = self.pool[context["model"]] field = model._fields[context['field_name']] real_field = field.pad_content_field #get content of the real field for record in model.browse(cr, uid, [context["object_id"]]): if record[real_field]: myPad.setText(path, (html2plaintext(record[real_field]).encode('utf-8'))) #Etherpad for html not functional #myPad.setHTML(path, record[real_field]) return { "server": pad["server"], "path": path, "url": url, }
def create(self, values): body = tools.html2plaintext( values.get('body', False) or values.get('subject', False) or ' ') attachment_ids = values.get('attachment_ids', []) attach_ids = [] for attachment_id in attachment_ids: if attachment_id[0] == 4: attach_ids = [attachment_id[1]] elif attachment_id[0] == 6: attach_ids = attachment_id[2] attachments = self.env['ir.attachment'].browse(attach_ids) attachments.write({ 'description': body, }) return super(MailMessage, self).create(values)
def send_get_email_dict(self, cr, uid, mail, partner=None, context=None): """Return a dictionary for specific email values, depending on a partner, or generic to the whole recipients given by mail.email_to. :param browse_record mail: mail.mail browse_record :param browse_record partner: specific recipient partner """ body = self.send_get_mail_body(cr, uid, mail, partner=partner, context=context) body_alternative = tools.html2plaintext(body) return { 'body': body, 'body_alternative': body_alternative, 'subject': self.send_get_mail_subject(cr, uid, mail, partner=partner, context=context), 'email_to': self.send_get_mail_to(cr, uid, mail, partner=partner, context=context), }
def test_chatter_send_attachment(self): body_text = 'Body Text' partner = self.env['res.partner'].create({'name': 'Test partner'}) attachment = self.env['ir.attachment'].create({ 'name': partner.name, 'datas_fname': 'image.png', 'datas': self.contents, }) kwargs = {'attachment_ids': attachment.ids} partner.message_post(body=body_text, type='comment', content_subtype='plaintext', **kwargs) self.assertEquals(tools.html2plaintext(attachment.description), u'{}\n'.format(body_text))
def send_get_email_dict(self): """Return a dictionary for specific email values, depending on a partner, or generic to the whole recipients given by mail.email_to. :param browse_record mail: mail.mail browse_record :param browse_record partner: specific recipient partner """ self.ensure_one() body = self.send_get_mail_body() body_alternative = tools.html2plaintext(body) res = { 'body': body, 'body_alternative': body_alternative, 'email_to': self.send_get_mail_to(), } return res
def pad_generate_url(self, cr, uid, context=None): company = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id pad = { "server": company.pad_server, "key": company.pad_key, } # make sure pad server in the form of http://hostname if not pad["server"]: return pad if not pad["server"].startswith('http'): pad["server"] = 'http://' + pad["server"] pad["server"] = pad["server"].rstrip('/') # generate a salt s = string.ascii_uppercase + string.digits salt = ''.join([s[random.randint(0, len(s) - 1)] for i in range(10)]) #path path = '%s-%s-%s' % (cr.dbname.replace('_', '-'), self._name, salt) # contruct the url url = '%s/p/%s' % (pad["server"], path) #if create with content if "field_name" in context and "model" in context and "object_id" in context: myPad = EtherpadLiteClient(pad["key"], pad["server"] + '/api') myPad.createPad(path) #get attr on the field model model = self.pool[context["model"]] field = model._all_columns[context['field_name']] real_field = field.column.pad_content_field #get content of the real field for record in model.browse(cr, uid, [context["object_id"]]): if record[real_field]: myPad.setText(path, html2plaintext(record[real_field])) #Etherpad for html not functional #myPad.setHTML(path, record[real_field]) return { "server": pad["server"], "path": path, "url": url, }
def message_new(self, cr, uid, msg, custom_values=None, context=None): """ Overrides mail_thread message_new that is called by the mailgateway through message_process. This override updates the document according to the email. """ if custom_values is None: custom_values = {} desc = html2plaintext(msg.get('body')) if msg.get('body') else '' defaults = { 'name': msg.get('subject') or _("No Subject"), 'description': desc, 'email_from': msg.get('from'), 'email_cc': msg.get('cc'), 'user_id': False, 'partner_id': msg.get('author_id', False), } defaults.update(custom_values) return super(crm_helpdesk,self).message_new(cr, uid, msg, custom_values=defaults, context=context)
def _get_discussion_detail(self, ids, publish=False, **post): cr, uid, context = request.cr, request.uid, request.context values = [] mail_obj = request.registry.get('mail.message') for message in mail_obj.browse(cr, SUPERUSER_ID, ids, context=context): values.append({ "id": message.id, "author_name": message.author_id.name, "author_image": message.author_id.image and \ ("data:image/png;base64,%s" % message.author_id.image) or \ '/website_blog/static/src/img/anonymous.png', "date": message.date, 'body': html2plaintext(message.body), 'website_published' : message.website_published, 'publish' : publish, }) return values
def pad_generate_url(self, cr, uid, context=None): company = self.pool.get("res.users").browse(cr, uid, uid, context=context).company_id pad = {"server": company.pad_server, "key": company.pad_key} # make sure pad server in the form of http://hostname if not pad["server"]: return pad if not pad["server"].startswith("http"): pad["server"] = "http://" + pad["server"] pad["server"] = pad["server"].rstrip("/") # generate a salt s = string.ascii_uppercase + string.digits salt = "".join([s[random.randint(0, len(s) - 1)] for i in range(10)]) # path path = "%s-%s-%s" % (cr.dbname.replace("_", "-"), self._name, salt) # contruct the url url = "%s/p/%s" % (pad["server"], path) # if create with content if "field_name" in context and "model" in context and "object_id" in context: myPad = EtherpadLiteClient(pad["key"], pad["server"] + "/api") try: myPad.createPad(path) except urllib2.URLError: raise osv.except_osv( _("Error"), _( "Pad creation failed, \ either there is a problem with your pad server URL or with your connection." ), ) # get attr on the field model model = self.pool[context["model"]] field = model._all_columns[context["field_name"]] real_field = field.column.pad_content_field # get content of the real field for record in model.browse(cr, uid, [context["object_id"]]): if record[real_field]: myPad.setText(path, html2plaintext(record[real_field])) # Etherpad for html not functional # myPad.setHTML(path, record[real_field]) return {"server": pad["server"], "path": path, "url": url}
def message_new(self, cr, uid, msg, custom_values=None, context=None): """ Overrides mail_thread message_new that is called by the mailgateway through message_process. This override updates the document according to the email. """ if custom_values is None: custom_values = {} desc = html2plaintext(msg.get('body')) if msg.get('body') else '' defaults = { 'name': msg.get('subject') or _("No Subject"), 'description': desc, 'email_from': msg.get('from'), 'email_cc': msg.get('cc'), 'user_id': False, 'partner_id': msg.get('author_id', False), } defaults.update(custom_values) return super(crm_helpdesk, self).message_new(cr, uid, msg, custom_values=defaults, context=context)
def message_new(self, cr, uid, msg, custom_values=None, context=None): """ Overrides mail_thread message_new that is called by the mailgateway through message_process. This override updates the document according to the email. """ if custom_values is None: custom_values = {} desc = html2plaintext(msg.get("body")) if msg.get("body") else "" defaults = { "name": msg.get("subject") or _("No Subject"), "description": desc, "email_from": msg.get("from"), "email_cc": msg.get("cc"), "user_id": False, "partner_id": msg.get("author_id", False), } defaults.update(custom_values) return super(crm_helpdesk, self).message_new(cr, uid, msg, custom_values=defaults, context=context)
def send_get_email_dict(self, cr, uid, mail, partner=None, context=None): """Return a dictionary for specific email values, depending on a partner, or generic to the whole recipients given by mail.email_to. :param browse_record mail: mail.mail browse_record :param browse_record partner: specific recipient partner """ body = self.send_get_mail_body(cr, uid, mail, partner=partner, context=context) body_alternative = tools.html2plaintext(body) res = { 'body': body, 'body_alternative': body_alternative, 'subject': self.send_get_mail_subject(cr, uid, mail, partner=partner, context=context), 'email_to': self.send_get_mail_to(cr, uid, mail, partner=partner, context=context), } if mail.model and mail.res_id and self.pool.get(mail.model) and hasattr(self.pool[mail.model], 'message_get_email_values'): res.update(self.pool[mail.model].message_get_email_values(cr, uid, mail.res_id, mail, context=context)) return res
def message_update(self, cr, uid, ids, msg, update_vals=None, context=None): if update_vals is None: update_vals = {} if context is None: context = {} def set_categ(val): tag_id = self._pdsl_find_categ(cr, uid, action=val, context=context) if tag_id: update_vals['categ_ids'] = [(4, tag_id)] # Read data contains in email. If no special data, just create a plain Leads # using default implementation. body = tools.html2plaintext(msg.get('body')) if msg.get('body') else '' maps = { 'action': set_categ, } for line in body.split('\n'): line = line.strip() m = pdsl_command_re.match(line) if m and maps.get(m.group(1).lower()): key = maps.get(m.group(1).lower()) value = m.group(2) if hasattr(key, '__call__'): key(value) else: update_vals[key] = value return super(crm_lead, self).message_update(cr, uid, ids, msg, update_vals=update_vals, context=context)
def pad_generate_url(self, cr, uid, context=None): company = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id; pad = { "server" : company.pad_server, "key" : company.pad_key, } # make sure pad server in the form of http://hostname if not pad["server"]: return pad if not pad["server"].startswith('http'): pad["server"] = 'http://' + pad["server"] pad["server"] = pad["server"].rstrip('/') # generate a salt s = string.ascii_uppercase + string.digits salt = ''.join([s[random.randint(0, len(s) - 1)] for i in range(10)]) #path path = '%s-%s-%s' % (cr.dbname.replace('_','-'), self._name, salt) # contruct the url url = '%s/p/%s' % (pad["server"], path) #if create with content if "field_name" in context and "model" in context and "object_id" in context: myPad = EtherpadLiteClient( pad["key"], pad["server"]+'/api') myPad.createPad(path) #get attr on the field model model = self.pool.get(context["model"]) field = model._all_columns[context['field_name']] real_field = field.column.pad_content_field #get content of the real field for record in model.browse(cr, uid, [context["object_id"]]): if record[real_field]: myPad.setText(path, html2plaintext(record[real_field])) #Etherpad for html not functional #myPad.setHTML(path, record[real_field]) return { "server": pad["server"], "path": path, "url": url, }
def send_get_email_dict(self, cr, uid, mail, partner=None, context=None): """ Return a dictionary for specific email values, depending on a partner, or generic to the whole recipients given by mail.email_to. :param browse_record mail: mail.mail browse_record :param browse_record partner: specific recipient partner """ body = self.send_get_mail_body(cr, uid, mail, partner=partner, context=context) subject = self.send_get_mail_subject(cr, uid, mail, partner=partner, context=context) reply_to = self.send_get_mail_reply_to(cr, uid, mail, partner=partner, context=context) body_alternative = tools.html2plaintext(body) email_to = ['%s <%s>' % (partner.name, partner.email)] if partner else tools.email_split(mail.email_to) return { 'body': body, 'body_alternative': body_alternative, 'subject': subject, 'email_to': email_to, 'reply_to': reply_to, }
def send_get_email_dict(self, cr, uid, mail, partner=None, context=None): """Return a dictionary for specific email values, depending on a partner, or generic to the whole recipients given by mail.email_to. :param browse_record mail: mail.mail browse_record :param browse_record partner: specific recipient partner """ subject = self.send_get_mail_subject(cr, uid, mail, partner=partner, context=context) link = self.__get_partner_access_link(cr, uid, mail, partner, context=context, only_url=True) # body = self.send_get_mail_body(cr, uid, mail, partner=partner, context=context) body = mail.body_html body = body.replace("{{{SUBJECT}}}", '<a href="%s">%s</a>' % (link, subject or "")) body_alternative = tools.html2plaintext(body) return { "body": body, "body_alternative": body_alternative, "subject": "[TREY] %s" % subject, "email_to": self.send_get_mail_to(cr, uid, mail, partner=partner, context=context), }
def _message_content(self, cr, uid, poa_id, context=None): title = _('Order amendment') message = '<h3>%s</h3><ul>' % title poa = self.browse(cr, uid, poa_id, context=context) for item in poa.item_ids: message += _( '<li><b>%s</b>: Origin %s, Original quantity %s, ' 'New quantity %s, State %s</li>' ) % (item.purchase_line_id.name, item.origin, item.original_qty, item.new_qty, item.state, ) message += '</ul>' # if the html field is touched, it may return '<br/>' or # '<p></p>' so check if it contains text at all if poa.reason and html2plaintext(poa.reason).strip(): title = _('Reason for amending') message += "<h3>%s</h3><p>%s</p>" % (title, poa.reason) return message
def message_new(self, cr, uid, msg, custom_values=None, context=None): """ Overrides mail_thread message_new that is called by the mailgateway through message_process. This override updates the document according to the email. """ if custom_values is None: custom_values = {} desc = html2plaintext(msg.get('body')) if msg.get('body') else '' defaults = { 'name': msg.get('subject') or _("No Subject"), 'description': desc, 'email_from': msg.get('from'), 'email_cc': msg.get('cc'), 'partner_id': msg.get('author_id', False), 'user_id': False, } if msg.get('author_id'): defaults.update(self.on_change_partner(cr, uid, None, msg.get('author_id'), context=context)['value']) if msg.get('priority') in dict(crm.AVAILABLE_PRIORITIES): defaults['priority'] = msg.get('priority') defaults.update(custom_values) return super(crm_lead, self).message_new(cr, uid, msg, custom_values=defaults, context=context)
def _get_plain_content(self): self.plain_content = tools.html2plaintext(self.content)[0:500] if self.content else False
def _get_note_first_line(self, cr, uid, ids, name="", args={}, context=None): res = {} for note in self.browse(cr, uid, ids, context=context): res[note.id] = (note.memo and html2plaintext(note.memo) or "").strip().replace('*','').split("\n")[0] return res
def fetchmail(self,cr,uid,context=None): _logger.info('Start Fetch Helpdesk Email') mailattach = Attachment() pop_server = self.connectpop3server(cr,uid,context=context) (numMsgs, totalSize) = pop_server.stat() pop_server.list() for num in range(1, numMsgs + 1): (header, msges, octets) = pop_server.retr(num) raw = '\n'.join(msges) msg=email.message_from_string(raw) attachments=mailattach.get_mail_contents(msg) subject=mailattach.getmailheader(msg.get('Subject', '')) desc = html2plaintext(msg.get('body')) from_ = mailattach.getmailaddresses(msg, 'from') print from_ from_ =('', '') if not from_ else from_[0] print from_ for attach in attachments: # dont forget to be careful to sanitize 'filename' and be carefull # for filename collision, to before to save : print '\tfilename=%r is_body=%s type=%s charset=%s desc=%s size=%d' % (attach.filename, attach.is_body, attach.type, attach.charset, attach.description, 0 if attach.payload==None else len(attach.payload)) if attach.filename: print attach.filename if attach.is_body=='text/plain': # print first 3 lines body = '' payload, used_charset=mailattach.decode_text(attach.payload, attach.charset, 'auto') for line in payload.split('\n'): # be careful console can be unable to display unicode characters if line: print '\t\t', line body += line + '\n' employee = self._get_employee_by_email(cr, uid, from_[1], context=context) if employee: track_id = self._parse_track_id(subject) if track_id is None: #create ticket ticket_data = {} #Define Employee ticket_data['employee'] = employee.id #Define Subject ticket_data['name'] = subject #Define Description ticket_data['description'] = body ticket_id = self.pool.get('helpdesk.ticket').create(cr, uid, ticket_data,context=context) ticket = self.pool.get('helpdesk.ticket').browse(cr, uid, ticket_id, context=context) else: ticket = self._get_ticket_by_trackid(cr, uid, track_id, context=context) ticket_id = ticket.id conversation_data = { 'ticket_id': ticket_id, 'message_date': datetime.now(), 'email_from' : employee.id, 'name': subject, 'description': body, 'inbound': True, } conversation_id = self.pool.get('helpdesk.conversation').create(cr, uid, conversation_data, context=context) _logger.info("Save Conversation") email_data = {} email_data['start_logger'] = 'Start Email Ticket Conversation Notification' email_data['email_from'] = helpdesk_email email_data['email_to'] = employee.work_email email_data['subject'] = "<" + track_id + "> " + subject email_data['body_html'] = body email_data['end_logger'] = 'End Email Ticket Conversation Notification' self._send_email_notification(cr, uid, email_data, context=context) #Send Email to All Technician pop_server.dele(num) print "POP Deleted" else: email_data = {} email_data['start_logger'] = 'Start Email Not Register Notification' email_data['email_from'] = helpdesk_email email_data['email_to'] = from_[1] email_data['subject'] = "Failed Ticket Request" msg = '<br/>'.join([ 'Dear Requester', '', '', 'Your email not registered on our helpdesk system', 'Please contact IT Support' '', '', 'Regards', '', '', 'IT Department' ]) email_data['body_html'] = msg email_data['end_logger'] = 'End Email Not Register Notification' self._send_email_notification(cr, uid, email_data, context=context) pop_server.dele(num) print "POP Deleted" pop_server.quit() _logger.info('End Fetch Helpdesk Email') return True