'Sends an NZB to SABnzbd via the API.
:param nzb: The NZBSearchResult object to send to SAB'

@staticmethod
def sendNZB(nzb):

    params = {}
    if (sickrage.srCore.srConfig.SAB_USERNAME is not None):
        params[u'ma_username'] = sickrage.srCore.srConfig.SAB_USERNAME
    if (sickrage.srCore.srConfig.SAB_PASSWORD is not None):
        params[u'ma_password'] = sickrage.srCore.srConfig.SAB_PASSWORD
    if (sickrage.srCore.srConfig.SAB_APIKEY is not None):
        params[u'apikey'] = sickrage.srCore.srConfig.SAB_APIKEY
    category = sickrage.srCore.srConfig.SAB_CATEGORY
    if nzb.show.is_anime:
        category = sickrage.srCore.srConfig.SAB_CATEGORY_ANIME
    for curEp in nzb.episodes:
        if ((datetime.date.today() - curEp.airdate) > datetime.timedelta(days=7)):
            category = sickrage.srCore.srConfig.SAB_CATEGORY_BACKLOG
            if nzb.show.is_anime:
                category = sickrage.srCore.srConfig.SAB_CATEGORY_ANIME_BACKLOG
    if (category is not None):
        params[u'cat'] = category
    if (nzb.priority == 1):
        if (sickrage.srCore.srConfig.SAB_FORCED == 1):
            params[u'priority'] = 2
        else:
            params[u'priority'] = 1
    try:
        f = None
        if (nzb.resultType == u'nzb'):
            if (nzb.provider.id == u'newzbin'):
                id = nzb.provider.getIDFromURL(nzb.url)
                if (not id):
                    sickrage.srCore.srLogger.error((u"Unable    to    send    NZB    to    sab,    can't    find    ID    in    URL    " + str(nzb.url)))
                    return False
                params[u'mode'] = u'addid'
                params[u'name'] = id
            else:
                params[u'mode'] = u'addurl'
                params[u'name'] = nzb.url
            url = ((sickrage.srCore.srConfig.SAB_HOST + u'api?') + urllib.urlencode(params))
            sickrage.srCore.srLogger.info(u'Sending    NZB    to    SABnzbd')
            sickrage.srCore.srLogger.debug((u'URL:    ' + url))
            if (nzb.resultType == u'nzb'):
                f = urllib.urlopen(url)
        elif (nzb.resultType == u'nzbdata'):
            params[u'mode'] = u'addfile'
            multiPartParams = {u'nzbfile': ((nzb.name + u'.nzb'), nzb.extraInfo[0])}
            url = ((sickrage.srCore.srConfig.SAB_HOST + u'api?') + urllib.urlencode(params))
            sickrage.srCore.srLogger.info(u'Sending    NZB    to    SABnzbd')
            sickrage.srCore.srLogger.debug((u'URL:    ' + url))
            cookies = cookielib.CookieJar()
            opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookies), MultipartPostHandler.MultipartPostHandler)
            req = urllib2.Request(url, multiPartParams, headers={u'User-Agent': sickrage.srCore.USER_AGENT})
            f = opener.open(req)
    except (EOFError, IOError) as e:
        sickrage.srCore.srLogger.error(u'Unable    to    connect    to    SAB:    {}'.format(e.message))
        return False
    except httplib.InvalidURL as e:
        sickrage.srCore.srLogger.error(u'Invalid    SAB    host,    check    your    config:    {}'.format(e.message))
        return False
    if (f is None):
        sickrage.srCore.srLogger.error(u'No    data    returned    from    SABnzbd,    NZB    not    sent')
        return False
    try:
        result = f.readlines()
    except Exception as e:
        sickrage.srCore.srLogger.error(u'Error    trying    to    get    result    from    SAB,    NZB    not    sent:    {}'.format(e.message))
        return False
    if (len(result) == 0):
        sickrage.srCore.srLogger.error(u'No    data    returned    from    SABnzbd,    NZB    not    sent')
        return False
    sabText = result[0].strip()
    sickrage.srCore.srLogger.debug((u'Result    text    from    SAB:    ' + sabText))
    if (sabText == u'ok'):
        sickrage.srCore.srLogger.debug(u'NZB    sent    to    SAB    successfully')
        return True
    elif (sabText == u'Missing    authentication'):
        sickrage.srCore.srLogger.error(u'Incorrect    username/password    sent    to    SAB,    NZB    not    sent')
        return False
    else:
        sickrage.srCore.srLogger.error((u'Unknown    failure    sending    NZB    to    sab.    Return    text    is:    ' + sabText))
        return False
