📄 readmail.cpp
字号:
} it++; } if ( !str.isEmpty() ) { out.append( str ); levelList.append( level ); } str = "<nobr>"; // tell the textview that we're in control of linebreaks lastLevel = 0; int pos = 0; it = out.begin(); while ( it != out.end() ) { if ( levelList[pos] == 0 ) { str += buildParagraph( *it, "" ) + "<br>"; } else { QString pre = ""; QString preString = ""; for ( int x = 0; x < (int)levelList[pos]; x++) { pre += "> "; preString += "> "; } // single lines ">" are dropped, so we insert this for better clarity if ( (int)levelList[pos] < lastLevel ) { str += "<font color=\"FF0000\">" + pre +"</font> <br>"; } p = buildParagraph( *it, preString ).split("<br>" ); if ( levelList[pos] % 2 == 0 ) { str += "<font color=\"#0000FF\">"; } else { str += "<font color=\"#FF0000\">"; } str += pre + p.join("<br> " + pre) + "</font><br>"; } lastLevel = levelList[pos]; pos++; it++; } if ( str.indexOf("<br>", -4) != -1 ) { str.truncate( str.length() - 4 ); //remove trailing br } str += "</nobr>"; return str;}QString ReadMail::buildParagraph(QString txt, QString prepend, bool preserveWs){ QStringList out; //use escape here so we don't clutter our <br> QStringList p; if (preserveWs) { txt = Qt::escape( txt ); p = txt.split(" ", QString::KeepEmptyParts); } else { txt = Qt::escape( txt.simplified() ); p = txt.split(" "); } QStringList::Iterator it = p.begin(); QString str; QFontMetrics fm( emailView->font() );// int w = emailView->viewport()->width()-20; int w = pWidth() - 20; while ( it != p.end() ) { if ( fm.width( prepend + (*it) + str) > w ) { if ( str.isEmpty() ) { out.append( *it ); } else { out.append( str ); str = *it; } } else if ( str.length() == 0 ) { str = *it; } else { str += " " + *it; } it++; } if ( !str.isEmpty() ) out.append( str ); return out.join("<br>");}/* This one is called after Qt::escape, so if the email address is of type<some@rtg> we have to remove the safe characters at the beginning and end. It's not a foolproof method, but it should handle nearly all cases. To make it foolproof add methods to determine legal/illegal characters in the url/email addresses.*/QString ReadMail::encodeUrlAndMail(QString txt){ QString emailAddress, url; QString str(txt); const QString validChars = QString(".!#$%'*+-/=?^_`{|}~"); // Find and encode email addresses int pos = 0; while ( ( pos = str.indexOf('@', pos) ) != -1 ) { int beg = pos - 1; while ( beg >= 0 && ( str[beg].isLetterOrNumber() || (validChars.indexOf( str[beg] ) != -1 ))) beg--; if (beg < 0) beg = 0; if ( !str[beg].isLetterOrNumber() && (validChars.indexOf( str[beg] ) == -1 )) beg++; int endPos = pos + 1; if (endPos >= (int)str.length()) endPos = pos; while ( endPos < (int)str.length() && ( str[endPos].isLetterOrNumber() || (validChars.indexOf( str[endPos] ) != -1 ))) endPos++; if ( !str[endPos].isLetterOrNumber() && (validChars.indexOf( str[endPos] ) == -1 )) endPos--; emailAddress = str.mid(beg, endPos - beg + 1); if ( emailAddress.startsWith("<") ) { emailAddress = emailAddress.right( emailAddress.length() - 4); beg += 4; if ( emailAddress.indexOf(">", -4) != -1 ) { emailAddress = emailAddress.left( emailAddress.length() - 4 ); endPos -= 4; } } if ( emailAddress.lastIndexOf('.', -1) > endPos - pos ) { //Scan for . after @ to verify that it is an email address QString s = refMailTo(emailAddress); str.replace(beg, endPos - beg + 1, s); pos = beg + s.length(); } else { pos = endPos + 1; } } // Find and encode http addresses pos = 0; const QString httpStr = "http://"; const QString wwwStr = "www."; while ( ( ( str.indexOf(httpStr, pos) ) != -1 ) || ( ( str.indexOf(wwwStr, pos) ) != -1 ) ) { int httpPos = str.indexOf(httpStr, pos); int wwwPos = str.indexOf(wwwStr, pos); int endPos = 0; QString urlPrefix; if ( (httpPos != -1) && ((wwwPos == -1) || (httpPos < wwwPos)) ) { pos = httpPos; endPos = pos + httpStr.length(); } else { pos = wwwPos; endPos = pos + wwwStr.length(); urlPrefix = "http://"; } while ( endPos < (int)str.length() && ( str[endPos].isLetterOrNumber() || (validChars.indexOf( str[endPos] ) != -1 ))) endPos++; if (endPos >= (int)str.length() || (!str[endPos].isLetterOrNumber() && (validChars.indexOf( str[endPos] ) == -1 ))) endPos--; url = str.mid(pos, endPos - pos + 1); if ( url.indexOf('.') > -1 ) { //Scan for . after // to verify that it is an url (weak, I know) QString s = "<a href=\"" + urlPrefix + url + "\"> " + url + " </a>"; str.replace(pos, endPos - pos + 1, s); pos += s.length(); } else { pos = endPos + 1; } } return str;}QString ReadMail::listRefMailTo(QStringList list){ QString str; for (QStringList::Iterator it = list.begin(); it != list.end(); ++it) { if ( str.isEmpty() ) { str += refMailTo( *it ); } else { str += ", " + refMailTo( *it ); } } return str;}QString ReadMail::refMailTo(QString adr){ int type = adr.indexOf("/TYPE="); if (type > 0) adr.truncate(type); return "<a href=\"mailto:" + Qt::escape(adr) + "\"> " + Qt::escape(adr) + " </a>";}//update view with current EmailListItem (item)void ReadMail::update(MailListView *view){ mailView = view; EmailListItem *current = (EmailListItem *) view->currentItem(); if ( !current || !view->isItemSelected( current ) ) { close(); return; } mail = current->mail(); lastMailUuid = mail->uuid(); QString mailbox = mailView->currentMailbox();#ifdef QTOPIA_PHONE context->clear(); if ( hasGet(mailbox) ) context->addAction( getThisMailButton ); else if ( hasSend(mailbox) ) context->addAction( sendThisMailButton ); if ( hasReply(mailbox) ) { context->addAction( replyButton ); context->addAction( replyAllAction ); context->addAction( forwardAction ); } if ( hasEdit(mailbox) ) context->addAction( modifyButton ); context->addAction( deleteButton ); context->addAction( plainTextButton ); //what about next/prev/attachments/status?#else#ifdef QTOPIA4_TODO bar->clear(); if ( hasGet(mailbox) ) getThisMailButton->addTo(bar); if ( hasSend(mailbox) ) sendThisMailButton->addTo(bar); if ( hasReply(mailbox) ) replyButton->addTo(bar); if ( hasEdit(mailbox) ) modifyButton->addTo(bar); previousButton->addTo(bar); nextButton->addTo(bar); deleteButton->addTo(bar); buildMenu(mailbox);#endif #endif updateView(); updateButtons();}void ReadMail::buildMenu(const QString &mailbox){#ifdef QTOPIA_PHONE QString unused = mailbox;#else#ifdef QTOPIA4_TODO mailMenu->clear(); statusMenu->clear(); if ( hasGet(mailbox) ) { getThisMailButton->addTo( mailMenu ); mailMenu->insertSeparator(); } if ( hasSend(mailbox) ) { sendThisMailButton->addTo( mailMenu ); mailMenu->insertSeparator(); } if ( hasReply(mailbox) ) { replyButton->addTo( mailMenu ); replyAllAction->addTo( mailMenu ); forwardAction->addTo( mailMenu ); } if ( hasEdit(mailbox) ) { modifyButton->addTo( mailMenu ); } mailMenu->insertSeparator(); mailMenu->insertItem(tr("Set status"), statusMenu); mailMenu->insertSeparator(); deleteButton->addTo(mailMenu); statusMenu->insertItem(tr("Unread"), this, SLOT( setStatus(int) ), 0, 1); statusMenu->insertItem(tr("Replied"), this, SLOT( setStatus(int) ), 0, 2); statusMenu->insertItem(tr("Forwarded"), this, SLOT( setStatus(int) ), 0, 3); statusMenu->insertItem(tr("Sent"), this, SLOT( setStatus(int) ), 0, 4); statusMenu->insertItem(tr("Unsent"), this, SLOT( setStatus(int) ), 0, 5);#endif#endif}void ReadMail::mailUpdated(Email *mailIn){ if ( lastMailUuid == mailIn->uuid() ) { mail = mailIn; updateView(); updateButtons(); } else { updateButtons(); }}#ifdef QTOPIA_PHONEbool ReadMail::eventFilter( QObject *obj, QEvent *e ){ if (obj == emailView && e->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = (QKeyEvent*)e; switch( keyEvent->key() ) { case Qt::Key_Left: emailView->scrollBy(-100,0); keyEvent->accept(); return true; break; case Qt::Key_Right: emailView->scrollBy(100,0); keyEvent->accept(); return true; break; default: break; }#ifndef QTOPIA_NO_MMS } else if (smilView && obj == smilView && e->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = (QKeyEvent*)e; switch( keyEvent->key() ) { case Qt::Key_Select: advanceMmsSlide(); break; }#endif } return QMainWindow::eventFilter( obj, e );}#endifvoid ReadMail::closeEvent( QCloseEvent *e ){ //check for read reply flag #ifdef QTOPIA_PHONE#ifndef QTOPIA_NO_MMS QString mmsType = mail->header("X-Mms-Message-Type"); QString msgClass = mail->header("X-Mms-Message-Class"); QString readReply = mail->header("X-Mms-Read-Reply"); if (mmsType.contains("m-retrieve-conf") && !msgClass.contains("Auto") && readReply.contains("Yes") && firstRead) { emit readReplyRequested(mail); } if (smilView && views->currentWidget() == smilView) { views->setCurrentWidget(emailView); smilView->reset(); e->ignore(); return;}#endif#endif cleanup(); emit cancelView();}void ReadMail::cleanup(){ emailView->setPlainText("");}//gets next item in listview, exits if there is no nextvoid ReadMail::next(){ EmailListItem *item = (EmailListItem *) mailView->currentItem(); if (item && mailView->isItemSelected(item) && mailView->row( item ) + 1 < mailView->rowCount() ) item = (EmailListItem* )mailView->item( mailView->row( item ) + 1, 0 ); else item = 0; if (item != NULL) { mailView->clearSelection(); mailView->setItemSelected( item, true ); mailView->setCurrentItem( item ); bool inbox = mail->status(EFlag_Incoming) > 0; mail = item->mail(); lastMailUuid = mail->uuid(); if ( inbox == (mail->status(EFlag_Incoming) > 0) ) { updateView(); } else { update( mailView ); } updateButtons(); }}//gets previous item in listview, exits if there is no previousvoid ReadMail::previous(){ EmailListItem *item = (EmailListItem *) mailView->currentItem(); if (item && mailView->isItemSelected(item) && mailView->row( item ) > 0 ) item = (EmailListItem* )mailView->item( mailView->row( item ) - 1, 0 ); else item = 0; if (item != NULL) { mailView->clearSelection(); mailView->setItemSelected( item, true ); mailView->setCurrentItem( item ); bool inbox = mail->status(EFlag_Incoming) > 0; mail = item->mail(); lastMailUuid = mail->uuid();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -