⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 emailclient.cpp

📁 Qtopia下的邮件处理程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    QListIterator<Email> it = mailboxList->mailbox("inbox")->entryIterator();    for ( ; it.current(); ++it) {        EmailListItem *item = (EmailListItem *)it.current();        if ( !it.current()->mail()->read() ) {            allread = false;            break;	    }	}	if ( allread ) {	    QCopEnvelope e( "QPE/TaskBar", "setLed(int,bool)" );	    e << LED_MAIL << false;	}#endif}void EmailClient::mailFromDisk(Email *mail, const QString &mailbox){    updateQuery( mail, mailbox );    updateFolderCount( mailbox );}void EmailClient::readMail(){    QTime s;    s.start();    mailboxList->openMailboxes();    QStringList mboxList = mailboxList->mailboxes();    for (QStringList::Iterator it = mboxList.begin(); it != mboxList.end(); ++it) {	updateFolderCount( *it, true );    }//    qDebug("opened mailboxes, time elapsed %d", s.elapsed() );}void EmailClient::accessError(EmailFolderList *box){    QString mailbox = "mailbox"; // No tr    if ( box )	mailbox = mailboxTrName( box->mailbox() );    QString msg = tr("<qt>Cannot access %1. Either there is insufficient space, or another program is accessing the mailbox.</qt>").arg(mailbox);    QMessageBox::critical( 0, tr("Unable to save mail"), msg );}void EmailClient::readSettings(){    int y;    QSettings mailconf("Trolltech","qtmail");    mailconf.beginGroup("qtmailglobal");    folderView->readQueries("qtmailglobal", &mailconf);    if (( y = mailconf.value("mailidcount", -1).toInt()) != -1) {	mailIdCount = y;    }    int page = mailconf.value( "currentpage", 0).toInt();    if (page != -1 && mailboxView) {	setCurrentMailboxWidget( page );	if ( page == 0 )	    folderView->setFocus();	else	    messageView()->setFocus();    }    mailconf.endGroup();    mailconf.beginGroup("settings");    QFont font;    if ( mailconf.value("font").toString() == "large") {	font.setPointSize( font.pointSize() + 4 );	// 4 larger than default	folderView->setFont( font );    } else {	folderView->setFont( font );    }    int val = mailconf.value("interval", -1 ).toInt();    if ( val == -1 ) {	fetchTimer.stop();    } else {	fetchTimer.start( val * 60 * 1000);    }    mailconf.endGroup();}bool EmailClient::saveSettings(){    QSettings mailconf("Trolltech","qtmail");    mailconf.beginGroup("qtmailglobal");    mailconf.remove("");    mailconf.setValue("mailidcount", mailIdCount);    folderView->saveQueries("qtmailglobal", &mailconf);    mailconf.endGroup();    mailconf.beginGroup("qtmailglobal");    if ( mailboxView )	mailconf.setValue( "currentpage", currentMailboxWidgetId() );    messageView()->writeConfig( &mailconf );    EmailListItem *item = (EmailListItem *) messageView()->currentItem();    if ( item ) {	QUuid id;	Email *mail = item->mail();	if ( mail )	    id = mail->uuid();		mailconf.setValue("currentmail", id.toString() );    }    mailconf.endGroup();     return true;}void EmailClient::selectAccount(int id){    if ( queuedAccountIds.contains( id ) )	return;    if ( receiving ) {	queuedAccountIds.append( id );	checkAccountTimer.start( 1 * 60 * 1000 );	return;    }	    if (accountList->count() > 0) {	accountIdCount = id;	mailAccount = accountList->at(id);	allAccounts = false;        getNewMail();    }}void EmailClient::selectAccount(QAction* action){    if (actionMap.contains(action))	selectAccount(actionMap[action]);}void EmailClient::selectAccountTimeout(){    if ( receiving )	return;    if ( queuedAccountIds.isEmpty() ) {	checkAccountTimer.stop();	return;    }    int accountId = queuedAccountIds.first();    queuedAccountIds.erase( queuedAccountIds.begin() );    selectAccount( accountId );}void EmailClient::editAccount(int id){#ifndef QTOPIA_PHONE	// we use a settings dialog    MailAccount *newAccount;    if (id == newAccountId) {		//new account	newAccount = new MailAccount;	newAccount->setUserName( accountList->getUserName() );    } else {	newAccount = accountList->at(id);    }    QDialog *editAccountView;    EditAccount *e = new EditAccount(this, "create-new-account");    e->(newAccount, id == newAccountId);    editAccountView = (QDialog *)e;#ifdef QTOPIA_DESKTOP    int ret = editAccountView->exec();#else    int ret = QtopiaApplication::execDialog(editAccountView);#endif    delete editAccountView;    switch ( ret ) {	case QDialog::Accepted:	    if (id == newAccountId) {		accountList->append(newAccount);	    }		    if ( newAccount->defaultMailServer() ) {		if ( accountList->defaultMailServerCount() > 1 ) {		    accountList->setDefaultMailServer( newAccount );				    QMessageBox::warning(qApp->activeWindow(),			tr("New default account"),			tr("<qt>Your previous default mail account has been unchecked</qt>"),			tr("OK"));		}	    }		    QTimer::singleShot(0, this, SLOT( updateAccounts() ) );	    folderView->updateAccountFolder( newAccount );	    accountList->saveAccounts();	    break;	case 2:	    deleteAccount(id);	    break;    }#else    Q_UNUSED( id );#endif}void EmailClient::editAccount(QAction* action){    if (actionMap.contains(action))	editAccount(actionMap[action]);}void EmailClient::deleteAccount(int id){#ifndef QTOPIA_PHONE    MailAccount *newAccount;    newAccount = accountList->at(id);    if (newAccount) {	QString message = tr("<qt>Delete account: %1</qt>").arg(newAccount->accountName());	switch( QMessageBox::warning( this, appTitle, message,	    tr("Yes"), tr("No"), 0,	0, 1 ) ) {	    case 0:	    {		folderView->deleteAccountFolder( accountList->at(id) );		accountList->remove(id);		QTimer::singleShot(0, this, SLOT( updateAccounts() ) );		accountList->saveAccounts();		break;	    }	    case 1: break;	}    }#else    Q_UNUSED( id );#endif}/*  Important:  If this method is called directly/indirectly from    either configure or selectAccountMenu you will get a failure    when mousemove/release/click events are tried being passed to    invalid qmenudataitems. (invalid because this procedure clears them)    Use QTimer:singleshot to dump the call after the mousevents*/void EmailClient::updateAccounts(){    queuedAccountIds.clear();    newAccountId = -1;#ifdef QTOPIA_PHONE//     sendMailButton->setVisible(false);    getMailButton->setVisible(false);    if ( emailHandler ) {	// Enable send mail account if smtp account exists// 	sendMailButton->setVisible( accountList->getSmtpRef() );	QListIterator<MailAccount*> it = accountList->accountIterator();	while ( it.hasNext() ) {	    MailAccount *account = it.next();	    if ( account->accountType() == MailAccount::SMS ) {		emailHandler->setSmsAccount( account );#ifndef QTOPIA_NO_MMS	    } else if ( account->accountType() == MailAccount::MMS ) {		emailHandler->setMmsAccount( account );#endif	    } else if ( account->accountType() < MailAccount::SMS ) {		// Enable send mail account if		// POP, IMAP, or Synchronized account exists		getMailButton->setVisible(true);	    }	}	        }#else    //rebuild menus, clear all first    configure->clear();    selectAccountMenu->clear();    QMapIterator<QAction*, int> i(actionMap);    while ( i.hasNext() ) {        i.next();	delete i.key();    }    actionMap.clear();    QAction *action = configure->addAction( QIcon(":icon/new"), tr("New Account") );    actionMap.insert( action, newAccountId );    configure->addSeparator();    int idCount = 0;    QListIterator<MailAccount*> it = accountList->accountIterator();    while ( it.hasNext() ) {	QString accountName = it.next()->accountName();	action = configure->addAction( accountName + "..." );	actionMap.insert( action, idCount );	if ( it.peekPrevious()->accountType() != MailAccount::Synchronized ) {	    action = selectAccountMenu->addAction( accountName );	    actionMap.insert( action, idCount );	}	        idCount++;    }#endif    // accounts has been changed, update writemailwidget if it's created    if ( mWriteMail )	mWriteMail->setAccountList( accountList );}void EmailClient::messageChanged(){    if (!messageView()->singleColumnMode())	return;    if ( currentMailboxWidgetId() != messageId )	return;        EmailListItem *item = (EmailListItem*)messageView()->currentItem();    if (item) {	QString statusString = EmailListItem::dateToString( item->mail()->dateTime() );	setStatusText( statusString );    }}/*  handles two primary cases.  When a mail being deleted from inbox/outbox view	it is transferred to trash, and if from trash it is expunged  */bool EmailClient::deleteMail(EmailListItem *mailItem){    Email *mail = mailItem->mail();    Folder *folder = folderView->currentFolder();    if ( folder == NULL ) {	qWarning("No folder selected, cannot delete mail");	return false;    }    //if the client has "deleteImmediately" set, then do so now.    MailAccount *account = accountList->getAccountById( mail->fromAccount() );    Client *client = (account ? emailHandler->clientFromAccount(account) : 0);    if ( client && client->hasDeleteImmediately() ) {	client->deleteImmediately( mail->serverUid() );    }    // Deleting an unread mail resets the new mail count    if (client && !mail->status(EFlag_Read))        client->resetNewMailCount();    //only request confirmation when expunging the mail from trash    if ( folder->folderType() == FolderTypeSystem && folder->mailbox() == TrashString )  {	// Add it to queue of mails to be deleted from server	if ( mail->status(EFlag_Incoming) ) {	    MailAccount *account = accountList->getAccountById( mail->fromAccount() );	    if ( account != NULL ) {         if ( account->deleteMail() ){		    account->deleteMsg( mail->serverUid(), mail->fromMailbox() );                }	    }	}#ifndef QTOPIA_NO_MMS        deleteDrmAttachments( *mail );#endif	mailboxList->mailbox(TrashString)->removeMail( mail->uuid(), true );	return true;    }    //if mail is in queue for download, remove it from queue if possible    if ( folder->mailbox() == InboxString )  {        if ( (receiving) && (mail->fromAccount() == mailAccount->id() ) ) {	    if ( !mail->status(EFlag_Downloaded) )		mailDownloadList.remove( mail->serverUid() );	}    }    moveMailToFolder( mailItem->mail(), mailboxList->mailbox( folder->mailbox() ), mailboxList->mailbox(TrashString) );    return true;}/*  Be careful using routines similar to this one.  As soon as a corresponding	email entry is removed, the mail cannot be swapped into memory */bool EmailClient::moveMailToFolder(Email *mail, EmailFolderList *source, EmailFolderList *target){    if ( source == target )	return false;    // Automatic swapping currently not working    mail->readFromFile();    if( isRightsObject( mail ) )        return false;    Email newMail = *mail;	// mail will be deleted when we call removeMail    if ( !target->addMail(newMail) ) {	accessError( target );	return false;    }    if ( !source->removeMail( mail->uuid(), false ) ) {	// Delete the copy we made	target->removeMail( newMail.uuid(), false );    	accessError( source );	return false;    }    return true;}void EmailClient::showItemMenu(EmailListItem *item){    Folder *folder = folderView->currentFolder();    if ( folder == NULL )	return;    QString mailbox = folder->mailbox();    QStringList list = mailboxList->mailboxes();    list.removeAll( mailbox );    QMenu *popFolder = new QMenu(this);    movePop->clear();    copyPop->clear();    moveMap.clear();    QAction *action;    uint pos = 0;    for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {	action = movePop->addAction(*pm_folder, mailboxTrName(*it) );	moveMap.insert(action, pos);	action = copyPop->addAction(*pm_folder, mailboxTrName(*it) );	moveMap.insert(action, pos);	pos++;    }    

⌨️ 快捷键说明

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