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

📄 readmail.cpp

📁 Qtopia下的邮件处理程序
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	case Qt::Key_P:	    if ( previousButton->isEnabled() )		previous();	    break;	case Qt::Key_N:	    if ( nextButton->isEnabled() )		next();	    break;	case Qt::Key_Delete:	    deleteItem();	    break;	case Qt::Key_R:	    reply();	    break;	case Qt::Key_F:	    forward();	    break;	case Qt::Key_T:	    shiftText();	    plainTextButton->toggle();	    break;	case Qt::Key_E:	    if ( modifyButton->isEnabled() )		modify();	default:	    QMainWindow::keyPressEvent( e );    }}int ReadMail::pWidth(){    if ( _pWidth )	return _pWidth;    return width();}int ReadMail::pHeight(){    if ( _pHeight )	return _pHeight;    return height();}QString ReadMail::fancyText(QString mailSize){    int i;    QString subj, text1, text2, sepText;	    subj += "<b><big><center><font color=\"#0000FF\">" +	     Qt::escape( mail->subject() ) +	     "</font></center></big></b><br>";    if (!mail->from().isEmpty() && mail->from() != "\"\" <>") { // ugh	text1 += "<b>"+tr("From")+": </b>";	text1 += refMailTo( mail->from() ) + "<br>";    }    if (mail->to().count() > 0) {	text1 +="<b>"+tr("To")+": </b>";	text1 += listRefMailTo( mail->to() );    }    if (mail->cc().count() > 0) {	text1 += "<br><b>CC: </b>";	text1 += listRefMailTo( mail->cc() );    }    if (mail->bcc().count() > 0) {	text1 += "<br><b>BCC: </b>";	text1 += listRefMailTo( mail->bcc() );    }    if ( !mail->replyTo().isEmpty() ) {	text1 += "<br><b>"+tr("Reply-To")+": </b>";	text1 += refMailTo( mail->replyTo() );    }    text1 += "<br><b>"+tr("Date")+"</b> ";    if ( !mail->dateTime().isNull() ) {	text1 += Qt::escape( Email::formattedDateTimeString( mail->dateTime() ) );    } else {	text1 += Qt::escape( mail->dateString() );    }    if (isMms && isSmil) {	text2 = "<a href=\"attachment;play\">";	text2 += "<b>" + tr("<b>Play MMS") + "</b>";	text2 += "</a>";	sepText += "<hr><br>";	bool showAtt = false;	for (i = 0; i < (int)mail->messagePartCount(); i++) {	    MailMessagePart &part = mail->messagePartAt(i);	    if (part.contentType().toLower() == "text/x-vcard"		|| part.contentType().toLower() == "text/x-vcalendar") {		if (!showAtt) {		    text2 += sepText + "<b>"+tr("Attachments")+": </b><br>";		    showAtt = true;		}		text2 += "<a href=\"attachment;view\"> " +			 Qt::escape(part.prettyName()) + "</a> ";	    }	}    } else if( isRightsObject( mail ) )        {            text2 += mail->plainTextBody();            text2 += "<hr><br>";            text2 += "<a href=\"installrights\">" + tr( "Install License" ) + "</a><br/>";    } else if (mail->messagePartCount() > 0) {#ifdef QTOPIA_PHONE	sepText += "<hr><br>";#else#ifdef QTOPIA4_TODO	sepText += "<br>";	text2 += "<b>"+tr("Attachments")+": </b>";	for (i = 0; i < (int)mail->messagePartCount(); i++ ) {	    MailMessagePart &part = mail->messagePartAt( i );	    if ( (part.contentType().startsWith("text") || part.contentType().startsWith("image") ) ) { // No tr		text2 += "<a href=\"attachment;scrollto;" + Qt::escape( part.prettyName() ) + "\"> " +			 Qt::escape(part.prettyName() ) + "</a> ";	    } else {		text2 += "<a href=\"attachment;view\"> " +			 Qt::escape(part.prettyName() ) + "</a> ";	    }	}	text2 += "<hr><br>";#endif#endif        text2 += formatText( mail->plainTextBody() );        if ( mail->plainTextBody().isEmpty() ) {            text2 += mail->htmlBody();            initImages();        }	for ( i = 0; i < (int)mail->messagePartCount(); i++ ) {	    MailMessagePart &part = mail->messagePartAt( i );        QString attachmentName = part.prettyName();#ifdef QTOPIA_PHONE        bool isFilePart = !part.name().isEmpty();        bool hasContentLocation = !part.contentLocation().isEmpty();        if ( isFilePart || hasContentLocation) {            if(!isFilePart)                attachmentName = part.contentLocation();#endif            text2 += "<a name=\"" + Qt::escape( attachmentName ) + "\"> </a>"; // No tr                        text2 += "<br><hr><b>" + tr("Attachment") +                     ": </b> <a href=\"attachment;view\"> " +                    Qt::escape( attachmentName ) + " </a> <hr>";#ifdef QTOPIA_PHONE        }#endif			    if (part.contentType().startsWith("text") ) { // No tr		QString temp;		if ( ( temp = part.decodedBody() ) != QString() ) {		    if ( part.contentType().indexOf("html") > -1) {			text2 += temp + "<br>";#ifdef QTOPIA_PHONE		    } else if ( !isFilePart ) {			text2 += formatText( temp );#endif		    } else {			text2 += "<pre> " + Qt::escape(temp) + "</pre>";		    }		} else {		    text2 += "<b>"+tr("Could not locate file")+"</b><br>";		}	    } else if (part.contentType().startsWith("image") ) { // No tr				QString str;		if ( mail->multipartRelated() ) {		    str = part.contentID();		    if ( str.length() > 0 && str[0] == '<' )			str = str.mid(1);		    if ( str.length() > 0 && str[(int)str.length() - 1] == '>' )			str = str.left(str.length() - 1);		    str = "cid:" + str;		} else {		    str = QString("%1_%2").arg(i).arg(part.filename());		    text2 += "<img src =\"" + str + "\"> </img>";		}				QString img = part.decodedBody();		QByteArray b( img.toAscii() );				QImage image( QImage::fromData( b ) );		int maxsize = qMin(emailView->width(), emailView->height());		if ( image.width() > maxsize || image.height() > maxsize )		    image = image.scaled(maxsize, maxsize, Qt::KeepAspectRatio,					 Qt::SmoothTransformation);		emailView->setResource( QUrl( str ), QVariant( image ) );	    }	}    } else {	sepText += "<hr><br>";	if ( mail->status(EFlag_Downloaded) || !mail->status(EFlag_Incoming) ) {            if ( mail->plainTextBody().isEmpty() ) {		text2 += mail->htmlBody();		initImages();	    } else if ( mail->plainTextBody().startsWith(                             SmsClient::vCardPrefix() ) ) {                QString copy = mail->plainTextBody();                QList<QContact> contacts                    = QContact::readVCard(                        copy.remove( SmsClient::vCardPrefix() ).toLatin1() );                if ( contacts.count() == 0 ) {                    // Invalid VCard data, so just show raw data                    text2 += formatText( mail->plainTextBody() );                } else if ( contacts.count() == 1 ) {                    QString name = tr( "Message contains vCard for %1" );                    if ( !contacts[0].nickname().isEmpty() ) {                        text2 += formatText( name.arg( contacts[0].nickname() ) );                    } else if ( !contacts[0].firstName().isEmpty() &&                                 !contacts[0].lastName().isEmpty() ) {                        text2 += formatText ( name.arg( contacts[0].firstName() +                                            " " +                                            contacts[0].lastName() ) );                    } else if ( !contacts[0].firstName().isEmpty() ) {                        text2 += formatText( name.arg( contacts[0].firstName() ) );                    } else {                        text2 += formatText(                                    tr( "Message contains vCard for a contact" ) );                    }                } else if ( contacts.count() > 1 ) {                    text2 += formatText(                                tr( "Message contains vCard for multiple contacts" ) );                }            } else {		text2 += formatText( mail->plainTextBody() );	    }	} else {	    text2 += "<b> "+tr("Awaiting download")+" </b><br>";	    text2 += tr("Size of mail") + ": " + mailSize;	}    }#ifdef QTOPIA_PHONE    return subj + text2 + sepText + "<font size=\"-5\">" + text1 + "</font>";#else    return subj + text1 + sepText + text2;#endif}QString ReadMail::normalText(QString mailSize){    QString text = tr("Subject")+": " + mail->subject() + "\n";    text += tr("From")+": " + mail->fromName() + " " + mail->fromEmail() + "\n";    text += tr("To")+": ";    text += mail->to().join(", ");    if (mail->cc().count() > 0) {	text += "\nCC: ";	text += mail->cc().join(", ");    }    if (mail->bcc().count() > 0) {	text += "\nBCC: ";	text += mail->bcc().join(", ");    }    if ( !mail->replyTo().isEmpty() ) {	text += "\nReply-To: ";	text += mail->replyTo();    }    text += "\n"+tr("Date")+": ";    if ( !mail->dateTime().isNull() ) {	text += Email::formattedDateTimeString( mail->dateTime() ) + "\n";    } else {	text += mail->dateString() + "\n";    }    if ( mail->messagePartCount() > 0 ) {	text += tr("Attachments")+": ";	for ( uint i = 0; i < mail->messagePartCount(); i++ ) {	    MailMessagePart &part = mail->messagePartAt( i );	    text += part.prettyName() + " ";	}	text += "\n\n";    } else text += "\n";    if ( !mail->status(EFlag_Incoming) ) {	text += mail->plainTextBody();    } else if ( mail->status(EFlag_Downloaded) ) {	text += mail->plainTextBody();    } else {	text += "\n"+tr("Awaiting download")+"\n";	text += tr("Size of mail")+": " + mailSize;    }    return text;}QString ReadMail::formatText(QString txt){    QStringList p, out;    p = txt.split("\n\n");    QStringList::Iterator it = p.begin();    uint lineCharLength;    if ( fontInfo().pointSize() >= 10 ) {	lineCharLength = width() / (fontInfo().pointSize() - 4 );    } else {	lineCharLength = width() / ( fontInfo().pointSize() - 3 );    }    //Maintain original linelengths if display width allows it    if (!mail->header("X-Sms-Type").isNull()) {	while ( it != p.end() ) {	    out.append( smsBreakReplies( *it) );	    it++;	}	    } else if ( lineCharLength >= 70 ) {	while ( it != p.end() ) {	    out.append( noBreakReplies( *it) );	    it++;	}    } else {	while ( it != p.end() ) {	    out.append( handleReplies( *it ) );	    it++;	}    }    QString ret = encodeUrlAndMail( out.join("<br><br>") );    if (!mail->header("X-Sms-Type").isNull())	ret.replace( QRegExp( "\\s" ), "&nbsp;" );    return ret;}/*  Preserve white space, add linebreaks so text is wrapped to    fit the display width */QString ReadMail::smsBreakReplies(QString txt){    QString str = "";    QStringList p = txt.split("\n");    QStringList::Iterator it = p.begin();    while ( it != p.end() ) {	str += buildParagraph( *it, "", true ) + "<br>";	it++;    }    return str;}/*  Maintains the original linebreaks, but colours the lines    according to reply level	*/QString ReadMail::noBreakReplies(QString txt){    QString str = "";    QStringList p = txt.split("\n");    int x, levelList;    QStringList::Iterator it = p.begin();    while ( it != p.end() ) {		x = 0;	levelList = 0;	while (x < (int)(*it).length() ) {	    if ( (*it)[x] == '>' ) {		levelList++;	    } else if ( (*it)[x] == ' ' ) {	    } else break;		    x++;	}		if (levelList == 0 ) {	    str += Qt::escape(*it) + "<br>";	} else {	    if ( levelList % 2 == 0 ) {		str += "<font color=\"#0000FF\">";	    } else {		str += "<font color=\"#FF0000\">";	    }	    str += Qt::escape(*it) + "</font><br>";	}		it++;    }    return str;}/*  This one is a bit complicated.  It divides up all lines according    to their reply level, defined as count of ">" before normal text    It then strips them from the text, builds the formatted paragraph    and inserts them back into the beginning of each line.  Probably not    to speed efficient on large texts, but this manipulation greatly increases    the readability (trust me, I'm using this program for my daily email reading..)*/QString ReadMail::handleReplies(QString txt){    QStringList out;    QStringList p = txt.split("\n");    QList<uint> levelList;    QStringList::Iterator it = p.begin();    int lastLevel = 0, level = 0;    QString str, line;    while ( it != p.end() ) {	line = (*it).trimmed();	if ( line.startsWith(">") ) {	    level = 0;	    for (int x = 0; x < (int)line.length(); x++) {		if ( line[x] == ' ') {	//do nothing		} else if ( line[x] == '>' ) {		    level++;		    if ( (level > 1 ) && (line[x-1] != ' ') ) {			line.insert(x, ' ');	//we need it to be "> > " etc..			x++;		    }		} else {		    // make sure it follows style "> > This is easier to format"		    line.insert(x, ' ');		    break;		}	    }	} else {	    level = 0;	}	if ( level != lastLevel ) {	    if ( !str.isEmpty() ) {		out.append( str );		levelList.append( lastLevel );	    }	    str = "";	    lastLevel = level;	    it--;	} else {	    str += line.mid( level * 2) + "\n";

⌨️ 快捷键说明

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