Repository: frappe/frappe

Issue:
Bug: Communication Attachments
![image](https://cloud.githubusercontent.com/assets/836785/3014441/04ef3884-df58-11e3-8871-5c83c82421ad.png)

Possible solution:
- fix cur_frm.get_files
- fix how file name is handled for attachment



Discussion:

Resolving patch:
diff --git a/frappe/utils/email_lib/email_body.py b/frappe/utils/email_lib/email_body.py
--- a/frappe/utils/email_lib/email_body.py
+++ b/frappe/utils/email_lib/email_body.py
@@ -4,7 +4,7 @@
 from __future__ import unicode_literals
 import frappe
 from frappe import msgprint, throw, _
-from frappe.utils import scrub_urls
+from frappe.utils import scrub_urls, cstr
 import email.utils
 import inlinestyler.utils
 
@@ -58,7 +58,7 @@ def set_html(self, message, text_content = None, footer=None, print_html=None, f
 			if text_content:
 				self.set_text(text_content)
 			else:
-				self.set_html_as_text(message)
+				self.set_html_as_text(formatted)
 
 		self.set_part_html(formatted)
 		self.html_set = True
@@ -194,14 +194,15 @@ def get_formatted_html(subject, message, footer=None, print_html=None):
 		"content": message,
 		"footer": get_footer(footer),
 		"title": subject,
-		"print_html": print_html
+		"print_html": print_html,
+		"subject": subject
 	})
 
 	# if in a test case, do not inline css
 	if frappe.local.flags.in_test:
 		return rendered_email
 
-	return inlinestyler.utils.inline_css(rendered_email)
+	return cstr(inlinestyler.utils.inline_css(rendered_email))
 
 def get_footer(footer=None):
 	"""append a footer (signature)"""
diff --git a/frappe/utils/file_manager.py b/frappe/utils/file_manager.py
--- a/frappe/utils/file_manager.py
+++ b/frappe/utils/file_manager.py
@@ -148,7 +148,8 @@ def check_max_file_size(content):
 	file_size = len(content)
 
 	if file_size > max_file_size:
-		frappe.msgprint(_("File size exceeded the maximum allowed size"),
+		frappe.msgprint(_("File size exceeded the maximum allowed size of {0} MB").format(
+			max_file_size / 1000000.0),
 			raise_exception=MaxFileSizeReachedError)
 
 	return file_size
diff --git a/frappe/utils/response.py b/frappe/utils/response.py
--- a/frappe/utils/response.py
+++ b/frappe/utils/response.py
@@ -4,7 +4,6 @@
 from __future__ import unicode_literals
 import json
 import datetime
-import gzip, cStringIO
 import mimetypes
 import os
 import frappe
@@ -63,8 +62,7 @@ def as_json():
 		del frappe.local.response['http_status_code']
 
 	response.headers[b"Content-Type"] = b"application/json; charset: utf-8"
-	response = gzip(json.dumps(frappe.local.response, default=json_handler, separators=(',',':')),
-		response=response)
+	response.data = json.dumps(frappe.local.response, default=json_handler, separators=(',',':'))
 	return response
 
 def make_logs():
@@ -80,28 +78,6 @@ def make_logs():
 	if frappe.debug_log and frappe.conf.get("logging") or False:
 		frappe.response['_debug_messages'] = json.dumps(frappe.local.debug_log)
 
-def gzip(data, response):
-	data = data.encode('utf-8')
-	orig_len = len(data)
-	if accept_gzip() and orig_len>512:
-		data = compressBuf(data)
-		response.headers[b"Content-Encoding"] = b"gzip"
-
-	response.headers[b"Content-Length"] = str(len(data))
-	response.data = data
-	return response
-
-def accept_gzip():
-	if "gzip" in frappe.get_request_header("HTTP_ACCEPT_ENCODING", ""):
-		return True
-
-def compressBuf(buf):
-	zbuf = cStringIO.StringIO()
-	zfile = gzip.GzipFile(mode = 'wb',  fileobj = zbuf, compresslevel = 5)
-	zfile.write(buf)
-	zfile.close()
-	return zbuf.getvalue()
-
 def json_handler(obj):
 	"""serialize non-serializable data for json"""
 	# serialize date


Test patch: