'Save email attachments in given document.'

def save_attachments_in_doc(self, doc):

    saved_attachments = []
    for attachment in self.attachments:
        try:
            file_data = save_file(attachment[u'fname'], attachment[u'fcontent'], doc.doctype, doc.name, is_private=1)
            saved_attachments.append(file_data)
            if (attachment[u'fname'] in self.cid_map):
                self.cid_map[file_data.name] = self.cid_map[attachment[u'fname']]
        except MaxFileSizeReachedError:
            pass
        except frappe.DuplicateEntryError:
            pass
    return saved_attachments
