📄 emailclient.cpp
字号:
{ QCopEnvelope e( "QPE/TaskBar", "setLed(int,bool)" ); e << LED_MAIL << true; }#endif // means this is the first time we encounter this mail if ( mail.uuid().isNull() ) { mail.setUuid( mailboxList->mailbox(InboxString)->generateUuid() ); //add to internal address list AddressPicker::addressList()->addAddress(mail.fromName(), mail.fromEmail() ); }#if defined(QTOPIA_PHONE) && !defined(QTOPIA_NO_MMS) bool readNow = false; bool getNow = false;#endif /* Test for get-this-mail activated on mail in trash. Replace mail in trash for consistency sake */ if ( mail.status(EFlag_Downloaded) ) { if ( mailboxList->mailbox(TrashString)->email( mail.uuid() ) ) { if ( !mailboxList->mailbox(TrashString)->addMail(mail) ) { accessError( mailboxList->mailbox(TrashString) ); } qDebug() << "return related to trash"; return; }#if defined(QTOPIA_PHONE) && !defined(QTOPIA_NO_MMS) QString mmsType = mail.header("X-Mms-Message-Type"); if (mmsType.contains("m-delivery-ind")) { QString msg; QString mmsStatus = mail.header("X-Mms-Status"); qDebug() << "Status:" << mmsStatus; if (mmsStatus.contains("Retrieved")) { msg = tr("<qt>Multimedia message delivered to %1.</qt>"); } else if (mmsStatus.contains("Rejected")) { msg = tr("<qt>Multimedia message rejected by %1.</qt>"); } else if (mmsStatus.contains("Deferred")) { msg = tr("<qt>Multimedia message deferred by %1.</qt>"); } else if (mmsStatus.contains("Expired")) { msg = tr("<qt>Multimedia message to %1 expired.</qt>"); } QString to = mail.header("To"); if (to.isEmpty()) to = tr("Unspecified", "MMS recipient"); QMessageBox::information(this, tr("Multimedia Message"), msg.arg(to), QMessageBox::Yes, QMessageBox::NoButton); qDebug() << "mms related return"; return; }#endif } else if (!mail.header("X-Mms-Message-Type").trimmed().isEmpty()) {#if defined(QTOPIA_PHONE) && !defined(QTOPIA_NO_MMS) static QDialog *newMMSDlg = 0; static QLabel *newMMSLabel = 0; static QListWidget *newMMSListBox = 0; MailAccount *account = accountList->getAccountById(mail.fromAccount()); if (newMMSDlg) { // We're already showing the new message dialog. // Change to a generic message and accept this mail immediately. QString msg(tr("You have new multimedia messages.")); newMMSLabel->setText(msg); newMMSListBox->model()->removeRow(2); emailHandler->acceptMail(mail);// getNow = true; //XXX read from settings. } else { QString msg(tr("You have a new multimedia message.")); msg += "<p><small>"; if (!mail.subject().isEmpty()) msg += tr("Subject: <b>%1</b><br>").arg(mail.subject()); if (!mail.from().isEmpty()) msg += tr("From: %1<br>").arg(mail.from()); msg += tr("%1 KBytes").arg(QString::number((mail.size()+1023)/1024)); msg += "</small>"; newMMSDlg = new QDialog(this, 0); newMMSDlg->setModal(true); newMMSDlg->setWindowTitle(tr("New MMS")); QVBoxLayout *vb = new QVBoxLayout(newMMSDlg); vb->setMargin(4); newMMSLabel = new QLabel(newMMSDlg); newMMSLabel->setTextFormat(Qt::RichText); newMMSLabel->setWordWrap(true); newMMSLabel->setText(msg); vb->addWidget(newMMSLabel); vb->addStretch(1); newMMSListBox = new QListWidget(newMMSDlg); vb->addWidget(newMMSListBox); newMMSListBox->addItem(tr("Read now")); newMMSListBox->addItem(tr("Read later")); newMMSListBox->addItem(tr("Reject message")); newMMSListBox->setCurrentRow(0); connect(newMMSListBox, SIGNAL(itemActivated(QListWidgetItem*)), newMMSDlg, SLOT(accept())); connect(newMMSListBox, SIGNAL(itemClicked(QListWidgetItem*)), newMMSDlg, SLOT(accept())); newMMSDlg->showMaximized(); QtopiaApplication::setMenuLike(newMMSDlg, true); QtopiaApplication::execDialog(newMMSDlg); if (newMMSDlg->result() == QDialog::Accepted) { if (newMMSListBox->currentRow() == 0) { // read now readNow = true;# ifndef QTOPIA_DESKTOP QtopiaApplication::setKeepRunning();# endif } else if (newMMSListBox->currentRow() == 2) { // reject emailHandler->rejectMail(mail); delete newMMSDlg; newMMSDlg = 0; return; } else { // read later QSettings mailconf("qtmail"); mailconf.beginGroup("MMS"); int count = mailconf.value("newMmsCount").toInt() + 1; mailconf.setValue("newMmsCount", count); QCopEnvelope e("QPE/System", "newMmsCount(int)"); e << count; if (account) { qDebug() << "**** autoDownload" << account->autoDownload(); getNow = account->autoDownload(); } } } delete newMMSDlg; newMMSDlg = 0; emailHandler->acceptMail(mail); }#endif } if ( !mailboxList->mailbox(InboxString)->addMail(mail) ) { accessError( mailboxList->mailbox(InboxString) ); }#if defined(QTOPIA_PHONE) && !defined(QTOPIA_NO_MMS) if (readNow) { autoDownloadMail = true; showMsgList = false; showMessageType = MailAccount::MMS; showMessageTimer.setSingleShot( true ); showMessageTimer.start( 0 ); showMsgId = mail.uuid(); } else if (getNow && !mail.status(EFlag_Downloaded)) { getSingleMail(&mail); if (!openedByUser) { QtopiaApplication::setKeepRunning(); closeAfterTransmissionsFinished(); QTMailWindow::singleton()->hide(); QTMailWindow::singleton()->forceHidden(true); } } else#endif if ( previewingMail ) { addMailToDownloadList( &mail ); }}// Called two times. After all headers are fetched and// after all mails have been picked by list.void EmailClient::allMailArrived(int){ // not previewing means all mailtransfer has been done if (!previewingMail) { // close current connection if ( !quitSent) { quitSent = true; emailHandler->popQuit(); return; } getNextNewMail(); return; } // all headers downloaded from server, start downloading remaining mails accountList->saveAccounts(); previewingMail = false; statusLabelHeader = mailAccount->accountName(); setTotalPopSize( mailDownloadList.size() ); emailHandler->setMailAccount(mailAccount); emailHandler->getMailByList(&mailDownloadList, false);}void EmailClient::getNextNewMail(){ // must use a counter, since several other functions may mess // with the current item in accountlist accountIdCount++; if (accountList->count() <= accountIdCount) { mailAccount = 0; } else { mailAccount = accountList->at(accountIdCount); if ( !mailAccount->canCollectMail() ) { getNextNewMail(); return; } } if ( (allAccounts) && (mailAccount != 0) ) { getNewMail(); if (queueStatus == 1) { progressBar->reset(); progressBar->setText(""); } } else { allAccounts = false; receiving = false; autoGetMail = false; getMailButton->setVisible(true); cancelButton->setVisible(false); selectAccountMenu->setEnabled(true); statusLabelHeader = ""; if (queueStatus == 1) { progressBar->reset(); progressBar->setText(""); } Folder *folder = folderView->currentFolder(); if ( folder ) updateFolderCount( folder->mailbox() ); isReceiving(false); }}void EmailClient::moveMailFront(Email *mailPtr){ qDebug("A: %d, %p, %p", receiving, mailPtr, mailAccount); if ( (receiving) && (mailPtr->fromAccount() == mailAccount->id() ) ) { qDebug("B"); mailDownloadList.moveFront( mailPtr->serverUid() ); }}void EmailClient::smtpError(int code, QString &msg){ QString temp = tr("<qt>Server: ") + smtpAccount->smtpServer() + "<br><br>"; if (code == ErrUnknownResponse) { temp += tr("Unexpected response from server:<br><br>"); QStringList list; list = msg.split(' '); int len = 0; for (QStringList::Iterator it = list.begin(); it != list.end(); ++it) { if ( (*it).length() + len > 35 ) { temp +="\n"; len = 0; } temp += *it + " "; len += (*it).length(); } } if (code == QAbstractSocket::ConnectionRefusedError) temp += tr( "Connection refused" ); if (code == QAbstractSocket::RemoteHostClosedError) temp += tr( "Remote host closed the connection" ); if (code == QAbstractSocket::HostNotFoundError) temp += tr( "Host not found" ); if (code == QAbstractSocket::SocketAccessError) temp += tr( "Permission denied" ); if (code == QAbstractSocket::SocketResourceError) temp += tr( "Insufficient resources" ); if (code == QAbstractSocket::SocketTimeoutError) temp += tr( "Operation timed out" ); if (code == QAbstractSocket::DatagramTooLargeError) temp += tr( "Datagram too large" ); if (code == QAbstractSocket::NetworkError) temp += tr( "Network error" ); if (code == QAbstractSocket::AddressInUseError) temp += tr( "Address in use" ); if (code == QAbstractSocket::SocketAddressNotAvailableError) temp += tr( "Address not available" ); if (code == QAbstractSocket::UnsupportedSocketOperationError) temp += tr( "Unsupported operation" ); if (code == QAbstractSocket::UnknownSocketError) temp += tr( "Unknown error" ); temp += "</qt>"; if (code != ErrCancel) { QMessageBox::warning(qApp->activeWindow(), tr("Sending error"), temp, tr("OK") ); } else { progressBar->setText( tr("Aborted by user") ); } sending = false; isSending(false);// sendMailButton->setVisible(true); cancelButton->setVisible(false); queuedUuids.clear();}void EmailClient::popError(int code, QString &msg){ QString temp = tr("<qt>Server: ") + mailAccount->mailServer() + "<br><br>"; if (code == ErrUnknownResponse) { temp += tr("Unexpected response from server:<br><br>" ); QStringList list; list = msg.split(' '); int len = 0; for (QStringList::Iterator it = list.begin(); it != list.end(); ++it) { if ( (*it).length() + len > 35 ) { temp +="\n"; len = 0; } temp += *it + " "; len += (*it).length(); } } if (code == ErrLoginFailed) temp += tr("Login failed. Check user name and password"); if (code == QAbstractSocket::ConnectionRefusedError) temp += tr( "Connection refused" ); if (code == QAbstractSocket::RemoteHostClosedError) temp += tr( "Remote host closed the connection" ); if (code == QAbstractSocket::HostNotFoundError) temp += tr( "Host not found" ); if (code == QAbstractSocket::SocketAccessError) temp += tr( "Permission denied" ); if (code == QAbstractSocket::SocketResourceError) temp += tr( "Insufficient resources" ); if (code == QAbstractSocket::SocketTimeoutError) temp += tr( "Operation timed out" ); if (code == QAbstractSocket::DatagramTooLargeError) temp += tr( "Datagram too large" ); if (code == QAbstractSocket::NetworkError) temp += tr( "Network error" ); if (code == QAbstractSocket::AddressInUseError) temp += tr( "Address in use" ); if (code == QAbstractSocket::SocketAddressNotAvailableError) temp += tr( "Address not available" ); if (code == QAbstractSocket::UnsupportedSocketOperationError) temp += tr( "Unsupported operation" ); if (code == QAbstractSocket::UnknownSocketError) temp += tr( "Unknown error" ); temp += "</qt>"; if (code != ErrCancel) { if ( !autoGetMail ) { QMessageBox::warning(qApp->activeWindow(), tr("Receiving error"), temp, tr("OK") ); } else { progressBar->setText( tr("Automatic Fetch failed") ); } } else { progressBar->setText(tr("Aborted by user")); } receiving = false; autoGetMail = false; isReceiving(false); getMailButton->setVisible(true); cancelButton->setVisible(false); selectAccountMenu->setEnabled(true);}void EmailClient::smsError(int code, QString &msg){ Q_UNUSED(code) QString temp(tr("<qt>Failed sending SMS: %1</qt>", "%1 will contain the reason for the failure")); QMessageBox::warning(qApp->activeWindow(), tr("Sending error"), temp.arg(msg), tr("OK") ); sending = false; isSending(false);// sendMailButton->setVisible(true); cancelButton->setVisible(false); queuedUuids.clear();}void EmailClient::mmsError(int code, QString &msg){#ifndef QTOPIA_NO_MMS Q_UNUSED(code) if (sending) { QString temp(tr("<qt>Failed sending MMS: %1</qt>", "%1 will contain the reason for the failure")); QMessageBox::warning(qApp->activeWindow(), tr("Sending error"), temp.arg(msg), tr("OK") ); sending = false; isSending(false);// sendMailButton->setVisible(true); queuedUuids.clear(); } else if (receiving) { QString temp(tr("<qt>Failed receiving MMS: %1</qt>", "%1 will contain the reason for the failure")); QMessageBox::warning(qApp->activeWindow(), tr("Receiving error"), temp.arg(msg), tr("OK") ); receiving = false; autoGetMail = false; isReceiving(false); getMailButton->setVisible(true); selectAccountMenu->setEnabled(true); } cancelButton->setVisible(false);#else Q_UNUSED(code) Q_UNUSED(msg)#endif}void EmailClient::queryItemSelected(){ EmailListItem *item = (EmailListItem*) messageView()->currentItem(); if (item == NULL) return; if (!messageView()->isItemSelected(item)) return; if (messageView()->currentMailbox() == DraftsString) { modify(item->mail()); return; } emit raiseWidget( readMailWidget(), tr("Read mail") ); mReadMail->update( messageView() ); if (autoDownloadMail) { if (!item->mail()->status(EFlag_Downloaded)) getSingleMail(item->mail()); autoDownloadMail = false; } #ifndef QT_NO_COP QCopEnvelope e( "QPE/TaskBar", "setLed(int,bool)" ); e << LED_MAIL << false;#endif // Reading a mail resets the new mail count QListIterator<MailAccount*> it = accountList->accountIterator(); while ( it.hasNext() ) { Client *client = emailHandler->clientFromAccount(it.next()); if (client) client->resetNewMailCount(); }#if 0 bool allread = true;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -