account.cpp
来自「Qtopia下的邮件处理程序」· C++ 代码 · 共 946 行 · 第 1/2 页
CPP
946 行
/******************************************************************************** Copyright (C) 2000-2006 TROLLTECH ASA. All rights reserved.**** This file is part of the Phone Edition of the Qtopia Toolkit.**** Licensees holding a valid license agreement from Trolltech or any of its** authorized distributors may use this file in accordance with** the License Agreement provided with the Licensed Software.**** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for** information about Trolltech's Commercial License Agreements.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.********** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "account.h"#include "search.h"#include "email.h"#include <qtimer.h>#include <qsettings.h>//* LIST (\flags) "/" "INBOX" response for each listMailbox::Mailbox(MailAccount *account, QString _flags, QString _delimiter, QString _name) : Folder( FolderTypeMailbox ){ noInferiors = ( _flags.indexOf("Noinferiors", 0, Qt::CaseInsensitive) != -1); noSelect = ( _flags.indexOf("Noselect", 0, Qt::CaseInsensitive) != -1); marked = ( _flags.indexOf("Marked", 0, Qt::CaseInsensitive) != -1); // No tr unMarked = ( _flags.indexOf("Unmarked", 0, Qt::CaseInsensitive) != -1); // No tr _localCopy = false; _syncSetting = Sync_AllMessages; delimiter = _delimiter; this->_name = _name; exists = 0; recent = 0; unseen = 0; oldName = ""; newName = false; byUser = false; deleted = false; _account = account; search = new Search(); search->setFromFolder( _name ); search->setFromAccount( _account->id() ); if(_account->accountType() == MailAccount::IMAP) _displayName = decodeModUTF7(baseName()); else _displayName = _name;}Mailbox::Mailbox(MailAccount *account) : Folder( FolderTypeMailbox ){ noInferiors = false; noSelect = false; marked = false; unMarked = false; _localCopy = false; _syncSetting = Sync_AllMessages; delimiter = "/"; this->_name = ""; exists = 0; recent = 0; unseen = 0; delList.clear(); oldName = ""; newName = false; byUser = false; deleted = false; _account = account; search = new Search(); search->setFromFolder( _name ); search->setFromAccount( _account->id() );}Mailbox::~Mailbox(){ delete search;}QString Mailbox::baseName(){ QStringList list = _name.split(delimiter); return list.last();}QString Mailbox::path(){ QStringList list = _name.split(delimiter); list.erase( list.end() ); QString str = list.join(delimiter); if ( !str.isEmpty() ) str += delimiter; return str;}void Mailbox::changeName(QString n, bool userChange){ if (userChange && !byUser) { if ( _name != path() + n) { if ( oldName.isEmpty() ) oldName = _name; _name = path() + n; } } else { oldName = ""; _name = path() + n; } if(_account && _account->accountType() == MailAccount::IMAP) _displayName = decodeModUTF7(baseName()); else _displayName = _name;}void Mailbox::deleteMsg(QString id){ //add to queue only if message still is on server, or //an identical copy has not been markedas to be deleted if ( serverUidList.contains(id) ) { if ( !delList.contains(id) ) { delList.append(id); } }}void Mailbox::msgDeleted(QString id){ delList.removeAll(id);}void Mailbox::saveSettings(QSettings *config){ config->remove(""); config->setValue("name", _name ); config->setValue("oldname", oldName ); config->setValue("delimiter", delimiter ); config->setValue("uid", uid ); config->setValue("exists", exists); config->setValue("byuser", byUser); config->setValue("deleted", deleted); config->setValue("queuedelete", delList.join(",") ); config->setValue("localcopy", _localCopy); config->setValue("syncsettings", (int) _syncSetting); int pos = 1; for (QStringList::Iterator it = serverUidList.begin(); it != serverUidList.end(); ++it) { config->setValue( QString::number(pos), *it); pos++; } int maxMailSize();}void Mailbox::readSettings(QSettings *config){ _name = config->value("name").toString(); oldName = config->value("oldname").toString(); delimiter = config->value("delimiter").toString(); uid = config->value("uid").toString(); exists = (uint) config->value("exists", 0).toInt(); byUser = config->value("byuser").toBool(); deleted = config->value("deleted").toBool(); delList = config->value("queuedelete").toString().split( "," ); _localCopy = config->value("localcopy", false ).toBool(); _syncSetting = config->value("syncsettings", Sync_AllMessages).toInt(); serverUidList.clear(); QString str; for (int x = 1; x < (exists + 1); x++) { int theUid = config->value( QString::number(x) ).toInt(); str = QString::number(theUid); if ( !str.isEmpty() ) serverUidList.append( str ); } search->setFromFolder( pathName() ); if(_account && _account->accountType() == MailAccount::IMAP) _displayName = decodeModUTF7(baseName()); else _displayName = _name;}void Mailbox::setServerUid(QStringList list){ serverUidList = list; exists = (int) serverUidList.count();}QStringList Mailbox::getServerUid(){ return serverUidList;}bool Mailbox::containsMsg(QString _uid){ if ( (serverUidList.contains(_uid)) ) return true; return false;}QStringList Mailbox::getNewUid(QStringList list){ QStringList newUidList; for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { if ( !serverUidList.contains(*it) ) newUidList.append(*it); } return newUidList;}bool Mailbox::matchesEmail(Email *mail){ return search->matches(mail);}QString Mailbox::fullName(){ return ( _account->accountName() + " - " + _displayName );}//decode modified UTF-7 in imapQString Mailbox::decodeModUTF7(QString in){ QRegExp reg("&[^&-]*-"); int startIndex = 0; int endIndex = 0; startIndex = in.indexOf(reg,endIndex); while(startIndex != -1) { endIndex = startIndex; while(endIndex < in.length() && in[endIndex] != '-') endIndex++; endIndex++; //extract the base64 string from the input string QString mbase64 = in.mid(startIndex,(endIndex - startIndex)); //decode QString unicodeString = decodeModBase64(mbase64); //remove encoding in.remove(startIndex,(endIndex-startIndex)); in.insert(startIndex,unicodeString); endIndex = startIndex + unicodeString.length(); startIndex = in.indexOf(reg,endIndex); } return in;}QString Mailbox::decodeModBase64(QString in){ //remove & - in.remove(0,1); in.remove(in.length()-1,1); if(in.isEmpty()) return "&"; unsigned char c, z; QByteArray buf(in.length(),(char)0); QByteArray out(in.length() * 3 / 4 + 2,(char)0); QString result; //chars to numeric for (int x = 0; x < in.length(); x++) { c = in.toLatin1()[x]; if ( (int) c >= 'A' && (int) c <= 'Z') buf[x] = (int) c - (int) 'A'; if ( (int) c >= 'a' && (int) c <= 'z') buf[x] = (int) c - (int) 'a' + 26; if ( (int) c >= '0' && (int) c <= '9') buf[x] = (int) c - (int) '0' + 52; if (c == '+') buf[x] = 62; if (c == ',') buf[x] = 63; } int i = 0; //in buffer index int j = i; //out buffer index while(i+1 < buf.size()) { out[j] = buf[i] & (0x3F); //mask out top 2 bits out[j] = out[j] << 2; z = buf[i+1] >> 4; out[j] = (out[j] | z); //first byte retrieved i++; j++; if(i+1 >= buf.size()) break; out[j] = buf[i] & (0x0F); //mask out top 4 bits out[j] = out[j] << 4; z = buf[i+1] >> 2; z &= 0x0F; out[j] = (out[j] | z); //second byte retrieved i++; j++; if(i+1 >= buf.size()) break; out[j] = buf[i] & 0x03; //mask out top 6 bits out[j] = out[j] << 6; z = buf[i+1]; out[j] = out[j] | z; //third byte retrieved i+=2; //next byte j++; } //go through the buffer and extract 16 bit unicode //network byte order for(int z = 0; z < out.count(); z+=2) { unsigned short outcode = 0x0000; outcode = out[z]; outcode <<= 8; outcode &= 0xFF00; unsigned short b = 0x0000; b = out[z+1]; b &= 0x00FF; outcode = outcode | b; if(outcode) result += QChar(outcode); } return result;}/* MailAccount */MailAccount::MailAccount() : Folder( FolderTypeAccount ){ _mailPort = 110; _smtpPort = 25;#ifdef SMTPAUTH _smtpAuthentication = Auth_NONE; _smtpEncryption = Encrypt_NONE; _mailEncryption = Encrypt_NONE;#endif _maxMailSize = -1; _checkInterval = -1; _accountType = POP; _synchronize = true; _deleteMail = false; _defaultMailServer = false; _useSig = false; search = new Search(); intervalCheckTimer = new QTimer(); connect( intervalCheckTimer, SIGNAL(timeout()), this, SLOT(checkIntervalTimeout()) ); _unreadCount = 0;}MailAccount::~MailAccount(){ delete search;}/* General */QString MailAccount::accountName(){ return _accountName;}void MailAccount::setAccountName(QString str){ _accountName = str;}QString MailAccount::userName(){ return _userName;}void MailAccount::setUserName(QString str){ _userName = str;}/* SMTP */QString MailAccount::emailAddress(){ return _emailAddress;}void MailAccount::setEmailAddress(QString str){ _emailAddress = str;}void MailAccount::setSmtpServer(QString str){ _smtpServer = str;}QString MailAccount::smtpServer(){ return _smtpServer;}int MailAccount::smtpPort(){ return _smtpPort;}void MailAccount::setSmtpPort(int i){ _smtpPort = i;}#ifdef SMTPAUTHQString MailAccount::smtpUsername() const{ return _smtpUsername;}void MailAccount::setSmtpUsername(const QString& username){ _smtpUsername = username;}QString MailAccount::smtpPassword() const{ return _smtpPassword;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?