def save_attachments_in_doc(self, doc):
		from frappe.utils.file_manager import save_file, MaxFileSizeReachedError
		saved_attachments = []

		for attachment in self.attachments:
			try:
				file_data = save_file(attachment['fname'], attachment['fcontent'],
					doc.doctype, doc.name, is_private=1)
				saved_attachments.append(file_data)

				if attachment['fname'] in self.cid_map:
					self.cid_map[file_data.name] = self.cid_map[attachment['fname']]

			except MaxFileSizeReachedError:
				# WARNING: bypass max file size exception
				pass
			except frappe.DuplicateEntryError:
				# same file attached twice??
				pass

		return saved_attachments
Save email attachments in given document.
dataset/ETHPy150Open frappe/frappe/frappe/email/receive.py/Email.save_attachments_in_doc