Browse Source

added date in pop3 mails

version-14
Rushabh Mehta 12 years ago
parent
commit
2c16f10a62
3 changed files with 19 additions and 16 deletions
  1. +3
    -1
      core/doctype/communication/communication.py
  2. +9
    -9
      webnotes/utils/__init__.py
  3. +7
    -6
      webnotes/utils/email_lib/receive.py

+ 3
- 1
core/doctype/communication/communication.py View File

@@ -41,7 +41,7 @@ def get_customer_supplier(args=None):
def make(doctype=None, name=None, content=None, subject=None, def make(doctype=None, name=None, content=None, subject=None,
sender=None, recipients=None, contact=None, lead=None, sender=None, recipients=None, contact=None, lead=None,
communication_medium="Email", send_email=False, print_html=None, communication_medium="Email", send_email=False, print_html=None,
attachments='[]', send_me_a_copy=False, set_lead=True):
attachments='[]', send_me_a_copy=False, set_lead=True, date=None):
# add to Communication # add to Communication


sent_via = None sent_via = None
@@ -53,6 +53,8 @@ def make(doctype=None, name=None, content=None, subject=None,
d.recipients = recipients d.recipients = recipients
d.lead = lead d.lead = lead
d.contact = contact d.contact = contact
if date:
d.creation = date
if doctype: if doctype:
sent_via = webnotes.get_obj(doctype, name) sent_via = webnotes.get_obj(doctype, name)
d.fields[doctype.replace(" ", "_").lower()] = name d.fields[doctype.replace(" ", "_").lower()] = name


+ 9
- 9
webnotes/utils/__init__.py View File

@@ -186,20 +186,20 @@ def time_diff_in_seconds(string_ed_date, string_st_date):
return (get_datetime(string_ed_date) - get_datetime(string_st_date)).seconds return (get_datetime(string_ed_date) - get_datetime(string_st_date)).seconds


def now_datetime(): def now_datetime():
global user_time_zone
from datetime import datetime from datetime import datetime
from pytz import timezone
# get localtime
return convert_utc_to_user_timezone(datetime.utcnow())

def get_user_time_zone():
global user_time_zone
if not user_time_zone: if not user_time_zone:
user_time_zone = webnotes.conn.get_value('Control Panel', None, 'time_zone') \ user_time_zone = webnotes.conn.get_value('Control Panel', None, 'time_zone') \
or 'Asia/Calcutta' or 'Asia/Calcutta'
return user_time_zone


# convert to UTC
utcnow = timezone('UTC').localize(datetime.utcnow())

# convert to user time zone
return utcnow.astimezone(timezone(user_time_zone))
def convert_utc_to_user_timezone(utc_timestamp):
from pytz import timezone
utcnow = timezone('UTC').localize(utc_timestamp)
return utcnow.astimezone(timezone(get_user_time_zone()))


def now(): def now():
"""return current datetime as yyyy-mm-dd hh:mm:ss""" """return current datetime as yyyy-mm-dd hh:mm:ss"""


+ 7
- 6
webnotes/utils/email_lib/receive.py View File

@@ -21,18 +21,17 @@
# #


from __future__ import unicode_literals from __future__ import unicode_literals
from webnotes.utils import extract_email_id
from webnotes.utils import extract_email_id, convert_utc_to_user_timezone


class IncomingMail: class IncomingMail:
""" """
Single incoming email object. Extracts, text / html and attachments from the email Single incoming email object. Extracts, text / html and attachments from the email
""" """
def __init__(self, content): def __init__(self, content):
"""
Parse the incoming mail content
"""
import email import email
from email.utils import parseaddr
import time
import datetime
import email.utils
self.mail = email.message_from_string(content) self.mail = email.message_from_string(content)
@@ -42,7 +41,9 @@ class IncomingMail:
self.parse() self.parse()
self.set_content_and_type() self.set_content_and_type()
self.from_email = extract_email_id(self.mail["From"]) self.from_email = extract_email_id(self.mail["From"])
self.from_real_name = parseaddr(self.mail["From"])[0]
self.from_real_name = email.utils(self.mail["From"])[0]
utc = email.utils.mktime_tz(email.utils.parsedate_tz(self.mail["Date"]))
self.date = convert_utc_to_user_timezone(utc).strftime('%Y-%m-%d %H:%M:%S')


def parse(self): def parse(self):
for part in self.mail.walk(): for part in self.mail.walk():


Loading…
Cancel
Save