account.cpp

来自「Qtopia下的邮件处理程序」· C++ 代码 · 共 946 行 · 第 1/2 页

CPP
946 行
字号
void MailAccount::setSmtpPassword(const QString& password){    _smtpPassword = password;}MailAccount::AuthType MailAccount::smtpAuthentication() const{    return _smtpAuthentication;}void MailAccount::setSmtpAuthentication(AuthType t){    _smtpAuthentication = t;}MailAccount::EncryptType MailAccount::smtpEncryption() const{    return _smtpEncryption;}void MailAccount::setSmtpEncryption(EncryptType t){    _smtpEncryption = t;}MailAccount::EncryptType MailAccount::mailEncryption() const{    return _mailEncryption;}void MailAccount::setMailEncryption(EncryptType t){    _mailEncryption = t;}#endifbool MailAccount::useSig(){    return _useSig;}void MailAccount::setUseSig(bool b){    _useSig = b;}QString MailAccount::sig(){    return _sig;}void MailAccount::setSig(QString str){    _sig = str;}bool MailAccount::defaultMailServer(){    return _defaultMailServer;}void MailAccount::setDefaultMailServer(bool b){    _defaultMailServer = b;}/* POP/IMAP */QString MailAccount::mailUserName(){    return _mailUserName;}void MailAccount::setMailUserName(QString str){    _mailUserName = str;    search->setFromAccount( id() );}QString MailAccount::mailPassword(){    return _mailPassword;}void MailAccount::setMailPassword(QString str){    _mailPassword = str;}QString MailAccount::mailServer(){    return _mailServer;}void MailAccount::setMailServer(QString str){    _mailServer = str;    search->setFromAccount( id() );}int MailAccount::mailPort(){    return _mailPort;}void MailAccount::setMailPort(int i){    _mailPort = i;}bool MailAccount::canCollectMail(){    if ( accountType() == MailAccount::Synchronized ||	 accountType() == MailAccount::SMS ||	 accountType() == MailAccount::MMS )	return false;    return true;}bool MailAccount::deleteMail(){    return _deleteMail;}void MailAccount::setDeleteMail(bool b){    _deleteMail = b;}int MailAccount::maxMailSize(){    return _maxMailSize;}void MailAccount::setMaxMailSize(int i){    _maxMailSize = i;}int MailAccount::checkInterval(){    return _checkInterval;}void MailAccount::setCheckInterval(int i){    _checkInterval = i;    if ( i == -1)	intervalCheckTimer->stop();    else	intervalCheckTimer->start( i * 1000 * 60 );}void MailAccount::deleteMsg(QString serverId, const QString &boxName){    if ( _accountType == IMAP ) {        Mailbox *box = getMailboxRefByMsgUid( serverId, boxName );        if ( box != NULL)	    box->deleteMsg( serverId );    } else {	if ( !delList.contains(serverId) ) {	    delList.append(serverId);	}    }}void MailAccount::msgDeleted(QString serverId, const QString &boxName ){    if ( _accountType == IMAP ) {	Mailbox *box = getMailboxRefByMsgUid( serverId, boxName );	if ( box != NULL)	    box->msgDeleted( serverId );    } else {	delList.removeAll( serverId );    }}/* POP Only */bool MailAccount::synchronize(){    return _synchronize;}void MailAccount::setSynchronize(bool b){    _synchronize = b;}// set uidllist belonging to this accountvoid MailAccount::setUidlList(QStringList in){    uidList = in;    QSettings accountconf("Trolltech","qtmail_account");    accountconf.beginGroup( id() );    accountconf.remove("");    accountconf.setValue("idcount", (int) uidList.count() );    int pos = 1;    for (QStringList::Iterator it = uidList.begin();        it != uidList.end(); ++it) {        accountconf.setValue( QString::number(pos), *it);        pos++;    }    accountconf.endGroup();}// get uidllist belonging to this accountQStringList MailAccount::getUidlList(){    return uidList;}/* IMAP Only */Mailbox* MailAccount::getMailboxRef(QString name){    QListIterator<Mailbox*> it(mailboxes);    while ( it.hasNext() ) {	Mailbox *box = it.next();        if ( box->pathName() == name )	    return box;	if ( box->nameChanged() == name)	    return box;    }    return NULL;}Mailbox* MailAccount::getMailboxRefByMsgUid(QString uid, const QString &boxName ){    qDebug(("searching for mail with uid " + QString(*uid.data())).toLatin1());    QListIterator<Mailbox*> it(mailboxes);    while ( it.hasNext() ) {	Mailbox *box = it.next();	if ( box->pathName() == boxName && box->containsMsg(uid) ) {	    qDebug(("found in box " + QString(*box->pathName().data())).toLatin1());	    return box;	}    }            return NULL;}void MailAccount::removeBox(Mailbox *box){    QSettings accountconf("Trolltech","qtmail_account");    for (uint x = 0; x < (uint)mailboxes.count(); x++) {	accountconf.beginGroup( id() + "_" + QString::number(x) );	accountconf.remove("");	accountconf.endGroup();    }    mailboxes.removeAll(box);}/* General */QString MailAccount::id(){    return ( _mailUserName + "@" + _mailServer);}bool MailAccount::hasSettings() const{    switch( accountType() ) {	case MailAccount::SMS:	    return false;	default:	    return true;    }}#ifdef QTOPIA4_TODOstatic QString encipher(const QString& plain){    // mainly, we make it long    QString cipher;    int mix=28730492;    for (int i=0; i<(int)plain.length(); i++) {	int u = plain[i].unicode();	int c = u ^ mix;	QString x = QString::number(c,36);    	cipher.append(QChar('a'+x.length()));	cipher.append(x);	mix *= u;    }    return cipher;}static QString decipher(const QString& cipher){    QString plain;    int mix=28730492;    for (int i=0; i<(int)cipher.length();) {	int l = cipher[i].unicode()-'a';	QString x = cipher.mid(i+1,l); i+=l+1;	int u = x.toInt(0,36) ^ mix;	plain.append(QChar(u));	mix *= u;    }    return plain;}#endifvoid MailAccount::saveSettings(QSettings *conf){    conf->remove("");    conf->setValue("accountname", _accountName );    conf->setValue("name", _userName );    conf->setValue("email", _emailAddress );    conf->setValue("mailuser", _mailUserName );    conf->setValue("mailpassword", _mailPassword); //TODO fix encipher    conf->setValue("mailserver", _mailServer );    conf->setValue("mailport", _mailPort);    conf->setValue("type", _accountType );    conf->setValue("basefolder", _baseFolder);    conf->setValue("smtpserver", _smtpServer );    conf->setValue("smtpport", _smtpPort);#ifdef SMTPAUTH    conf->setValue("smtpUsername",_smtpUsername);    conf->setValue("smtpPassword",_smtpPassword);    conf->setValue("smtpAuthentication",_smtpAuthentication);    conf->setValue("smtpEncryption",_smtpEncryption);    conf->setValue("mailEncryption",_mailEncryption);#endif    conf->setValue("usesig", _useSig);    conf->setValue("maxmailsize", _maxMailSize);    conf->setValue("checkinterval", _checkInterval);    conf->setValue("defaultmailserver", _defaultMailServer);    QString file = QString(getenv("HOME")) + "/Applications/qtmail/sig_" + _mailUserName + "_" + _mailServer;    QFile f(file);    if ( f.open(QIODevice::WriteOnly) ) {    // file opened successfully        QTextStream t( &f );        // use a text stream        t << _sig;        f.close();    }    conf->setValue("synchronize", _synchronize);    conf->setValue("deletemail", _deleteMail);    conf->setValue("networkConfig", _networkCfg);    conf->setValue("autoDownload", _autoDL);    if ( _accountType == IMAP ) {        int count = 0;        conf->setValue("mailboxes", (int) mailboxes.count() );	QListIterator<Mailbox*> it(mailboxes);	while ( it.hasNext() ) {	    Mailbox *box = it.next();    	    conf->beginGroup( id() + "_" + QString::number(count) );    	    box->saveSettings(conf);    	    count++;    	    conf->endGroup();	}    } else {        conf->setValue("queuedelete", delList.join(",!;") );    }}void MailAccount::readSettings(QSettings *conf){    _accountName = conf->value("accountname").toString();    _userName = conf->value("name").toString();    _emailAddress = conf->value("email").toString();    _mailUserName = conf->value("mailuser").toString();    _mailPassword = conf->value("mailpassword").toString(); //TODO fix decipher    _mailServer = conf->value("mailserver").toString();    _mailPort = conf->value("mailport", 110).toInt();    _accountType = (AccountType) conf->value("type", POP ).toInt();    _baseFolder = conf->value("basefolder").toString();    _useSig = conf->value("usesig").toBool();    _maxMailSize = conf->value("maxmailsize", 100*1024).toInt();    setCheckInterval( conf->value("checkinterval", -1).toInt() );    // write signature to a file (to resolve problem with config.h)    QString file = QString(getenv("HOME")) + "/Applications/qtmail/sig_" + _mailUserName + "_" + _mailServer;    QFile f(file);    if ( f.open(QIODevice::ReadOnly) ) {    // file opened successfully        QTextStream t( &f );        // use a text stream        _sig = t.readAll();        f.close();    }    _smtpServer = conf->value("smtpserver").toString();    _smtpPort = conf->value("smtpport", 25).toInt();#ifdef SMTPAUTH    _smtpUsername = conf->value("smtpUsername").toString();    _smtpPassword = conf->value("smtpPassword").toString();        int index = conf->value("smtpAuthentication",0).toInt();    _smtpAuthentication = static_cast<AuthType>(index);    index = conf->value("smtpEncryption",0).toInt();    _smtpEncryption = static_cast<EncryptType>(index);    index = conf->value("mailEncryption",0).toInt();    _mailEncryption = static_cast<EncryptType>(index);#endif    _defaultMailServer = conf->value("defaultmailserver", Qt::CaseInsensitive).toBool();    _synchronize = conf->value("synchronize").toBool();    _deleteMail = conf->value("deletemail").toBool();        _networkCfg = conf->value("networkConfig").toString();    _autoDL = conf->value("autoDownload").toBool();    if ( _accountType == IMAP ) {        uint count = conf->value("mailboxes", 0).toInt();        Mailbox *box;        for (uint x = 0; x < count; x++) {	    conf->beginGroup( id() + "_" + QString::number(x) );	    box = new Mailbox( this );	    box->readSettings(conf);	    mailboxes.append(box);	    conf->endGroup();        }    } else {        QString queueDelete = conf->value("queuedelete").toString();        if(!queueDelete.isEmpty())            delList = queueDelete.split(",!;");        conf->endGroup();        conf->beginGroup( id() );	int count = conf->value("idcount", 0).toInt();	uidList.clear();	for (int x = 1; x < (count + 1); x++) {	    uidList.append( conf->value( QString::number(x) ).toString() );	}	conf->endGroup();    }    search->setFromAccount( id() );}bool MailAccount::matchesEmail(Email *mail){    return search->matches(mail);}void MailAccount::checkIntervalTimeout(){    emit intervalCheck( this );}int MailAccount::unreadCount(){    return _unreadCount;}void MailAccount::setUnreadCount( int count ){    _unreadCount = count;}QString MailAccount::networkConfig() const{    if (_networkCfg.isEmpty()) {        QSettings dfltConfig("Trolltech", "Network");        dfltConfig.beginGroup("WAP");        return dfltConfig.value("DefaultAccount").toString();    }    return _networkCfg;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?