'Fetches data from IMAP server.
Arguments:
- uids: message UIDS
- retry_num: number of retries to make
Returns: data obtained by this query.'

def _fetch_from_imap(self, uids, retry_num=1):

    imapobj = self.imapserver.acquireconnection()
    try:
        query = ('(%s)' % '    '.join(self.imap_query))
        fails_left = retry_num
        while fails_left:
            try:
                imapobj.select(self.getfullname(), readonly=True)
                (res_type, data) = imapobj.uid('fetch', uids, query)
                break
            except imapobj.abort as e:
                fails_left -= 1
                if (fails_left <= 0):
                    message = ('%s,    while    fetching    msg    %r    in    folder    %r.    Max    retry    reached    (%d)' % (e, uids, self.name, retry_num))
                    severity = OfflineImapError.ERROR.MESSAGE
                    raise OfflineImapError(message, OfflineImapError.ERROR.MESSAGE)
                self.ui.error(('%s.    While    fetching    msg    %r    in    folder    %r.    Query:    %s    Retrying    (%d/%d)' % (e, uids, self.name, query, (retry_num - fails_left), retry_num)))
                self.imapserver.releaseconnection(imapobj, True)
                imapobj = self.imapserver.acquireconnection()
    finally:
        self.imapserver.releaseconnection(imapobj)
    if (res_type == 'OK'):
        data = [res for res in data if (not isinstance(res, str))]
    if ((data == [None]) or (res_type != 'OK') or (len(data) != 1)):
        severity = OfflineImapError.ERROR.MESSAGE
        reason = ("IMAP    server    '%s'    failed    to    fetch    messages    UID    '%s'.    Server    responded:    %s    %s" % (self.getrepository(), uids, res_type, data))
        if ((data == [None]) or (len(data) < 1)):
            reason = ("IMAP    server    '%s'    does    not    have    a    message    with    UID    '%s'" % (self.getrepository(), uids))
        raise OfflineImapError(reason, severity)
    return data
