'Connect to repository and output useful information for debugging.'

def serverdiagnostics(self, repository, type):

    conn = None
    self._msg(("%s    repository    '%s':    type    '%s'" % (type, repository.name, self.getnicename(repository))))
    try:
        if hasattr(repository, 'gethost'):
            self._msg(('Host:    %s    Port:    %s    SSL:    %s' % (repository.gethost(), repository.getport(), repository.getssl())))
            try:
                conn = repository.imapserver.acquireconnection()
            except OfflineImapError as e:
                self._msg(('Failed    to    connect.    Reason    %s' % e))
            else:
                if ('ID' in conn.capabilities):
                    self._msg('Server    supports    ID    extension.')
                self._msg(('Server    welcome    string:    %s' % str(conn.welcome)))
                self._msg(('Server    capabilities:    %s\n' % str(conn.capabilities)))
                repository.imapserver.releaseconnection(conn)
        if (type != 'Status'):
            folderfilter = repository.getconf('folderfilter', None)
            if folderfilter:
                self._msg(('folderfilter=    %s\n' % folderfilter))
            folderincludes = repository.getconf('folderincludes', None)
            if folderincludes:
                self._msg(('folderincludes=    %s\n' % folderincludes))
            nametrans = repository.getconf('nametrans', None)
            if nametrans:
                self._msg(('nametrans=    %s\n' % nametrans))
            folders = repository.getfolders()
            foldernames = [(f.name, f.getvisiblename(), f.sync_this) for f in folders]
            folders = []
            for (name, visiblename, sync_this) in foldernames:
                syncstr = ('' if sync_this else '    (disabled)')
                if (name == visiblename):
                    folders.append(('%s%s' % (name, syncstr)))
                else:
                    folders.append(('%s    ->    %s%s' % (name, visiblename, syncstr)))
            self._msg(('Folderlist:\n    %s\n' % '\n    '.join(folders)))
    finally:
        if conn:
            repository.imapserver.close()
