You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
2.0 KiB

  1. # -*- coding: utf-8 -*-
  2. from openerp.addons.web import http
  3. from openerp.addons.web.http import request
  4. import werkzeug
  5. import email
  6. import requests
  7. import simplejson
  8. class MailMailgun(http.Controller):
  9. def get_logs(self):
  10. return requests.get(
  11. "https://api.mailgun.net/v3/iledarn.ru/events",
  12. auth=("api", "key-8345fd06eeb8b27a3b1f9a1e025519ad"),
  13. params={"begin" : "Fri, 3 May 2013 09:00:00 -0000",
  14. "ascending" : "yes",
  15. "limit" : 25,
  16. "pretty" : "yes",
  17. "recipient" : "admin@iledarn.ru"
  18. })
  19. @http.route('/mail_mailgun', auth='public', csrf=False)
  20. def incoming_mail(self, **kw):
  21. print '\n\n\n', 'in incoming_mail ', 'kw ', kw, '\n\n\n\n'
  22. res = self.get_logs()
  23. logs = res.text
  24. logs_obj = simplejson.loads(logs)
  25. items = logs_obj.get('items')
  26. print '\n\n\n', 'logs ', logs, '\n\n\n'
  27. print '\n\n\n', 'logs_obj ', logs_obj, '\n\n\n'
  28. counter = 1
  29. for item in items:
  30. mes = 'Item ' + str(counter)
  31. counter = counter + 1
  32. if 'store' in item['routes'][0]['actions'][0]:
  33. print '\n', mes, '\n'
  34. print item
  35. print '\n'
  36. @http.route('/mail_mailgun_mime', auth='public', csrf=False)
  37. def incoming_mail_mime(self, **kw):
  38. print '\n\n\n', 'in incoming_mail_mime ', 'kw ', kw, '\n\n\n\n'
  39. body_mime = kw.get('body-mime')
  40. mail_thread = request.env['mail.thread'].sudo()
  41. # mail_thread_obj = request.env['res.partner'].sudo()
  42. # msg_dict = mail_thread_obj.message_parse(body_mime)
  43. # print '\n\n\n', 'msg_dict ', msg_dict, '\n\n\n'
  44. # msg_id = msg_dict.get('message_id')
  45. # print '\n\n\n', 'msg_id ', msg_id, '\n\n\n'
  46. # mail_thread_obj.message_new(msg_dict)
  47. res_id = mail_thread.message_process(model=False, message=body_mime)
  48. print '\n\n\n', 'res_id ', res_id, '\n\n\n'