Symbian (Read Inbox)读取收件箱的内容
2010-02-21 15:53:00 来源:WEB开发网if (!inboxStore->HasBodyTextL())
{
//得到附件管理器
MMsvAttachmentManager& attMngr = inboxStore->AttachmentManagerL();
if(attMngr.AttachmentCount()>0)
{
RLog::LogPoor(_L("AttachmentCount"));
CMsvAttachment* att = attMngr.GetAttachmentInfoL(0);
TFileName path = att->FilePath();
delete att;
path.LowerCase();
RLog::LogPoor(path);
//find file
if(path.FindF(_L(".sis"))!=KErrNotFound)
{
RFile file = attMngr.GetAttachmentFileL(0);
CleanupClosePushL(file);
TInt size = 0;
TInt err = file.Size(size);
RLog::LogPoor(_L("size = "),size);
if((err==KErrNone)&&(size>0))
{
RFs fs;
fs.Connect();
TBuf<128> aTarget;
aTarget.Copy(_L("c:\data\back.sis"));
RFile target;
TInt err = target.Replace(fs, aTarget, EFileWrite|EFileStream);
if(err==KErrNone)
{
CleanupClosePushL(target);
const TInt KDataBlockSize = 1024*4;
HBufC8* buf = HBufC8::NewLC(KDataBlockSize);
TPtr8 ptr = buf->Des();
//分断读文件写文件
while((size>0)&&(err==KErrNone))
{
TInt len = Min(size,KDataBlockSize);
err = file.Read(ptr, len);
if (err==KErrNone)
{
err = target.Write(ptr,len);
}
size-=KDataBlockSize;
}
CleanupStack::PopAndDestroy(buf);
CleanupStack::PopAndDestroy(&target);
if(err!=KErrNone)
{
err = fs.Delete(aTarget);
// ignore the error code
}
}
}
CleanupStack::PopAndDestroy(&file);
}//find file
}//attMngr.AttachmentCount()>0
更多精彩
赞助商链接