fixes issue where previous communication has no attribute _attachments
before it fails, causing the following error:
Traceback (most recent call last):
File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/background_jobs.py", line 99, in execute_job
method(**kwargs)
File "/home/frappe/frappe-bench/apps/frappe/frappe/email/doctype/email_account/email_account.py", line 724, in pull_from_email_account
email_account.receive()
File "/home/frappe/frappe-bench/apps/frappe/frappe/email/doctype/email_account/email_account.py", line 295, in receive
attachments = [d.file_name for d in communication._attachments]
AttributeError: 'Communication' object has no attribute '_attachments'
Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
fixes issue where email_server is unhandled in test
Traceback (most recent call last):
File "/home/chnmy/workspace/frappe/benches/master-bench/apps/frappe/frappe/email/doctype/email_account/test_email_account.py", line 44, in test_unread_notification
self.test_incoming()
File "/home/chnmy/workspace/frappe/benches/master-bench/apps/frappe/frappe/email/doctype/email_account/test_email_account.py", line 35, in test_incoming
email_account.receive(test_mails=test_mails)
File "/home/chnmy/workspace/frappe/benches/master-bench/apps/frappe/frappe/email/doctype/email_account/email_account.py", line 291, in receive
self.handle_bad_emails(email_server, uid, msg, frappe.get_traceback())
UnboundLocalError: local variable 'email_server' referenced before assignment
Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
fixes issue where smtplib fails to encode the mail as ascii
Traceback (most recent call last):
File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 60, in application
response = frappe.api.handle()
File "/home/frappe/frappe-bench/apps/frappe/frappe/api.py", line 55, in handle
return frappe.handler.handle()
File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 22, in handle
data = execute_cmd(cmd)
File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 61, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1042, in call
return fn(*args, **newargs)
File "/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/user/user.py", line 801, in reset_password
user.reset_password(send_email=True)
File "/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/user/user.py", line 234, in reset_password
self.password_reset_mail(link)
File "/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/user/user.py", line 253, in password_reset_mail
"password_reset", {"link": link}, now=True)
File "/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/user/user.py", line 298, in send_login_mail
delayed=(not now) if now!=None else self.flags.delay_emails, retry=3)
File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 476, in sendmail
inline_images=inline_images, header=header, print_letterhead=print_letterhead)
File "/home/frappe/frappe-bench/apps/frappe/frappe/email/queue.py", line 162, in send
print_letterhead=print_letterhead)
File "/home/frappe/frappe-bench/apps/frappe/frappe/email/queue.py", line 185, in add
send_one(email_queue.name, now=True)
File "/home/frappe/frappe-bench/apps/frappe/frappe/email/queue.py", line 475, in send_one
raise e
File "/home/frappe/frappe-bench/apps/frappe/frappe/email/queue.py", line 415, in send_one
smtpserver.sess.sendmail(email.sender, recipient.recipient, message)
File "/usr/lib64/python3.6/smtplib.py", line 855, in sendmail
msg = _fix_eols(msg).encode('ascii')
UnicodeEncodeError: 'ascii' codec can't encode characters in position 335-339: ordinal not in range(128)
Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
mail status wasn't being set when the check was run, so the output for
any() would always be false, and none of the mails would have status set
to sent in the backend. moving the check to a point after setting status
for each email should fix this issue
Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
* fix: Do not encode smtp server
Because it breaks in python 3
* fix: use cstr to change text_type to str
Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
Co-authored-by: Chinmay Pai <chinmaydpai@gmail.com>
chardet requires input to be bytes or bytesarray, but sometimes
frappe.cstr() returns text_type of str without encoding it to utf-8
Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
* start of tests
* rfc compliant emails for frappe.
* fix for deepsource
* fix length of strings.
* fix bug that I'm not sure where it came from?
* codacy and deepsource issues trying to keep them happy
* take a punt in the dark
* fix: use SMTPUTF8 instead of SMTP and other minor fixes
Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
fixes issues with class objects other than str
Traceback (most recent call last):
File "/home/frappe/frappe-bench/apps/frappe/frappe/email/doctype/email_account/email_account.py", line 281, in receive
communication = self.insert_communication(msg, args=args)
File "/home/frappe/frappe-bench/apps/frappe/frappe/email/doctype/email_account/email_account.py", line 338, in insert_communication
email = Email(raw)
File "/home/frappe/frappe-bench/apps/frappe/frappe/email/receive.py", line 372, in __init__
self.parse()
File "/home/frappe/frappe-bench/apps/frappe/frappe/email/receive.py", line 393, in parse
self.process_part(part)
File "/home/frappe/frappe-bench/apps/frappe/frappe/email/receive.py", line 445, in process_part
self.text_content += self.get_payload(part)
File "/home/frappe/frappe-bench/apps/frappe/frappe/email/receive.py", line 489, in get_payload
charset = self.get_charset(part)
File "/home/frappe/frappe-bench/apps/frappe/frappe/email/receive.py", line 484, in get_charset
charset = chardet.detect(frappe.safe_encode(part))['encoding']
File "/home/frappe/frappe-bench/env/lib/python3.6/site-packages/chardet/__init__.py", line 34, in detect
'{0}'.format(type(byte_str)))
TypeError: Expected object of type bytes or bytearray, got: <class 'email.message.Message'>
Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
notifications triggered through hooks have no checks for recipients, if
no recipients exist, sending mails shouldn't be attempted
Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
* chore: remove unused get_limits method
Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>
* chore: remove misleading docstring from email_queue
Signed-off-by: Chinmay D. Pai <chinmaydpai@gmail.com>