194 // ---------------------------------------------------------- |
194 // ---------------------------------------------------------- |
195 // |
195 // |
196 void CSimpleDocument::GetDirectContentsL( |
196 void CSimpleDocument::GetDirectContentsL( |
197 RPointerArray<MSimpleContent>& aContents ) |
197 RPointerArray<MSimpleContent>& aContents ) |
198 { |
198 { |
|
199 CleanupClosePushL( aContents ); |
199 aContents.Reset(); |
200 aContents.Reset(); |
200 TInt myCount = iContents.Count(); |
201 TInt myCount = iContents.Count(); |
201 for ( TInt i = 0; i<myCount; i++ ) |
202 for ( TInt i = 0; i<myCount; i++ ) |
202 { |
203 { |
203 User::LeaveIfError( aContents.Append( iContents[i] )); |
204 aContents.AppendL( iContents[i] ); |
204 } |
205 } |
|
206 CleanupStack::Pop( &aContents ); |
205 } |
207 } |
206 |
208 |
207 // ---------------------------------------------------------- |
209 // ---------------------------------------------------------- |
208 // CSimpleDocument::AddDirectContentL |
210 // CSimpleDocument::AddDirectContentL |
209 // ---------------------------------------------------------- |
211 // ---------------------------------------------------------- |
651 // Convert all the multipart into CBodyPart. |
653 // Convert all the multipart into CBodyPart. |
652 |
654 |
653 // Let's convert first ROOT element into CBodyPart |
655 // Let's convert first ROOT element into CBodyPart |
654 CBodyPart* root = CBodyPart::NewL(); |
656 CBodyPart* root = CBodyPart::NewL(); |
655 // Add into cleanup array |
657 // Add into cleanup array |
656 aBodies.Append( root ); |
658 aBodies.AppendL( root ); |
657 CSenElement* e = Root()->BaseElement(); |
659 CSenElement* e = Root()->BaseElement(); |
658 |
660 |
659 // externalize the document into stream |
661 // externalize the document into stream |
660 CBufFlat* myBuffer = CBufFlat::NewL( KBufferSize ); |
662 CBufFlat* myBuffer = CBufFlat::NewL( KBufferSize ); |
661 CleanupStack::PushL( myBuffer ); |
663 CleanupStack::PushL( myBuffer ); |
674 using namespace NSimpleDocument::NSimpleRoot; |
676 using namespace NSimpleDocument::NSimpleRoot; |
675 |
677 |
676 // calculate the size of headers |
678 // calculate the size of headers |
677 TInt headerSize = KContentTypeSize + KCIDSize; |
679 TInt headerSize = KContentTypeSize + KCIDSize; |
678 HBufC8* headers = HBufC8::NewL( headerSize ); |
680 HBufC8* headers = HBufC8::NewL( headerSize ); |
679 aBuffers.Append( headers ); |
681 aBuffers.AppendL( headers ); |
680 TPtr8 pH(headers->Des()); |
682 TPtr8 pH(headers->Des()); |
681 // append to MIME headers for the root part |
683 // append to MIME headers for the root part |
682 pH.Append( NSimpleDocument::NSimpleRoot::KContentType ); |
684 pH.Append( NSimpleDocument::NSimpleRoot::KContentType ); |
683 pH.Append( NSimpleDocument::NSimpleRoot::KCID ); |
685 pH.Append( NSimpleDocument::NSimpleRoot::KCID ); |
684 root->SetHeaders( pH ); |
686 root->SetHeaders( pH ); |
687 TInt contCount = iContents.Count(); |
689 TInt contCount = iContents.Count(); |
688 for ( TInt i=0; i<contCount; i++ ) |
690 for ( TInt i=0; i<contCount; i++ ) |
689 { |
691 { |
690 // Let's convert next element into CBodyPart |
692 // Let's convert next element into CBodyPart |
691 CBodyPart* cp = CBodyPart::NewL(); |
693 CBodyPart* cp = CBodyPart::NewL(); |
692 aBodies.Append( cp ); |
694 aBodies.AppendL( cp ); |
693 |
695 |
694 // Set Headers |
696 // Set Headers |
695 headerSize = NSimpleDocument::NSimpleContent::KContentTypeSize + |
697 headerSize = NSimpleDocument::NSimpleContent::KContentTypeSize + |
696 NSimpleDocument::NSimpleContent::KCIDSize + |
698 NSimpleDocument::NSimpleContent::KCIDSize + |
697 NSimpleDocument::NSimpleContent::KContentEncodingSize; |
699 NSimpleDocument::NSimpleContent::KContentEncodingSize; |
698 headerSize += (iContents[i])->ContentID().Length(); |
700 headerSize += (iContents[i])->ContentID().Length(); |
699 headerSize += (iContents[i])->ContentType().Length(); |
701 headerSize += (iContents[i])->ContentType().Length(); |
700 |
702 |
701 headers = HBufC8::NewL( headerSize ); |
703 headers = HBufC8::NewL( headerSize ); |
702 // Append to cleanup array |
704 // Append to cleanup array |
703 aBuffers.Append( headers ); |
705 aBuffers.AppendL( headers ); |
704 pH.Set( headers->Des() ); |
706 pH.Set( headers->Des() ); |
705 |
707 |
706 // _LIT8( KMyContentType, "Content-Type: %S\r\n"); |
708 // _LIT8( KMyContentType, "Content-Type: %S\r\n"); |
707 TPtrC8 myValue = (iContents[i])->ContentType(); |
709 TPtrC8 myValue = (iContents[i])->ContentType(); |
708 pH.Format( NSimpleDocument::NSimpleContent::KContentType, &myValue ); |
710 pH.Format( NSimpleDocument::NSimpleContent::KContentType, &myValue ); |
714 |
716 |
715 // Body |
717 // Body |
716 |
718 |
717 // BASE64 encode |
719 // BASE64 encode |
718 HBufC8* body64 = HBufC8::NewL( (iContents[i])->Body().Length() * KB64Expand ); |
720 HBufC8* body64 = HBufC8::NewL( (iContents[i])->Body().Length() * KB64Expand ); |
719 aBuffers.Append( body64 ); |
721 aBuffers.AppendL( body64 ); |
720 TImCodecB64 codec64; |
722 TImCodecB64 codec64; |
721 codec64.Initialise(); |
723 codec64.Initialise(); |
722 TPtr8 desti8 = body64->Des(); |
724 TPtr8 desti8 = body64->Des(); |
723 |
725 |
724 // notice: leave if error? |
726 // notice: leave if error? |