<commit_before>from PyQt4 import QtCore, QtGui

import shared
import re
import sys
import inspect
from helper_sql import *
from addresses import decodeAddress
from foldertree import AccountMixin
from pyelliptic.openssl import OpenSSL
from utils import str_broadcast_subscribers
import time

def getSortedAccounts():
    configSections = filter(lambda x: x != 'bitmessagesettings', shared.config.sections())
    configSections.sort(cmp = 
        lambda x,y: cmp(unicode(shared.config.get(x, 'label'), 'utf-8').lower(), unicode(shared.config.get(y, 'label'), 'utf-8').lower())
        )
    return configSections

def getSortedSubscriptions(count = False):
    queryreturn = sqlQuery('SELECT label, address, enabled FROM subscriptions ORDER BY label COLLATE NOCASE ASC')
    ret = {}
    for row in queryreturn:
        label, address, enabled = row
        ret[address] = {}
        ret[address]["inbox"] = {}
        ret[address]["inbox"]['label'] = label
        ret[address]["inbox"]['enabled'] = enabled
        ret[address]["inbox"]['count'] = 0
    if count:
        queryreturn = sqlQuery('''SELECT fromaddress, folder, count(msgid) as cnt
            FROM inbox, subscriptions
            WHERE read = 0 AND subscriptions.address = inbox.fromaddress
            GROUP BY inbox.fromaddress, folder''')
        for row in queryreturn:
            address, folder, cnt = row
            ret[address][folder]['count'] = cnt
    return ret

def accountClass(address):
    if not shared.config.has_section(address):
        if address == str_broadcast_subscribers:
            subscription = BroadcastAccount(address)
            if subscription.type != AccountMixin.BROADCAST:
                return None
        else:
            subscription = SubscriptionAccount(address)
            if subscription.type != AccountMixin.SUBSCRIPTION:
                return None
        return subscription
    try:
        gateway = shared.config.get(address, "gateway")
        for name, cls in inspect.getmembers(sys.modules[__name__], inspect.isclass):
#            obj = g(address)
            if issubclass(cls, GatewayAccount) and cls.gatewayName == gateway:
                return cls(address)
        # general gateway
        return GatewayAccount(address)
    except:
        pass
    # no gateway
    return BMAccount(address)
    
class AccountColor(AccountMixin):
    def __init__(self, address, type = None):
        self.isEnabled = True
        self.address = address
        if type is None:
            if address is None:
                self.type = AccountMixin.ALL
            elif shared.safeConfigGetBoolean(self.address, 'mailinglist'):
                self.type = AccountMixin.MAILINGLIST
            elif shared.safeConfigGetBoolean(self.address, 'chan'):
                self.type = AccountMixin.CHAN
            elif sqlQuery(
                '''select label from subscriptions where address=?''', self.address):
                self.type = AccountMixin.SUBSCRIPTION
            else:
                self.type = AccountMixin.NORMAL
        else:
            self.type = type
        
    
class BMAccount(object):
    def __init__(self, address = None):
        self.address = address
        self.type = 'normal'
        if shared.config.has_section(address):
            if shared.safeConfigGetBoolean(self.address, 'chan'):
                self.type = AccountMixin.CHAN
            elif shared.safeConfigGetBoolean(self.address, 'mailinglist'):
                self.type = AccountMixin.MAILINGLIST<commit_msg>Fix wrong account type initialiser<commit_after>from PyQt4 import QtCore, QtGui

import shared
import re
import sys
import inspect
from helper_sql import *
from addresses import decodeAddress
from foldertree import AccountMixin
from pyelliptic.openssl import OpenSSL
from utils import str_broadcast_subscribers
import time

def getSortedAccounts():
    configSections = filter(lambda x: x != 'bitmessagesettings', shared.config.sections())
    configSections.sort(cmp = 
        lambda x,y: cmp(unicode(shared.config.get(x, 'label'), 'utf-8').lower(), unicode(shared.config.get(y, 'label'), 'utf-8').lower())
        )
    return configSections

def getSortedSubscriptions(count = False):
    queryreturn = sqlQuery('SELECT label, address, enabled FROM subscriptions ORDER BY label COLLATE NOCASE ASC')
    ret = {}
    for row in queryreturn:
        label, address, enabled = row
        ret[address] = {}
        ret[address]["inbox"] = {}
        ret[address]["inbox"]['label'] = label
        ret[address]["inbox"]['enabled'] = enabled
        ret[address]["inbox"]['count'] = 0
    if count:
        queryreturn = sqlQuery('''SELECT fromaddress, folder, count(msgid) as cnt
            FROM inbox, subscriptions
            WHERE read = 0 AND subscriptions.address = inbox.fromaddress
            GROUP BY inbox.fromaddress, folder''')
        for row in queryreturn:
            address, folder, cnt = row
            ret[address][folder]['count'] = cnt
    return ret

def accountClass(address):
    if not shared.config.has_section(address):
        if address == str_broadcast_subscribers:
            subscription = BroadcastAccount(address)
            if subscription.type != AccountMixin.BROADCAST:
                return None
        else:
            subscription = SubscriptionAccount(address)
            if subscription.type != AccountMixin.SUBSCRIPTION:
                return None
        return subscription
    try:
        gateway = shared.config.get(address, "gateway")
        for name, cls in inspect.getmembers(sys.modules[__name__], inspect.isclass):
#            obj = g(address)
            if issubclass(cls, GatewayAccount) and cls.gatewayName == gateway:
                return cls(address)
        # general gateway
        return GatewayAccount(address)
    except:
        pass
    # no gateway
    return BMAccount(address)
    
class AccountColor(AccountMixin):
    def __init__(self, address, type = None):
        self.isEnabled = True
        self.address = address
        if type is None:
            if address is None:
                self.type = AccountMixin.ALL
            elif shared.safeConfigGetBoolean(self.address, 'mailinglist'):
                self.type = AccountMixin.MAILINGLIST
            elif shared.safeConfigGetBoolean(self.address, 'chan'):
                self.type = AccountMixin.CHAN
            elif sqlQuery(
                '''select label from subscriptions where address=?''', self.address):
                self.type = AccountMixin.SUBSCRIPTION
            else:
                self.type = AccountMixin.NORMAL
        else:
            self.type = type
        
    
class BMAccount(object):
    def __init__(self, address = None):
        self.address = address
        self.type = AccountMixin.NORMAL
        if shared.config.has_section(address):
            if shared.safeConfigGetBoolean(self.address, 'chan'):
                self.type = AccountMixin.CHAN
            elif shared.safeConfigGetBoolean(self.address, 'mailinglist'):
                self.type = AccountMixin.MAILINGLIST
{'fraction_non_alphanumeric': 0.09371476888387824, 'fraction_numerical': 0.0014092446448703494, 'mean_word_length': 2.41859344894027, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3598462', 'n_tokens_mistral': 1922, 'n_tokens_neox': 1886, 'n_words': 493}