email.cpp

来自「Qtopia下的邮件处理程序」· C++ 代码 · 共 185 行

CPP
185 行
字号
/******************************************************************************** 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 <qfileinfo.h>#include <qbuffer.h>#include <qtextcodec.h>#include "email.h"#include "emailfolderlist.h"#ifndef QTOPIA_NO_MMS#include "drmattachmentlink.h"#endif#include <qtopia/qcontent.h>#include <qtopia/qmimetype.h>Email::Email(EmailFolderList *parent)    : MailMessage(){    _parent = parent;    _inMem = false;    _dirty = false;    _arrival = 0;}Email::Email(const MailMessage &m, EmailFolderList *parent)    : MailMessage(m){    _parent = parent;    _inMem = false;    _dirty = false;    _arrival = 0;}EmailFolderList* Email::parent(){    return _parent;}void Email::reparent(EmailFolderList *parent){    _parent = parent;}void Email::readFromFile(){    if ( _parent && !_inMem)	_parent->swapMailIn( this );}void Email::setInMemory(bool b){    _inMem = b;}bool Email::setAttachmentInstalled(const QString& filename, bool install){    for ( int i = 0; i < (int)messagePartCount(); i++ ) {	MailMessagePart &part = messagePartAt( i );        if (part.name() == filename || (part.name().isEmpty() && part.contentLocation() == filename) ) {		    QString file = part.storedFilename();	    QString lnk = part.linkFile();            QContent c(lnk);            if ( install ) {		if ( !validateFile(part) )  //install file to documents folder		    return false;		file = part.storedFilename();		if ( !c.isValid() || c.file() != file ) {		    QContent d( file );           // QContent determines it's internal type in the constructor		    if( d.drmState() == QContent::Unprotected )                        d.setType( part.contentType() );                        d.setName( !part.name().isEmpty() ? part.name() : part.contentLocation() );                    d.commit();                    part.setLinkFile( d.linkFile() );		    _dirty = true;		}		return true;            } else {                if ( c.isValid() )                    c.removeFiles();		part.setLinkFile( "" );		part.setStoredFilename("");				_dirty = true;		return true;            }        }    }    return false;}bool Email::validateFile(MailMessagePart &part){    QString str = part.storedFilename().trimmed();    if ( str.isEmpty() ) {	//str = Qtopia::applicationFileName("qtmail", "enclosures/");    str = Qtopia::documentDir();   		uint i = 0;	while ( i < messagePartCount() ) {	    if ( messagePartAt(i).filename() == part.filename() )		break;	    i++;	}   	str += QString("%1_%2_%3").arg( uuid().data1 ).arg( i ).arg( part.filename() );#ifndef QTOPIA_NO_MMS        if( !str.endsWith( ".dcf" ) && part.contentType() == "qtopia/drmattachmentlink" )            str.append( ".dcf" );#endif	part.setStoredFilename( str );	_dirty = true;    }    QFile f( str );    if ( !f.exists() )	return saveFile(part);    return true;}bool Email::saveFile(MailMessagePart &part){#ifndef QTOPIA_NO_MMS    if( part.contentType() == "qtopia/drmattachmentlink" )    {        if( !QFile::link( DrmAttachmentLink( part.decodedBody() ).enclosureLocation(), part.storedFilename() ) )        {            qWarning("could not save attachment %s", part.storedFilename().toLatin1().data() );            return false;        }    }    else    {#endif        QFile f( part.storedFilename() );        if ( !f.open(QIODevice::WriteOnly) ) {            qWarning("could not save attachment %s", part.storedFilename().toLatin1().data() );            return false;        }        f.write(QByteArray(part.decodedBody().toAscii()));        f.close();#ifndef QTOPIA_NO_MMS    }#endif    return true;}

⌨️ 快捷键说明

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