'Appends communication to parent based on thread ID. Will extract
parent communication and will link the communication to the reference of that
communication. Also set the status of parent transaction to Open or Replied.
If no thread id is found and `append_to` is set for the email account,
it will create a new parent transaction (e.g. Issue)'

def set_thread(self, communication, email):

    parent = None
    parent = self.find_parent_from_in_reply_to(communication, email)
    if ((not parent) and self.append_to):
        self.set_sender_field_and_subject_field()
    if ((not parent) and self.append_to):
        parent = self.find_parent_based_on_subject_and_sender(communication, email)
    if ((not parent) and self.append_to and (self.append_to != u'Communication')):
        parent = self.create_new_parent(communication, email)
    if parent:
        communication.reference_doctype = parent.doctype
        communication.reference_name = parent.name
    isnotification = email.mail.get(u'isnotification')
    if isnotification:
        if (u'notification' in isnotification):
            communication.unread_notification_sent = 1
