emailuis/emailui/src/FreestyleMessageHeaderHTML.cpp
branchRCL_3
changeset 22 d620048b4810
parent 16 b5fbb9b25d57
child 23 dcf0eedfc1a3
equal deleted inserted replaced
20:efd4f1afd43e 22:d620048b4810
    29 #include <finditemengine.h>
    29 #include <finditemengine.h>
    30 #include "FreestyleMessageHeaderHTML.h"
    30 #include "FreestyleMessageHeaderHTML.h"
    31 #include "FreestyleEmailUiUtilities.h"
    31 #include "FreestyleEmailUiUtilities.h"
    32 #include "ncsconstants.h"
    32 #include "ncsconstants.h"
    33 
    33 
    34 
    34 _LIT( KAlignRight, "right" );
    35 
    35 _LIT( KAlignLeft, "left" );
    36 _LIT8( KExpandHeaderIconFileName, "plus.gif");
    36 _LIT( KRtl, "rtl" );
    37 _LIT8( KCollapseHeaderIconFileName, "minus.gif");
    37 _LIT( KLtr, "ltr" );
    38 _LIT8( KAttachementIconGeneral, "attachment.gif");
    38 
    39 _LIT8( KFollowUpIconFileName, "follow_up.png");
    39 const TInt KMaxRecipientsShown( 10 );
    40 _LIT8( KFollowUpCompleteIconFileName, "follow_up_complete.png");
       
    41 _LIT8( KPriorityHighIconFileName, "todo_high_add.png");
       
    42 _LIT8( KPriorityLowIconFileName, "todo_low_add.png");
       
    43 
       
    44 _LIT8( KCollapsedHeaderTableName, "collapsed_header" );
       
    45 _LIT8( KExpandedHeaderTableName, "expanded_header" );
       
    46 _LIT8( KToTableName, "to_table");
       
    47 _LIT8( KCcTableName, "cc_table");
       
    48 _LIT8( KBccTableName, "bcc_table");
       
    49 _LIT8( KAttachmentTableName, "attachment_table");
       
    50 _LIT8( KFromTableName,"from_table");
       
    51 
       
    52 _LIT8( KFromFieldName, "from_field");
       
    53 _LIT8( KToFieldName, "to_field");
       
    54 _LIT8( KCcFieldName, "cc_field");
       
    55 _LIT8( KBccFieldName, "bcc_field");
       
    56 _LIT8( KSentFieldName, "sent_field");
       
    57 _LIT8( KSubjectFieldName, "subject_field");
       
    58 
       
    59 _LIT8( KToImageName, "to_img");
       
    60 _LIT8( KCcImageName, "cc_img");
       
    61 _LIT8( KBccImageName, "bcc_img");
       
    62 _LIT8( KAttachmentImageName, "attachment_img");
       
    63 _LIT8( KFollowUpImageName, "follow_up_img");
       
    64 _LIT8( KFollowUpCompleteImageName, "follow_up_complete_img");
       
    65 _LIT8( KPriorityHighImageName, "todo_high_add_img");
       
    66 _LIT8( KPriorityLowImageName, "todo_low_add_img");
       
    67 
       
    68 _LIT8( KSpace8, " ");
       
    69 
       
    70 _LIT8( KHTMLImgTagId, "<image id=\"" );
       
    71 _LIT8( KHTMLImgTagSrcBefore, "\" border=\"0\" src=\"" );
       
    72 _LIT8( KHTMLImgTagSrcAfter, "\">" );
       
    73 
       
    74 _LIT8( KMetaHeader, "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n" );
       
    75 
       
    76 _LIT8( KDisplayImagesLeftToRight,
       
    77         "<script language=\"javascript\">var g_autoLoadImages = %d;</script>\n<table style=\"display: none;\" id=\"displayImagesTable\" width=\"%dpx\"><tr><td align=\"left\">%S</td><td align=\"right\"><input type=\"submit\" class=\"button\" value=\"%S\" onClick=\"displayImagesButtonPressed()\"/></td></tr></table>" );
       
    78 
       
    79 _LIT8( KDisplayImagesRightToLeft,
       
    80         "<script language=\"javascript\">var g_autoLoadImages = %d;</script>\n<table style=\"display: none;\" id=\"displayImagesTable\" width=\"%dpx\"><tr><td align=\"left\"><input type=\"submit\" class=\"button\" value=\"%S\" onClick=\"displayImagesButtonPressed()\"/></td><td align=\"right\">%S</td></tr></table>" );
       
    81 _LIT8 ( KProtocolIdentifier, "://" );
       
    82 const TInt KMaxEventLength( 256 );
       
    83 const TInt KFreestyleMessageHeaderHTMLRightMarginInPx( 10 );
    40 const TInt KFreestyleMessageHeaderHTMLRightMarginInPx( 10 );
    84 const TInt KFreestyleMessageHeaderHTMLMaxBufferSizeForWidth( 5 );
    41 
       
    42 _LIT8( KTableRowBegin, "<tr>" );
       
    43 _LIT8( KTableRowEnd, "</tr>\n" );
       
    44 _LIT8( KTableCellEnd, "</td>" );
       
    45 
       
    46 _LIT( KSchemeSeparator, "://" );
       
    47 _LIT( KUrlFormat, "<a href=\"%S\">%S</a>" );
       
    48 _LIT( KUrlFormatWithHttp, "<a href=\"http://%S\">%S</a>" );
    85 
    49 
    86 // Define this to allow theme colorin for the header
    50 // Define this to allow theme colorin for the header
    87 #undef __USE_THEME_COLOR_FOR_HEADER    
    51 #define __USE_THEME_COLOR_FOR_HEADER    
    88 
    52 
    89 EXPORT_C CFreestyleMessageHeaderHTML* CFreestyleMessageHeaderHTML::NewL( CFSMailMessage& aMailMessage, 
    53 EXPORT_C CFreestyleMessageHeaderHTML* CFreestyleMessageHeaderHTML::NewL( CFSMailMessage& aMailMessage, 
    90                                                                          RWriteStream& aWriteStream,
    54                                                                          RWriteStream& aWriteStream,
    91                                                                          TInt aVisibleWidth,
    55                                                                          TInt aVisibleWidth,
    92                                                                          TInt aScrollPosition,
    56                                                                          TInt aScrollPosition,
    93                                                                          const TBool aAutoLoadImages,
    57                                                                          const TBool aAutoLoadImages,
    94                                                                          const TBool aExpanded 
    58                                                                          const TBitFlags& aFlags 
    95                                                                          )
    59                                                                          )
    96     {
    60     {
    97     CFreestyleMessageHeaderHTML* self = new (ELeave) CFreestyleMessageHeaderHTML( aMailMessage, aWriteStream, aVisibleWidth, aScrollPosition, aAutoLoadImages, aExpanded);
    61     CFreestyleMessageHeaderHTML* self = new (ELeave) CFreestyleMessageHeaderHTML( aMailMessage, aWriteStream, aVisibleWidth, aScrollPosition, aAutoLoadImages, aFlags);
    98     self->ConstructL();
    62     self->ConstructL();
    99     return self;
    63     return self;
   100     }
    64     }
   101 
    65 
   102 EXPORT_C void CFreestyleMessageHeaderHTML::ExportL( CFSMailMessage& aMailMessage, 
    66 EXPORT_C void CFreestyleMessageHeaderHTML::ExportL( CFSMailMessage& aMailMessage, 
   103                                                     RWriteStream& aWriteStream, 
    67                                                     RWriteStream& aWriteStream, 
   104                                                     TInt aVisibleWidth,
    68                                                     TInt aVisibleWidth,
   105                                                     TInt aScrollPosition,
    69                                                     TInt aScrollPosition,
   106                                                     const TBool aAutoLoadImages,
    70                                                     const TBool aAutoLoadImages,
   107                                                     const TBool aExpanded )
    71                                                     const TBitFlags& aFlags )
   108     {
    72     {
   109     CFreestyleMessageHeaderHTML* headerHtml = CFreestyleMessageHeaderHTML::NewL( aMailMessage, aWriteStream, aVisibleWidth, aScrollPosition, aAutoLoadImages, aExpanded);
    73     CFreestyleMessageHeaderHTML* headerHtml = CFreestyleMessageHeaderHTML::NewL( aMailMessage, aWriteStream, aVisibleWidth, aScrollPosition, aAutoLoadImages, aFlags);
   110     CleanupStack::PushL( headerHtml );
    74     CleanupStack::PushL( headerHtml );
   111     headerHtml->ExportL();
    75     headerHtml->ExportL();
   112     CleanupStack::PopAndDestroy( headerHtml );
    76     CleanupStack::PopAndDestroy( headerHtml );
   113     }
    77     }
   114 
    78 
   115 EXPORT_C void CFreestyleMessageHeaderHTML::ExportL( CFSMailMessage& aMailMessage, 
    79 EXPORT_C void CFreestyleMessageHeaderHTML::ExportL( CFSMailMessage& aMailMessage, 
   116                                                     RFile& aFile, 
    80                                                     RFile& aFile, 
   117                                                     TInt aVisibleWidth,
    81                                                     TInt aVisibleWidth,
   118                                                     TInt aScrollPosition,
    82                                                     TInt aScrollPosition,
   119                                                     const TBool aAutoLoadImages,
    83                                                     const TBool aAutoLoadImages,
   120                                                     const TBool aExpanded )
    84                                                     const TBitFlags& aFlags )
   121     {
    85     {
   122     RFileWriteStream fwstream;
    86     RFileWriteStream fwstream;
   123     fwstream.Attach( aFile, 0 );
    87     fwstream.Attach( aFile, 0 );
   124     CleanupClosePushL( fwstream );
    88     CleanupClosePushL( fwstream );
   125     
    89     
   126     CFreestyleMessageHeaderHTML* headerHtml = CFreestyleMessageHeaderHTML::NewL( aMailMessage, fwstream, aVisibleWidth, aScrollPosition, aAutoLoadImages, aExpanded );
    90     CFreestyleMessageHeaderHTML* headerHtml = CFreestyleMessageHeaderHTML::NewL( aMailMessage, fwstream, aVisibleWidth, aScrollPosition, aAutoLoadImages, aFlags );
   127     CleanupStack::PushL( headerHtml );
    91     CleanupStack::PushL( headerHtml );
   128     headerHtml->ExportL();
    92     headerHtml->ExportL();
   129     CleanupStack::PopAndDestroy( headerHtml );
    93     CleanupStack::PopAndDestroy( headerHtml );
   130     
    94     
   131     CleanupStack::PopAndDestroy( &fwstream );
    95     CleanupStack::PopAndDestroy( &fwstream );
   135                                                     RFs& aFs, 
    99                                                     RFs& aFs, 
   136                                                     const TPath& aFilePath, 
   100                                                     const TPath& aFilePath, 
   137                                                     TInt aVisibleWidth,
   101                                                     TInt aVisibleWidth,
   138                                                     TInt aScrollPosition,
   102                                                     TInt aScrollPosition,
   139                                                     const TBool aAutoLoadImages,
   103                                                     const TBool aAutoLoadImages,
   140                                                     const TBool aExpanded )
   104                                                     const TBitFlags& aFlags )
   141     {
   105     {
   142     RFileWriteStream fwstream;
   106     RFileWriteStream fwstream;
   143     User::LeaveIfError( fwstream.Replace( aFs, aFilePath, EFileStreamText | EFileWrite) );
   107     User::LeaveIfError( fwstream.Replace( aFs, aFilePath, EFileStreamText | EFileWrite) );
   144     CleanupClosePushL( fwstream );
   108     CleanupClosePushL( fwstream );
   145     
   109     
   146     CFreestyleMessageHeaderHTML* headerHtml = CFreestyleMessageHeaderHTML::NewL( aMailMessage, fwstream, aVisibleWidth, aScrollPosition, aAutoLoadImages, aExpanded);
   110     CFreestyleMessageHeaderHTML* headerHtml = CFreestyleMessageHeaderHTML::NewL( aMailMessage, fwstream, aVisibleWidth, aScrollPosition, aAutoLoadImages, aFlags);
   147     CleanupStack::PushL( headerHtml );
   111     CleanupStack::PushL( headerHtml );
   148     headerHtml->ExportL();
   112     headerHtml->ExportL();
   149     CleanupStack::PopAndDestroy( headerHtml );
   113     CleanupStack::PopAndDestroy( headerHtml );
   150 
   114 
   151     CleanupStack::PopAndDestroy( &fwstream );    
   115     CleanupStack::PopAndDestroy( &fwstream );    
   152     }
   116     }
   153 
   117 
   154 CFreestyleMessageHeaderHTML::~CFreestyleMessageHeaderHTML()
   118 CFreestyleMessageHeaderHTML::~CFreestyleMessageHeaderHTML()
   155     {
   119     {
   156     iAttachments.ResetAndDestroy();
   120     iAttachments.ResetAndDestroy();
   157     }
       
   158 
       
   159 EXPORT_C void CFreestyleMessageHeaderHTML::ExportL() const
       
   160     {
       
   161     HTMLStartL();
       
   162     ExportHTMLHeaderL();
       
   163     ExportHTMLBodyL();
       
   164     HTMLEndL();
       
   165     }
   121     }
   166 
   122 
   167 CFreestyleMessageHeaderHTML::CFreestyleMessageHeaderHTML( CFSMailMessage& aMailMessage,  
   123 CFreestyleMessageHeaderHTML::CFreestyleMessageHeaderHTML( CFSMailMessage& aMailMessage,  
   168                                                           RWriteStream& aWriteStream,
   124                                                           RWriteStream& aWriteStream,
   169                                                           TInt aVisibleWidth,
   125                                                           TInt aVisibleWidth,
   170                                                           TInt aScrollPosition,
   126                                                           TInt aScrollPosition,
   171                                                           const TBool aAutoLoadImages,
   127                                                           const TBool aAutoLoadImages,
   172                                                           const TBool aExpanded )
   128                                                           const TBitFlags& aFlags )
   173     : iMailMessage( aMailMessage ),
   129     : iMailMessage( aMailMessage ),
   174     iWriteStream( aWriteStream ),
   130     iWriteStream( aWriteStream ),
   175     iVisibleWidth( aVisibleWidth - KFreestyleMessageHeaderHTMLRightMarginInPx ),
   131     iVisibleWidth( aVisibleWidth - KFreestyleMessageHeaderHTMLRightMarginInPx ),
   176     iScrollPosition( aScrollPosition ),
   132     iScrollPosition( aScrollPosition ),
   177     iAutoLoadImages( aAutoLoadImages ),
   133     iExportFlags( aFlags )
   178     iMirrorLayout( AknLayoutUtils::LayoutMirrored() ),
   134     {
   179     iExpanded( aExpanded  )
   135     iExportFlags.Assign( EAutoLoadImages, aAutoLoadImages );
   180     {
   136     iExportFlags.Assign( EMirroredLayout, AknLayoutUtils::LayoutMirrored() );
   181     }
   137     }
   182 
   138 
   183 void CFreestyleMessageHeaderHTML::ConstructL()
   139 void CFreestyleMessageHeaderHTML::ConstructL()
   184     {
   140     {
   185     iMailMessage.AttachmentListL( iAttachments );
   141     iMailMessage.AttachmentListL( iAttachments );
   186     }
   142     }
   187 
   143 
   188 void CFreestyleMessageHeaderHTML::HTMLStartL() const
   144 EXPORT_C void CFreestyleMessageHeaderHTML::ExportL() const
   189     {
   145     {
   190     iWriteStream.WriteL(_L8("<html"));
   146     ExportBodyStyleL();
   191     if ( iMirrorLayout )
   147     ExportHTMLBodyStartL();
   192         {
   148     ExportHeaderTablesL();
   193         iWriteStream.WriteL(_L8(" dir=\"rtl\""));
   149     ExportHTMLBodyEndL();    
       
   150     }
       
   151 
       
   152 void CFreestyleMessageHeaderHTML::ExportHTMLBodyStartL() const
       
   153     {
       
   154     _LIT( KHtmlBodyStart, "<html dir=\"%S\" xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<title>Email Header</title>\n<script language=\"javascript\" src=\"header.js\"></script>\n<link rel=\"stylesheet\" type=\"text/css\" href=\"header.css\"/>\n</head>\n<body onLoad = \"init(%d)\">\n" );
       
   155     //_LIT( KHtmlBodyStart, "<html dir=\"%S\" xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<title>Email Header</title>\n<script language=\"javascript\" src=\"header.js\"></script>\n<link rel=\"stylesheet\" type=\"text/css\" href=\"header%d.css\"/>\n</head>\n<body onLoad = \"init(%d)\">\n" );
       
   156     const TPtrC direction(  iExportFlags.IsSet( EMirroredLayout ) ? KRtl() : KLtr() );
       
   157     HBufC* formatBuffer = HBufC::NewLC( KHtmlBodyStart().Length() + direction.Length() + 16 );
       
   158     formatBuffer->Des().Format( KHtmlBodyStart(), &direction, iScrollPosition );
       
   159     //formatBuffer->Des().Format( KHtmlBodyStart(), &direction, Math::Random() % 2, iScrollPosition );
       
   160     HBufC8* utf = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *formatBuffer );
       
   161     CleanupStack::PushL( utf );
       
   162     iWriteStream.WriteL( *utf );
       
   163     CleanupStack::PopAndDestroy( 2 ); // formatBuffer, utf    
       
   164     iWriteStream.CommitL();
       
   165     }
       
   166 
       
   167 void CFreestyleMessageHeaderHTML::ExportInnerTableBeginWithRowBeginL( const TDesC& aTableName, const TInt aColSpan, 
       
   168         const TBool aVisible, const TBitFlags& aFlags ) const
       
   169     {
       
   170     iWriteStream.WriteL( KTableRowBegin() );
       
   171     ExportTableVisibilityParameterL( aTableName, aVisible );
       
   172     ExportInnerTableBeginL( aTableName, aColSpan, aFlags );
       
   173     }
       
   174 
       
   175 
       
   176 void CFreestyleMessageHeaderHTML::ExportInnerTableBeginL( const TDesC& aTableName, const TInt aColSpan, 
       
   177         const TBitFlags& aFlags ) const
       
   178     {
       
   179     _LIT( KHidden, " style=\"display: none;\"");
       
   180     _LIT( KFixed, " class=\"fixed\"");   
       
   181     _LIT( KTableHeader, "<td colspan=\"%d\"><table id=\"%S\" width=\"100%%\"%S%S>\n" );
       
   182     const TPtrC style( aFlags.IsClear( EHidden ) ? KNullDesC() : KHidden() );
       
   183     const TPtrC fixed( aFlags.IsClear( EFixed ) ? KNullDesC() : KFixed() );
       
   184     HBufC* formatBuffer = HBufC::NewLC( KTableHeader().Length() + aTableName.Length() + 16 + style.Length() + fixed.Length() );
       
   185     formatBuffer->Des().Format( KTableHeader(), aColSpan, &aTableName, &style, &fixed );
       
   186     HBufC8* utf = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *formatBuffer );
       
   187     CleanupStack::PushL( utf );
       
   188     iWriteStream.WriteL( *utf );
       
   189     CleanupStack::PopAndDestroy( 2 ); // formatBuffer, utf    
       
   190     }
       
   191 
       
   192 void CFreestyleMessageHeaderHTML::ExportTableVisibilityParameterL( const TDesC& aTableName, const TBitFlags& aFlags ) const
       
   193     {   
       
   194     ExportTableVisibilityParameterL( aTableName, aFlags.IsClear( EHidden ) );
       
   195     }
       
   196 
       
   197 void CFreestyleMessageHeaderHTML::ExportTableVisibilityParameterL( const TDesC& aTableName, const TBool aVisible ) const
       
   198     {   
       
   199     _LIT( KTrue, "true" );
       
   200     _LIT( KFalse, "false" );
       
   201     _LIT( KVisibilityParameter, "<script type=\"text/javascript\">var is_%S_visible=%S;</script>" );
       
   202     const TPtrC visible( aVisible ? KTrue() : KFalse() );
       
   203     HBufC* formatBuffer = HBufC::NewLC( KVisibilityParameter().Length() + aTableName.Length() + visible.Length() );
       
   204     formatBuffer->Des().Format( KVisibilityParameter(), &aTableName, &visible );
       
   205     HBufC8* utf = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *formatBuffer );
       
   206     CleanupStack::PushL( utf );
       
   207     iWriteStream.WriteL( *utf );        
       
   208     CleanupStack::PopAndDestroy( 2 ); // formatBuffer, utf
       
   209     }
       
   210 
       
   211 void CFreestyleMessageHeaderHTML::ExportTableBeginL( const TDesC& aTableName, const TBitFlags& aFlags ) const
       
   212     {   
       
   213     _LIT( KFixed, " class=\"fixed\"");   
       
   214     _LIT( KTableHeader, "<table id=\"%S\" width=\"%dpx\"%S%S>\n" );
       
   215     const TPtrC style( aFlags.IsClear( EHidden ) ? KNullDesC() : KNullDesC() );
       
   216     const TPtrC fixed( aFlags.IsClear( EFixed ) ? KNullDesC() : KFixed() );
       
   217     ExportTableVisibilityParameterL( aTableName, aFlags );   
       
   218     HBufC* formatBuffer = HBufC::NewLC( KTableHeader().Length() + aTableName.Length() + 16 + style.Length() + fixed.Length() );
       
   219     formatBuffer->Des().Format( KTableHeader(), &aTableName, iVisibleWidth, &style, &fixed );
       
   220     HBufC8* utf = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *formatBuffer );
       
   221     CleanupStack::PushL( utf );
       
   222     iWriteStream.WriteL( *utf );
       
   223     CleanupStack::PopAndDestroy( 2 ); // formatBuffer, utf    
       
   224     }
       
   225 
       
   226 void CFreestyleMessageHeaderHTML::ExportInnerTableEndL() const
       
   227     {
       
   228     ExportTableEndL();
       
   229     iWriteStream.WriteL( KTableCellEnd() );
       
   230     }
       
   231 
       
   232 void CFreestyleMessageHeaderHTML::ExportInnerTableEndWithRowEndL() const
       
   233     {
       
   234     ExportInnerTableEndL();
       
   235     iWriteStream.WriteL( KTableRowEnd() );
       
   236     }
       
   237 
       
   238 void CFreestyleMessageHeaderHTML::ExportTableEndL() const
       
   239     {
       
   240     HBufC8* utf = CnvUtfConverter::ConvertFromUnicodeToUtf8L( _L("</table>\n") );
       
   241     CleanupStack::PushL( utf );
       
   242     iWriteStream.WriteL( *utf );
       
   243     CleanupStack::PopAndDestroy(); // utf    
       
   244     }
       
   245 
       
   246 void CFreestyleMessageHeaderHTML::ExportSenderTableRowL( const TBool aCollapsed ) const
       
   247     {
       
   248     _LIT( KStyleExpand, "expand" );
       
   249     _LIT( KStyleCollapse, "collapse" );
       
   250     _LIT( KExpandFunction, "expandHeader(true)" );
       
   251     _LIT( KCollapseFunction, "collapseHeader(true)" );
       
   252     _LIT( KSenderFormat, "<tr><td align=\"%S\" class=\"sender_name\"><div class=\"truncate\">%S</div></td><td valign=\"top\" rowSpan=\"2\" class=\"button_cell\"><button value=\"submit\" onClick=\"%S\" class=\"%S\"></button></td></tr>\n" );
       
   253     const CFSMailAddress* sender( iMailMessage.GetSender() );
       
   254     TPtrC displayName( sender->GetDisplayName() );
       
   255     if ( !displayName.Length() )
       
   256         {
       
   257         displayName.Set( sender->GetEmailAddress() );
       
   258         }
       
   259     const TPtrC function( aCollapsed ? KExpandFunction() : KCollapseFunction() );
       
   260     const TPtrC style( aCollapsed ? KStyleExpand() : KStyleCollapse() );
       
   261     const TPtrC align(  iExportFlags.IsSet( EMirroredLayout ) ? KAlignRight() : KAlignLeft() );
       
   262     HBufC* formatBuffer = HBufC::NewLC( KSenderFormat().Length() + displayName.Length() + align.Length() + function.Length() + style.Length() );
       
   263     formatBuffer->Des().Format( KSenderFormat(), &align, &displayName, &function, &style );
       
   264     HBufC8* utf = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *formatBuffer );
       
   265     CleanupStack::PushL( utf );
       
   266     iWriteStream.WriteL( *utf );
       
   267     CleanupStack::PopAndDestroy( 2 ); // formatBuffer, utf    
       
   268     }
       
   269 
       
   270 void CFreestyleMessageHeaderHTML::ExportSenderAddressTableRowL() const
       
   271     {
       
   272     _LIT( KSenderAddressFormat, "<tr><td colspan=\"2\" align=\"%S\"><div class=\"truncate\"><a class=\"sender_address\" href=\"cmail://from/%S\">%S</a></div></td></tr>\n" );
       
   273     const CFSMailAddress* sender( iMailMessage.GetSender() );
       
   274     const TPtrC emailAddress( sender->GetEmailAddress() );
       
   275     const TPtrC align(  iExportFlags.IsSet( EMirroredLayout ) ? KAlignRight() : KAlignLeft() );
       
   276     HBufC* formatBuffer = HBufC::NewLC( KSenderAddressFormat().Length() + emailAddress.Length() * 2 + align.Length() );
       
   277     formatBuffer->Des().Format( KSenderAddressFormat(), &align, &emailAddress, &emailAddress );
       
   278     HBufC8* utf = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *formatBuffer );
       
   279     CleanupStack::PushL( utf );
       
   280     iWriteStream.WriteL( *utf );
       
   281     CleanupStack::PopAndDestroy( 2 ); // formatBuffer, utf    
       
   282     }
       
   283 
       
   284 void CFreestyleMessageHeaderHTML::ExportLabelTableRowL( const TInt aResourceId, const TInt aColSpan ) const
       
   285     {
       
   286     _LIT( KLabelFormat, "<tr><td align=\"%S\" colspan=\"%d\" class=\"label\">%S</td></tr>\n" );
       
   287     HBufC* labelText = StringLoader::LoadLC( aResourceId );
       
   288     const TPtrC align(  iExportFlags.IsSet( EMirroredLayout ) ? KAlignRight() : KAlignLeft() );
       
   289     HBufC* formatBuffer = HBufC::NewLC( KLabelFormat().Length() + labelText->Length() + align.Length() + 8 );
       
   290     formatBuffer->Des().Format( KLabelFormat(), &align, aColSpan, labelText );
       
   291     HBufC8* utf = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *formatBuffer );
       
   292     CleanupStack::PushL( utf );
       
   293     iWriteStream.WriteL( *utf );
       
   294     CleanupStack::PopAndDestroy( 3 ); // labelText, formatBuffer, utf    
       
   295     }
       
   296 
       
   297 void  CFreestyleMessageHeaderHTML::ExportFromTableRowL() const
       
   298     {
       
   299     ExportLabelTableRowL( R_FREESTYLE_EMAIL_UI_VIEWER_FROM );
       
   300     ExportSenderAddressTableRowL();
       
   301     }
       
   302 
       
   303 void  CFreestyleMessageHeaderHTML::ExportExpandRecipientsL( const TDesC& aType, const TInt aCount ) const
       
   304     {
       
   305     _LIT( KExpandRecipientsFormat, "<tr><td align=\"%S\"><a class=\"recipient\" href=\"cmail://expand_%S/\" onclick=\"handleHeaderDisplay('%S_collapsed','%S_expanded')\">%S</a></td></tr>\n" );
       
   306     HBufC* text =  StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_N_MORE_RECIPIENTS, aCount );
       
   307     const TPtrC align(  iExportFlags.IsSet( EMirroredLayout ) ? KAlignRight() : KAlignLeft() );
       
   308     HBufC* formatBuffer = HBufC::NewLC( KExpandRecipientsFormat().Length() + text->Length() + align.Length() + aType.Length() * 3 );
       
   309     formatBuffer->Des().Format( KExpandRecipientsFormat(), &align, &aType, &aType, &aType, text );
       
   310     HBufC8* utf = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *formatBuffer );
       
   311     CleanupStack::PushL( utf );
       
   312     iWriteStream.WriteL( *utf );
       
   313     CleanupStack::PopAndDestroy( 3 ); // text, formatBuffer, utf    
       
   314     }
       
   315 
       
   316 void  CFreestyleMessageHeaderHTML::ExportExpandAttachmentsL( const TDesC& aType, const TInt aCount ) const
       
   317     {
       
   318     _LIT( KExpandRecipientsFormat, "<td align=\"%S\" class=\"attachment\"><a href=\"cmail://expand_%S/\" onclick=\"handleHeaderDisplay('%S_collapsed','%S_expanded')\">%S</a></td>" );
       
   319     HBufC* text =  StringLoader::LoadLC( R_FSE_VIEWER_ATTACHMENTS_TEXT, aCount );
       
   320     const TPtrC align(  iExportFlags.IsSet( EMirroredLayout ) ? KAlignRight() : KAlignLeft() );
       
   321     HBufC* formatBuffer = HBufC::NewLC( KExpandRecipientsFormat().Length() + text->Length() + align.Length() + aType.Length() * 3 );
       
   322     formatBuffer->Des().Format( KExpandRecipientsFormat(), &align, &aType, &aType, &aType, text );
       
   323     HBufC8* utf = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *formatBuffer );
       
   324     CleanupStack::PushL( utf );
       
   325     iWriteStream.WriteL( *utf );
       
   326     CleanupStack::PopAndDestroy( 3 ); // text, formatBuffer, utf    
       
   327     }
       
   328 
       
   329 void  CFreestyleMessageHeaderHTML::ExportRecipientsTableL( const TDesC& aType, const TInt aLabelResourceId, 
       
   330         const RPointerArray<CFSMailAddress>& aRecipients, const TBool aExpanded ) const
       
   331     {  
       
   332     if ( aRecipients.Count() > 0 )
       
   333         { 
       
   334         TBool innerTableExpanded( aExpanded );
       
   335         TBitFlags flags;
       
   336         flags.Assign( EHidden, iExportFlags.IsClear( EHeaderExpanded ) );
       
   337         _LIT( KTableNameFormat, "%S_table" );
       
   338         HBufC* outerTableName = HBufC::NewLC( KTableNameFormat().Length() + aType.Length() );
       
   339         outerTableName->Des().Format( KTableNameFormat(), &aType );
       
   340         ExportTableBeginL( *outerTableName, flags );
       
   341         CleanupStack::PopAndDestroy(); // outerTableName
       
   342         
       
   343         ExportLabelTableRowL( aLabelResourceId, 2 );
       
   344         const TBool showCollapsed( aRecipients.Count() > KMaxRecipientsShown );
       
   345         TBitFlags tableFlags;
       
   346         tableFlags.Set( EFixed );        
       
   347         if ( showCollapsed )
       
   348             {
       
   349             _LIT( KFormatCollapsed, "%S_collapsed" );
       
   350             HBufC* tableName = HBufC::NewLC( KFormatCollapsed().Length() + 8 );
       
   351             tableName->Des().Format( KFormatCollapsed(), &aType );
       
   352             ExportInnerTableBeginWithRowBeginL( *tableName, 2, !innerTableExpanded, tableFlags );
       
   353             CleanupStack::PopAndDestroy(); // tableName
       
   354             ExportExpandRecipientsL( aType, aRecipients.Count() );        
       
   355             ExportInnerTableEndWithRowEndL();
       
   356             tableFlags.Set( EHidden );
       
   357             }
       
   358         else
       
   359             {
       
   360             innerTableExpanded = ETrue;
       
   361             }
       
   362         _LIT( KFormatExpanded, "%S_expanded" );
       
   363         HBufC* tableName = HBufC::NewLC( KFormatExpanded().Length() + 8 );
       
   364         tableName->Des().Format( KFormatExpanded(), &aType );
       
   365         ExportInnerTableBeginWithRowBeginL( *tableName, 2, innerTableExpanded, tableFlags );
       
   366         CleanupStack::PopAndDestroy(); // tableName
       
   367         ExportRecipientsL( aType, aRecipients );
       
   368         ExportInnerTableEndWithRowEndL();        
       
   369         ExportTableEndL();
       
   370         }
       
   371     }
       
   372 
       
   373 void  CFreestyleMessageHeaderHTML::ExportRecipientsL( const TDesC& aType, 
       
   374         const RPointerArray<CFSMailAddress>& aRecipients) const
       
   375     {
       
   376     _LIT( KRecipientFormat, "<tr><td align=\"%S\"><div class=\"truncate\"><a class=\"recipient\" href=\"cmail://%S/%S\">%S</a></div></td></tr>" );
       
   377     const TPtrC align(  iExportFlags.IsSet( EMirroredLayout ) ? KAlignRight() : KAlignLeft() );
       
   378     for ( TInt i = 0; i < aRecipients.Count(); i++ )
       
   379         {
       
   380         const CFSMailAddress* sender( aRecipients[ i ] );
       
   381         TPtrC displayName( sender->GetDisplayName() );
       
   382         const TPtrC emailAddress( sender->GetEmailAddress() );
       
   383         if ( !displayName.Length() )
       
   384             {
       
   385             displayName.Set( emailAddress );
       
   386             }   
       
   387         HBufC* formatBuffer = HBufC::NewLC( KRecipientFormat().Length() + align.Length() + aType.Length() + emailAddress.Length() + displayName.Length() );
       
   388         formatBuffer->Des().Format( KRecipientFormat(), &align, &aType, &emailAddress, &displayName );
       
   389         HBufC8* utf = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *formatBuffer );
       
   390         CleanupStack::PushL( utf );
       
   391         iWriteStream.WriteL( *utf );
       
   392         CleanupStack::PopAndDestroy( 2 ); // formatBuffer, utf    
       
   393         }
       
   394     }
       
   395 
       
   396 void  CFreestyleMessageHeaderHTML::ExportToTableL() const
       
   397     {
       
   398     ExportRecipientsTableL( _L("to"), R_FREESTYLE_EMAIL_UI_VIEWER_TO, iMailMessage.GetToRecipients(), iExportFlags.IsSet( EToExpanded ) );
       
   399     }
       
   400 
       
   401 void  CFreestyleMessageHeaderHTML::ExportCcTableL() const
       
   402     {
       
   403     ExportRecipientsTableL( _L("cc"), R_FREESTYLE_EMAIL_UI_VIEWER_CC, iMailMessage.GetCCRecipients(), iExportFlags.IsSet( ECcExpanded ) );
       
   404     }
       
   405 
       
   406 void  CFreestyleMessageHeaderHTML::ExportBccTableL() const
       
   407     {
       
   408     ExportRecipientsTableL( _L("bcc"), R_FREESTYLE_EMAIL_UI_VIEWER_BCC, iMailMessage.GetBCCRecipients(), iExportFlags.IsSet( EBccExpanded ) );
       
   409     }
       
   410 
       
   411 void CFreestyleMessageHeaderHTML::ExportDateTimeTableRowL( const TInt aColSpan ) const
       
   412     {
       
   413     _LIT( KDateTimeFormat, "<tr><td colspan=\"%d\" align=\"%S\" class=\"datetime\">%S%S%S</td></tr>\n" );
       
   414     HBufC* dateText = TFsEmailUiUtility::DateTextFromMsgLC( &iMailMessage );
       
   415     HBufC* timeText = TFsEmailUiUtility::TimeTextFromMsgLC( &iMailMessage );
       
   416     const TPtrC align(  iExportFlags.IsSet( EMirroredLayout ) ? KAlignRight() : KAlignLeft() );
       
   417     HBufC* formatBuffer = HBufC::NewLC( KDateTimeFormat().Length() + dateText->Length() + timeText->Length() +  KSentLineDateAndTimeSeparatorText().Length() + align.Length() + 3 );
       
   418     formatBuffer->Des().Format( KDateTimeFormat(), aColSpan, &align, dateText, &KSentLineDateAndTimeSeparatorText(), timeText );
       
   419     HBufC8* utf = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *formatBuffer );
       
   420     CleanupStack::PushL( utf );
       
   421     iWriteStream.WriteL( *utf );
       
   422     CleanupStack::PopAndDestroy( 4 ); // dateText, timeText, formatBuffer, utf   
       
   423     }
       
   424 
       
   425 void CFreestyleMessageHeaderHTML::ExportSubjectTableRowL( const TBool aShowLabel ) const
       
   426     {
       
   427     _LIT( KClassSubject, "subject" );
       
   428     TPtrC subjectClass( KClassSubject() );
       
   429     if ( aShowLabel )
       
   430         {
       
   431         _LIT( KClassSubjectIntended, "subject_intended");
       
   432         ExportLabelTableRowL( R_FREESTYLE_EMAIL_UI_VIEWER_SUBJECT, 2 );
       
   433         subjectClass.Set( KClassSubjectIntended() );
       
   434         }
       
   435     _LIT( KSubjectFormat, "<tr><td align=\"%S\" class=\"%S\">%S</td><td align=\"center\" valign=\"bottom\" width=\"1\">");
       
   436     const TPtrC align(  iExportFlags.IsSet( EMirroredLayout ) ? KAlignRight() : KAlignLeft() );
       
   437     HBufC* subject = SubjectLC();
       
   438     HBufC* formatBuffer = HBufC::NewLC( KSubjectFormat().Length() + align.Length() + subject->Length() + subjectClass.Length() );
       
   439     formatBuffer->Des().Format( KSubjectFormat(), &align, &subjectClass, subject );
       
   440     HBufC8* utf = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *formatBuffer );
       
   441     CleanupStack::PushL( utf );
       
   442     iWriteStream.WriteL( *utf );
       
   443     CleanupStack::PopAndDestroy( 3 ); // subject, formatBuffer, utf
       
   444     ExportMessageIconsL();
       
   445     iWriteStream.WriteL( KTableCellEnd() );
       
   446     iWriteStream.WriteL( KTableRowEnd() );
       
   447     }
       
   448 
       
   449 void CFreestyleMessageHeaderHTML::ExportMessageIconsL() const
       
   450     {
       
   451     _LIT( KPriorityLow, "priority_low" );
       
   452     _LIT( KPriorityHigh, "priority_high" );
       
   453     _LIT( KFollowUp, "follow_up" );
       
   454     _LIT( KFollowUpComplete, "follow_up_complete" );
       
   455     
       
   456     TBool iconShown( EFalse );
       
   457     
       
   458     if ( iMailMessage.IsFlagSet( EFSMsgFlag_Low ) )
       
   459         {
       
   460         ExportIconL( KPriorityLow() );
       
   461         iconShown = ETrue;
       
   462         }
       
   463     else if ( iMailMessage.IsFlagSet( EFSMsgFlag_Important ) )
       
   464         {
       
   465         ExportIconL( KPriorityHigh() );    
       
   466         iconShown = ETrue;
       
   467         }
       
   468     
       
   469     if ( iMailMessage.IsFlagSet( EFSMsgFlag_FollowUp ) )
       
   470         {
       
   471         ExportIconL( KFollowUp() );
       
   472         iconShown = ETrue;
       
   473         }
       
   474     else if ( iMailMessage.IsFlagSet( EFSMsgFlag_FollowUpComplete ) )
       
   475         {
       
   476         ExportIconL( KFollowUpComplete() );    
       
   477         iconShown = ETrue;
       
   478         }
       
   479     if ( iconShown )
       
   480         {
       
   481         iWriteStream.WriteL( _L8("<div class=\"icon_cell\"></div>") );
       
   482         }
       
   483     }
       
   484 
       
   485 void CFreestyleMessageHeaderHTML::ExportHeaderTablesL() const        
       
   486     {
       
   487     ExportCollapsedHeaderTableL();
       
   488     ExportExpandedHeaderTablesL();
       
   489     ExportAttachmentTablesL();
       
   490     ExportDisplayImagesTableL();
       
   491     }
       
   492 
       
   493 void CFreestyleMessageHeaderHTML::ExportCollapsedHeaderTableL() const
       
   494     {
       
   495     TBitFlags flags;
       
   496     flags.Set( EFixed );
       
   497     flags.Assign( EHidden, iExportFlags.IsSet( EHeaderExpanded ) );
       
   498     ExportTableBeginL( _L("header_collapsed"), flags );
       
   499     ExportSenderTableRowL( ETrue );
       
   500     ExportDateTimeTableRowL();
       
   501     ExportTableEndL();
       
   502     flags.Clear( EFixed );
       
   503     ExportTableBeginL( _L("header_collapsed_2"), flags );
       
   504     ExportSubjectTableRowL();
       
   505     ExportTableEndL();
       
   506     iWriteStream.CommitL();
       
   507     }
       
   508 
       
   509 void CFreestyleMessageHeaderHTML::ExportExpandedHeaderTablesL() const
       
   510     {
       
   511     TBitFlags flags;
       
   512     flags.Set( EFixed );
       
   513     flags.Assign( EHidden, iExportFlags.IsClear( EHeaderExpanded ) );
       
   514     ExportTableBeginL( _L("header_expanded"), flags );
       
   515     ExportSenderTableRowL( EFalse );
       
   516     ExportFromTableRowL();
       
   517     ExportTableEndL();
       
   518     ExportToTableL();
       
   519     ExportCcTableL();
       
   520     ExportBccTableL();
       
   521     flags.Clear( EFixed );
       
   522     ExportTableBeginL( _L("header_expanded_2"), flags );
       
   523     ExportDateTimeTableRowL( 2 );
       
   524     ExportSubjectTableRowL();
       
   525     ExportTableEndL();
       
   526     iWriteStream.CommitL();
       
   527     }
       
   528 
       
   529 void CFreestyleMessageHeaderHTML::ExportAttachmentTablesL() const
       
   530     {
       
   531     const TInt attachmentCount( iAttachments.Count() );
       
   532     if ( attachmentCount )
       
   533         {
       
   534         if ( attachmentCount > 1 )
       
   535             {
       
   536             ExportCollapsedAttachmentTableL( iExportFlags.IsSet( EAttachmentExpanded ) );
       
   537             ExportExpandedAttachmentTableL( iExportFlags.IsClear( EAttachmentExpanded ) );
       
   538             }
       
   539         else
       
   540             {
       
   541             ExportExpandedAttachmentTableL( EFalse );        
       
   542             }
       
   543         }
       
   544     }
       
   545 
       
   546 void CFreestyleMessageHeaderHTML::ExportAttachmentIconL() const
       
   547     {    
       
   548     _LIT8( KCellBegin, "<td width=\"1\" valign=\"top\" class=\"attachment\">" );
       
   549     iWriteStream.WriteL( KCellBegin() );
       
   550     _LIT( KAttachment, "attachment" );
       
   551     ExportIconL( KAttachment() );
       
   552     iWriteStream.WriteL( KTableCellEnd() );
       
   553     }
       
   554 
       
   555 void CFreestyleMessageHeaderHTML::ExportCollapsedAttachmentTableL( const TBool aHide ) const
       
   556     {
       
   557     TBitFlags flags;
       
   558     flags.Assign( EHidden, aHide );
       
   559     ExportTableBeginL( _L("attachments_collapsed"), flags );
       
   560     ExportCollapsedAttachmentsTableRowL();
       
   561     ExportTableEndL();
       
   562     }
       
   563 
       
   564 void CFreestyleMessageHeaderHTML::ExportCollapsedAttachmentsTableRowL() const
       
   565     {
       
   566     iWriteStream.WriteL( KTableRowBegin() );
       
   567     ExportAttachmentIconL();
       
   568     ExportExpandAttachmentsL( _L("attachments"), iAttachments.Count() );
       
   569     iWriteStream.WriteL( KTableRowEnd() );
       
   570     }
       
   571 
       
   572 void CFreestyleMessageHeaderHTML::ExportExpandedAttachmentTableL( const TBool aHide ) const
       
   573     {    
       
   574     TBitFlags flags;
       
   575     flags.Assign( EHidden, aHide );
       
   576     ExportTableBeginL( _L("attachments_expanded"), flags );
       
   577     ExportExpandedAttachmentsTableRowsL();
       
   578     ExportTableEndL();
       
   579     }
       
   580 
       
   581 void CFreestyleMessageHeaderHTML::ExportExpandedAttachmentsTableRowsL() const
       
   582     {
       
   583     iWriteStream.WriteL( KTableRowBegin() );
       
   584     ExportAttachmentIconL();
       
   585     ExportAttachmentsL();
       
   586     iWriteStream.WriteL( KTableRowEnd() );
       
   587     }
       
   588 
       
   589 void CFreestyleMessageHeaderHTML::ExportAttachmentsL() const
       
   590     {
       
   591     ExportInnerTableBeginL( _L("_attachments_expanded"), 1 );
       
   592     for ( TInt i = 0; i < iAttachments.Count(); i++ )
       
   593         {
       
   594         ExportAttachmentL( *iAttachments[ i ] );
       
   595         }
       
   596     ExportInnerTableEndL();
       
   597     }
       
   598 
       
   599 void CFreestyleMessageHeaderHTML::ExportAttachmentL( CFSMailMessagePart& aAttachment ) const
       
   600     {
       
   601     _LIT( KAttachmentFormat, "<tr><td align=\"%S\" class=\"attachment\"><a href=\"cmail://attachment/%d\">%S (%S)</a></td></tr>\n" );
       
   602     const TPtrC align(  iExportFlags.IsSet( EMirroredLayout ) ? KAlignRight() : KAlignLeft() );
       
   603     HBufC* size = TFsEmailUiUtility::CreateSizeDescLC( aAttachment.ContentSize(), EFalse );
       
   604     const TPtrC attachmentName( aAttachment.AttachmentNameL() );
       
   605     HBufC* formatBuffer = HBufC::NewLC( KAttachmentFormat().Length() + align.Length() + size->Length() + attachmentName.Length() + 16 );
       
   606     formatBuffer->Des().Format( KAttachmentFormat(), &align, aAttachment.GetPartId().Id(), &attachmentName, size );
       
   607     HBufC8* utf = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *formatBuffer );
       
   608     CleanupStack::PushL( utf );
       
   609     iWriteStream.WriteL( *utf );
       
   610     CleanupStack::PopAndDestroy( 3 ); // size, formatBuffer, utf
       
   611     }
       
   612 
       
   613 void CFreestyleMessageHeaderHTML::ExportIconL( const TDesC& aIconName ) const
       
   614     {
       
   615     _LIT( KMessageIconFormat, "<img src=\"%S.png\" class=\"icon\"/>" );
       
   616     HBufC* formatBuffer = HBufC::NewLC( KMessageIconFormat().Length() + aIconName.Length() );
       
   617     formatBuffer->Des().Format( KMessageIconFormat(), &aIconName );
       
   618     HBufC8* utf = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *formatBuffer );
       
   619     CleanupStack::PushL( utf );
       
   620     iWriteStream.WriteL( *utf );
       
   621     CleanupStack::PopAndDestroy( 2 ); // formatBuffer, utf
       
   622     }
       
   623 
       
   624 HBufC* CFreestyleMessageHeaderHTML::SubjectLC() const
       
   625     {
       
   626     return CreateLinksLC( iMailMessage.GetSubject(), CFindItemEngine::EFindItemSearchURLBin );
       
   627     }
       
   628 
       
   629 TInt CFreestyleMessageHeaderHTML::CalculateTotalSpaceRequired( const TDesC& aText, 
       
   630         CFindItemEngine& aItemEngine, TInt& aMaxLength ) const
       
   631     {
       
   632     TInt totalLength( 0 );
       
   633     aMaxLength = KMinTInt;
       
   634     CFindItemEngine::SFoundItem item;
       
   635     aItemEngine.ResetPosition();
       
   636     for ( TBool available( aItemEngine.Item( item ) ); available; available = aItemEngine.NextItem( item ) )
       
   637         {
       
   638         totalLength += item.iLength;
       
   639         if ( item.iItemType == CFindItemEngine::EFindItemSearchURLBin )
       
   640             {
       
   641             const TPtrC url( aText.Mid( item.iStartPos, item.iLength ) );
       
   642             if (  url.FindF( KSchemeSeparator() ) == KErrNotFound )
       
   643                 {
       
   644                 totalLength += KUrlFormatWithHttp().Length();
       
   645                 }
       
   646             else
       
   647                 {
       
   648                 totalLength += KUrlFormat().Length();        
       
   649                 }
       
   650             aMaxLength = ( aMaxLength < item.iLength ) ? item.iLength : aMaxLength;
       
   651             }
       
   652         }
       
   653     aItemEngine.ResetPosition();
       
   654     return totalLength;
       
   655     }
       
   656 
       
   657 HBufC* CFreestyleMessageHeaderHTML::CreateLinksLC( const TDesC& aText, const TInt aSearchCases ) const
       
   658     {
       
   659     HBufC* result = NULL;
       
   660     CFindItemEngine* itemEngine = CFindItemEngine::NewL( aText, 
       
   661             CFindItemEngine::TFindItemSearchCase( aSearchCases ) );
       
   662     CleanupStack::PushL ( itemEngine );
       
   663     if ( itemEngine->ItemCount() > 0 )
       
   664         {
       
   665         RBuf buf;
       
   666         TInt maxLength;
       
   667         buf.CreateL( CalculateTotalSpaceRequired( aText, *itemEngine, maxLength ) + aText.Length() );
       
   668         buf.CleanupClosePushL();
       
   669         TInt currentReadPosition( 0 );
       
   670         CFindItemEngine::SFoundItem item;
       
   671         HBufC* urlBuffer = HBufC::NewLC( KUrlFormatWithHttp().Length() + maxLength * 2 );
       
   672         for ( TBool available( itemEngine->Item( item ) ); available; available = itemEngine->NextItem( item ) )
       
   673             {
       
   674             // Append characters from currentReadPosition to iStartPos
       
   675             buf.Append( aText.Mid( currentReadPosition, item.iStartPos - currentReadPosition ) );
       
   676             const TPtrC url( aText.Mid( item.iStartPos, item.iLength ) );
       
   677             TPtrC format( KUrlFormat() );
       
   678             if ( url.FindF( KSchemeSeparator() ) == KErrNotFound )
       
   679                 {
       
   680                 format.Set( KUrlFormatWithHttp() );
       
   681                 }
       
   682             urlBuffer->Des().Format( format, &url, &url );
       
   683             buf.Append( *urlBuffer );
       
   684             currentReadPosition = item.iStartPos + item.iLength;
       
   685             }
       
   686         CleanupStack::PopAndDestroy(); // urlBuffer
       
   687         // Append characters that are left in buffer
       
   688         buf.Append( aText.Mid( currentReadPosition ) );
       
   689         result = buf.AllocL();
       
   690         CleanupStack::PopAndDestroy(); // buf.Close()
   194         }
   691         }
   195     else
   692     else
   196         {
   693         {
   197         iWriteStream.WriteL(_L8(" dir=\"ltr\""));
   694         result = aText.AllocL();
   198         }
   695         }
   199     iWriteStream.WriteL(_L8(" xmlns=\"http://www.w3.org/1999/xhtml\">\n"));
   696     CleanupStack::PopAndDestroy( itemEngine );
       
   697     CleanupStack::PushL( result );
       
   698     return result;
       
   699     }
       
   700 
       
   701 void CFreestyleMessageHeaderHTML::ExportHTMLBodyEndL() const
       
   702     {
       
   703     iWriteStream.WriteL( _L8("</body>\n</html>\n") );
   200     iWriteStream.CommitL();
   704     iWriteStream.CommitL();
   201     }
   705     }
   202 
   706 
   203 void CFreestyleMessageHeaderHTML::HTMLEndL() const
       
   204     {
       
   205     iWriteStream.WriteL(_L8("</html>\n"));
       
   206     iWriteStream.CommitL();
       
   207     }
       
   208 
       
   209 void CFreestyleMessageHeaderHTML::ExportHTMLHeaderL() const
       
   210     {
       
   211     HTMLHeaderStartL();
       
   212     HTMLMetaL();
       
   213     iWriteStream.WriteL( _L8("<title>Email Header</title>\n") );
       
   214     AddJavascriptL();
       
   215     AddStyleSheetL();
       
   216     HTMLHeaderEndL();
       
   217     }
       
   218 
       
   219 void CFreestyleMessageHeaderHTML::HTMLHeaderStartL() const
       
   220     {
       
   221     iWriteStream.WriteL(_L8("<head>"));
       
   222     iWriteStream.CommitL();
       
   223     }
       
   224 
       
   225 void CFreestyleMessageHeaderHTML::HTMLMetaL() const
       
   226     {
       
   227     // Html file representing email header fields, is always constructed locally
       
   228     // in the phone, and it is always of charset UTF-8 irrespective of what
       
   229     // the email html-format body is
       
   230     iWriteStream.WriteL( KMetaHeader );
       
   231     iWriteStream.CommitL();
       
   232     }
       
   233 
       
   234 void CFreestyleMessageHeaderHTML::HTMLHeaderEndL() const
       
   235     {
       
   236     iWriteStream.WriteL(_L8("</head>\n"));
       
   237     iWriteStream.CommitL();
       
   238     }
       
   239 
       
   240 void CFreestyleMessageHeaderHTML::ExportHTMLBodyL() const
       
   241     {
       
   242     HTMLBodyStartL();
       
   243     ExportCollapsedHeaderTableL();
       
   244     ExportExpandedHeaderTableL();
       
   245     ExportAttachmentsL();
       
   246     ExportDisplayImagesTableL();
       
   247     HTMLBodyEndL();
       
   248     }
       
   249 
       
   250 void CFreestyleMessageHeaderHTML::ExportDisplayImagesTableL() const
   707 void CFreestyleMessageHeaderHTML::ExportDisplayImagesTableL() const
   251     {
   708     {
   252     if (!iAutoLoadImages)
   709     _LIT( KDisplayImagesLeftToRight,
   253         {
   710             "<script language=\"javascript\">var g_autoLoadImages = %d;</script><table style=\"display: none\" id=\"displayImagesTable\" width=\"%dpx\"><tr><td align=\"left\">%S</td><td align=\"right\"><button value=\"submit\" class=\"submitBtn\" onClick=\"displayImagesButtonPressed()\"><span><span class=\"buttonText\">%S</span></span></button></td></tr></table>" );
   254         _LIT8(KDescription, "");
   711     
   255         //_LIT8(KButton, "Display images");
   712     _LIT( KDisplayImagesRightToLeft,
   256         HBufC8* description = KDescription().AllocLC(); //HeadingTextLC(R_FREESTYLE_EMAIL_UI_IMAGES_ARE_NOT_DISPLAYED);
   713             "<script language=\"javascript\">var g_autoLoadImages = %d;</script><table style=\"display: none\" id=\"displayImagesTable\" width=\"%dpx\"><tr><td align=\"left\"><button value=\"submit\" class=\"submitBtn\" onClick=\"displayImagesButtonPressed()\"><span><span class=\"buttonText\">%S</span></span></button></td><td align=\"right\">%S</td></tr></table>" );
   257         HBufC8* button = HeadingTextLC(R_FREESTYLE_EMAIL_UI_DISPLAY_IMAGES); // KButton().AllocLC();
   714 
   258         HBufC8* formatBuffer = NULL;
   715     if ( iExportFlags.IsClear( EAutoLoadImages ) )
   259         if (iMirrorLayout)
   716         {
   260             {
   717         _LIT(KDescription, "");
   261             formatBuffer = HBufC8::NewLC(KDisplayImagesRightToLeft().Length() + description->Length() + button->Length() + 8);
   718         HBufC* description = KDescription().AllocLC(); //StringLoader::LoadLC(R_FREESTYLE_EMAIL_UI_IMAGES_ARE_NOT_DISPLAYED);
       
   719         HBufC* button = StringLoader::LoadLC(R_FREESTYLE_EMAIL_UI_DISPLAY_IMAGES);
       
   720         HBufC* formatBuffer = NULL;
       
   721         if ( iExportFlags.IsSet( EMirroredLayout ) )
       
   722             {
       
   723             formatBuffer = HBufC::NewLC(KDisplayImagesRightToLeft().Length() + description->Length() + button->Length() + 8);
   262             formatBuffer->Des().Format(
   724             formatBuffer->Des().Format(
   263                     KDisplayImagesRightToLeft(),
   725                     KDisplayImagesRightToLeft(),
   264                     iAutoLoadImages,
   726                     EFalse,
   265                     iVisibleWidth,
   727                     iVisibleWidth,
   266                     button,
   728                     button,
   267                     description);
   729                     description);
   268             }
   730             }
   269         else
   731         else
   270             {
   732             {
   271             formatBuffer = HBufC8::NewLC(KDisplayImagesLeftToRight().Length() + description->Length() + button->Length() + 8);
   733             formatBuffer = HBufC::NewLC(KDisplayImagesLeftToRight().Length() + description->Length() + button->Length() + 8);
   272             formatBuffer->Des().Format(
   734             formatBuffer->Des().Format(
   273                     KDisplayImagesLeftToRight(),
   735                     KDisplayImagesLeftToRight(),
   274                     iAutoLoadImages,
   736                     EFalse,
   275                     iVisibleWidth,
   737                     iVisibleWidth,
   276                     description,
   738                     description,
   277                     button);
   739                     button);
   278             }
   740             }
   279         iWriteStream.WriteL(*formatBuffer);
   741         HBufC8* utf = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *formatBuffer );
   280         CleanupStack::PopAndDestroy(3); // description, button, formatBuffer
   742         CleanupStack::PushL( utf );
       
   743         iWriteStream.WriteL( *utf );
       
   744         CleanupStack::PopAndDestroy( 4 ); // description, button, formatBuffer, utf
   281         iWriteStream.CommitL();
   745         iWriteStream.CommitL();
   282         }
   746         }
   283     }
   747     }
   284 
   748 
   285 void CFreestyleMessageHeaderHTML::HTMLBodyStartL() const
   749 void CFreestyleMessageHeaderHTML::ExportBodyStyleL() const
   286     {
   750     {
   287     TBuf8<KFreestyleMessageHeaderHTMLRightMarginInPx> scrollPos;
       
   288     scrollPos.AppendNum(iScrollPosition);
       
   289     iWriteStream.WriteL(_L8("<body onLoad = \"init("));
       
   290     iWriteStream.WriteL(scrollPos);
       
   291     iWriteStream.WriteL(_L8(")\">\n"));
       
   292     iWriteStream.CommitL();
       
   293     }
       
   294 
       
   295 void CFreestyleMessageHeaderHTML::ExportCollapsedHeaderTableL() const
       
   296     {
       
   297     StartHeaderTableL( KCollapsedHeaderTableName, !iExpanded );
       
   298     ExportTimeAndExpandButtonL();
       
   299     ExportSubjectCollapsedL();
       
   300     EndHeaderTableL();
       
   301     }
       
   302 
       
   303 void CFreestyleMessageHeaderHTML::ExportExpandedHeaderTableL() const
       
   304     {
       
   305     StartHeaderTableL( KExpandedHeaderTableName, iExpanded );
       
   306     ExportCollapseButtonL();
       
   307     ExportFromL();
       
   308     ExportToL();
       
   309     ExportCcL();
       
   310     ExportBccL();
       
   311     ExportSentTimeL();
       
   312     ExportSubjectL();
       
   313     EndHeaderTableL();
       
   314     }
       
   315 
       
   316 // -----------------------------------------------------------------------------
       
   317 // CFreestyleMessageHeaderHTML::WriteSubjectL
       
   318 // Writes the subject to iWriteStream and also
       
   319 // takes care of the urls and marks them as hotspots
       
   320 // -----------------------------------------------------------------------------
       
   321 //
       
   322 void CFreestyleMessageHeaderHTML::WriteSubjectL(TDesC& aText ) const
       
   323     {
       
   324     /* 
       
   325     * Add these to searchcases to make it also search 
       
   326     * for emailaddress and phonenumber :
       
   327     * CFindItemEngine::EFindItemSearchMailAddressBin |
       
   328     * CFindItemEngine::EFindItemSearchPhoneNumberBin |
       
   329     */
       
   330     // Search for urls    
       
   331     TInt searchCases = CFindItemEngine::EFindItemSearchURLBin;
       
   332                        
       
   333     CFindItemEngine* itemEngine =
       
   334               CFindItemEngine::NewL ( aText,
       
   335                        ( CFindItemEngine::TFindItemSearchCase ) searchCases );
       
   336     CleanupStack::PushL (itemEngine );
       
   337 
       
   338     const CArrayFixFlat<CFindItemEngine::SFoundItem>
       
   339             * foundItems = itemEngine->ItemArray ( );
       
   340     
       
   341     TInt index = 0;
       
   342     // For each found item
       
   343     for (TInt i=0; i<foundItems->Count ( ); ++i )
       
   344         {
       
   345         // iItemType, iStartPos, iLength
       
   346         const CFindItemEngine::SFoundItem& item = foundItems->At (i );
       
   347         HBufC* valueBuf = aText.Mid (item.iStartPos, item.iLength ).AllocL ( );
       
   348         CleanupStack::PushL (valueBuf );
       
   349         // We write the normal text to iWriteStream before and between the links in the header subject field
       
   350         if(item.iStartPos > 0)
       
   351             {
       
   352             TInt itemstart = item.iStartPos;
       
   353             HBufC* normalText = aText.Mid(index, itemstart-index).Alloc();
       
   354             CleanupStack::PushL( normalText );
       
   355             HBufC8* normalText8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *normalText );
       
   356             CleanupStack::PushL( normalText8 );
       
   357             iWriteStream.WriteL( *normalText8 );
       
   358             CleanupStack::PopAndDestroy( 2 ); //normalText8m, normalText
       
   359             }        
       
   360         switch (item.iItemType )
       
   361             {
       
   362             /* To make header subjectfield to recognise also phonenumber and emailadress just 
       
   363              * add CFindItemEngine::EFindItemSearchMailAddressBin & 
       
   364              * CFindItemEngine::EFindItemSearchPhoneNumberBin cases here.
       
   365              */
       
   366             case CFindItemEngine::EFindItemSearchURLBin:
       
   367                 {
       
   368                 HBufC8* url8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *valueBuf );
       
   369                 CFreestyleMessageHeaderURL *fsurl = FreestyleMessageHeaderURLFactory::CreateEmailSubjectUrlL(*valueBuf);
       
   370                 delete fsurl;
       
   371                 CleanupStack::PushL( url8 );
       
   372                 StartHyperlinkL(*url8);
       
   373                 iWriteStream.WriteL(*url8);
       
   374                 EndHyperlinkL();
       
   375                 CleanupStack::PopAndDestroy( url8 );
       
   376 
       
   377                 break;
       
   378                 }
       
   379             default:
       
   380                 {
       
   381                 break;
       
   382                 }
       
   383             }        
       
   384         index = item.iStartPos+item.iLength;
       
   385         CleanupStack::PopAndDestroy (valueBuf );
       
   386         }
       
   387         //Write the rest of the subject to subject field if we are not 
       
   388         //at the end of the subject already, or if there wasn't any
       
   389         //url items write the whole subject field here
       
   390         if(index < aText.Length() )
       
   391             {
       
   392             HBufC* normalText = aText.Mid(index, aText.Length()-index).Alloc();
       
   393             CleanupStack::PushL( normalText );
       
   394             HBufC8* normalText8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *normalText );
       
   395             CleanupStack::PushL( normalText8 );
       
   396             iWriteStream.WriteL( *normalText8 );
       
   397             CleanupStack::PopAndDestroy( 2 ); //normalText8m, normalText
       
   398             }
       
   399     CleanupStack::PopAndDestroy (itemEngine );
       
   400     }
       
   401 
       
   402 HBufC8* CFreestyleMessageHeaderHTML::HTMLHeaderFollowUpIconLC( TBool aShowText ) const
       
   403     {
       
   404     HBufC8* followUpText8( NULL );
       
   405     HBufC8* followUpCompletedText8( NULL );
       
   406         
       
   407     // Reserve space with worst case scenario in mind. 
       
   408     TInt textLength( 0 );
       
   409     if ( aShowText )
       
   410         {
       
   411         // Follow up completed.
       
   412         HBufC* followUpCompletedText = StringLoader::LoadLC( 
       
   413                 R_FREESTYLE_EMAIL_UI_VIEWER_COMPLETED );
       
   414         followUpCompletedText8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( 
       
   415                 *followUpCompletedText );
       
   416         CleanupStack::PopAndDestroy( followUpCompletedText );
       
   417         CleanupStack::PushL( followUpCompletedText8 );
       
   418         
       
   419         // Follow up.
       
   420         HBufC* followUpText = StringLoader::LoadLC( 
       
   421                 R_FREESTYLE_EMAIL_UI_VIEWER_FOLLOWUP );
       
   422         followUpText8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( 
       
   423                 *followUpText );
       
   424         CleanupStack::PopAndDestroy( followUpText );
       
   425         CleanupStack::PushL( followUpText8 );
       
   426     
       
   427         textLength += KHTMLImgTagId().Length() +
       
   428                       KFollowUpCompleteImageName().Length() +
       
   429                       KHTMLImgTagSrcBefore().Length() +
       
   430                       KFollowUpCompleteIconFileName().Length() +
       
   431                       KHTMLImgTagSrcAfter().Length() +
       
   432                       ( followUpText8->Length() >= followUpCompletedText8->Length() ?
       
   433                       followUpText8->Length() : followUpCompletedText8->Length() ); 
       
   434         }
       
   435     else
       
   436         {
       
   437         // Plain icon and no text.
       
   438         textLength += KHTMLImgTagId().Length() + 
       
   439                       KFollowUpCompleteImageName().Length() +
       
   440                       KHTMLImgTagSrcBefore().Length() +
       
   441                       KFollowUpCompleteIconFileName().Length() +
       
   442                       KHTMLImgTagSrcAfter().Length();
       
   443         }
       
   444 
       
   445     // Allocate space.
       
   446     HBufC8* iconText8 = HBufC8::NewLC( textLength );    
       
   447         
       
   448     // Generate HTML code
       
   449     TPtr8 iconPtr( iconText8->Des() );
       
   450         
       
   451     if ( iMailMessage.IsFlagSet( EFSMsgFlag_FollowUp ) )
       
   452         {
       
   453         iconPtr.Append( KHTMLImgTagId );
       
   454         iconPtr.Append( KFollowUpImageName );
       
   455         iconPtr.Append( KHTMLImgTagSrcBefore );
       
   456         iconPtr.Append( KFollowUpIconFileName );
       
   457         iconPtr.Append( KHTMLImgTagSrcAfter );
       
   458         if ( aShowText && followUpText8 )
       
   459             {
       
   460             iconPtr.Append( followUpText8->Des() );
       
   461             }
       
   462         }
       
   463     else if ( iMailMessage.IsFlagSet( EFSMsgFlag_FollowUpComplete ) )
       
   464         {
       
   465         iconPtr.Append( KHTMLImgTagId );
       
   466         iconPtr.Append( KFollowUpCompleteImageName );
       
   467         iconPtr.Append( KHTMLImgTagSrcBefore );
       
   468         iconPtr.Append( KFollowUpCompleteIconFileName );
       
   469         iconPtr.Append( KHTMLImgTagSrcAfter );
       
   470         if ( aShowText && followUpCompletedText8 )
       
   471             {
       
   472             iconPtr.Append( followUpCompletedText8->Des() );
       
   473             }
       
   474         }
       
   475     else
       
   476         {
       
   477         // No follow up flag set.
       
   478         CleanupStack::PopAndDestroy( iconText8 );
       
   479         iconText8 = NULL;
       
   480         }
       
   481 
       
   482     if ( aShowText )
       
   483         {
       
   484         if ( iconText8 )
       
   485             {
       
   486             CleanupStack::Pop( iconText8 );
       
   487             }
       
   488         CleanupStack::PopAndDestroy( followUpText8 );
       
   489         CleanupStack::PopAndDestroy( followUpCompletedText8 );
       
   490         if ( iconText8 )
       
   491             {
       
   492             CleanupStack::PushL( iconText8 );
       
   493             }
       
   494         }
       
   495     
       
   496     return iconText8;
       
   497     }
       
   498 
       
   499 HBufC8* CFreestyleMessageHeaderHTML::HTMLHeaderPriorityIconLC( TBool aShowText ) const
       
   500     {
       
   501     HBufC8* highPrioText8( NULL );
       
   502     HBufC8* lowPrioText8( NULL );
       
   503         
       
   504     // Reserve space with worst case scenario in mind. 
       
   505     TInt textLength( 0 );
       
   506     if ( aShowText )
       
   507         {
       
   508         // High priority.
       
   509         HBufC* highPrioText = StringLoader::LoadLC( 
       
   510                 R_FREESTYLE_EMAIL_UI_VIEWER_HIGH_PRIO );
       
   511         highPrioText8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( 
       
   512                 *highPrioText );
       
   513         CleanupStack::PopAndDestroy( highPrioText );
       
   514         CleanupStack::PushL( highPrioText8 );
       
   515     
       
   516         // Low priority.
       
   517         HBufC* lowPrioText = StringLoader::LoadLC( 
       
   518                 R_FREESTYLE_EMAIL_UI_VIEWER_LOW_PRIO );
       
   519         lowPrioText8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( 
       
   520                 *lowPrioText );
       
   521         CleanupStack::PopAndDestroy( lowPrioText );
       
   522         CleanupStack::PushL( lowPrioText8 );
       
   523             
       
   524         textLength += KHTMLImgTagId().Length() +
       
   525                       KPriorityHighImageName().Length() +
       
   526                       KHTMLImgTagSrcBefore().Length() +
       
   527                       KPriorityHighIconFileName().Length() +
       
   528                       KHTMLImgTagSrcAfter().Length() +
       
   529                       ( lowPrioText8->Length() >= highPrioText8->Length() ?
       
   530                       lowPrioText8->Length() : highPrioText8->Length() ); 
       
   531         }
       
   532     else
       
   533         {
       
   534         // Plain icon and no text.
       
   535         textLength += KHTMLImgTagId().Length() + 
       
   536                       KPriorityHighImageName().Length() +
       
   537                       KHTMLImgTagSrcBefore().Length() +
       
   538                       KPriorityHighIconFileName().Length() +
       
   539                       KHTMLImgTagSrcAfter().Length();
       
   540         }
       
   541 
       
   542     // Allocate space.
       
   543     HBufC8* iconText8 = HBufC8::NewLC( textLength );    
       
   544         
       
   545     // Generate HTML code
       
   546     TPtr8 iconPtr( iconText8->Des() );
       
   547         
       
   548     if ( iMailMessage.IsFlagSet( EFSMsgFlag_Low ) )
       
   549         {
       
   550         iconPtr.Append( KHTMLImgTagId );
       
   551         iconPtr.Append( KPriorityLowImageName );
       
   552         iconPtr.Append( KHTMLImgTagSrcBefore );
       
   553         iconPtr.Append( KPriorityLowIconFileName );
       
   554         iconPtr.Append( KHTMLImgTagSrcAfter );
       
   555         if ( aShowText && lowPrioText8 )
       
   556             {
       
   557             iconPtr.Append( lowPrioText8->Des() );
       
   558             }
       
   559         }
       
   560     else if ( iMailMessage.IsFlagSet( EFSMsgFlag_Important ) )
       
   561         {
       
   562         iconPtr.Append( KHTMLImgTagId );
       
   563         iconPtr.Append( KPriorityHighImageName );
       
   564         iconPtr.Append( KHTMLImgTagSrcBefore );
       
   565         iconPtr.Append( KPriorityHighIconFileName );
       
   566         iconPtr.Append( KHTMLImgTagSrcAfter );
       
   567         if ( aShowText && highPrioText8 )
       
   568             {
       
   569             iconPtr.Append( highPrioText8->Des() );
       
   570             }
       
   571         }
       
   572     else
       
   573         {
       
   574         // No priority flag set.
       
   575         CleanupStack::PopAndDestroy( iconText8 );
       
   576         iconText8 = NULL;
       
   577         }
       
   578 
       
   579     if ( aShowText )
       
   580         {
       
   581         if ( iconText8 )
       
   582             {
       
   583             CleanupStack::Pop( iconText8 );
       
   584             }
       
   585         CleanupStack::PopAndDestroy( lowPrioText8 );
       
   586         CleanupStack::PopAndDestroy( highPrioText8 );
       
   587         if ( iconText8 )
       
   588             {
       
   589             CleanupStack::PushL( iconText8 );
       
   590             }
       
   591         }
       
   592     
       
   593     return iconText8;
       
   594     }
       
   595 
       
   596 void CFreestyleMessageHeaderHTML::HTMLBodyEndL() const
       
   597     {
       
   598     iWriteStream.WriteL(_L8("</body>\n"));
       
   599     iWriteStream.CommitL();
       
   600     }
       
   601 
       
   602 void CFreestyleMessageHeaderHTML::ExportCollapseButtonL() const
       
   603     {
       
   604     TBuf8<KFreestyleMessageHeaderHTMLMaxBufferSizeForWidth> tableWidth;
       
   605     tableWidth.AppendNum( iVisibleWidth );
       
   606 
       
   607     // Add "Collapse" button as its own table with its own width
       
   608     iWriteStream.WriteL( _L8("<tr><td>\n") );
       
   609     iWriteStream.WriteL( _L8("<table id =\"table_minus_icon\" border=\"0\" width=\"") );
       
   610     iWriteStream.WriteL( tableWidth );
       
   611     iWriteStream.WriteL( _L8("px\">\n") );
       
   612     iWriteStream.WriteL( _L8("<tr>\n") );
       
   613 
       
   614     iWriteStream.WriteL( _L8("<td valign=\"top\"") );
       
   615     if ( !iMirrorLayout )
       
   616         {
       
   617         iWriteStream.WriteL( _L8(" align=\"right\"") );
       
   618         iWriteStream.WriteL( _L8(" style=\"padding-right: 10px;\">\n") );
       
   619         }
       
   620     else
       
   621         {
       
   622         iWriteStream.WriteL( _L8(" align=\"left\"") );
       
   623         iWriteStream.WriteL( _L8(" style=\"padding-left: 10px;\">\n") );
       
   624         }
       
   625     iWriteStream.WriteL( _L8("<input type=\"submit\" id=\"collapse\" value=\"\" class=\"collapse\"") );
       
   626     iWriteStream.WriteL( _L8(" onClick=\"collapseHeader(true)\"/>") );
       
   627     iWriteStream.WriteL( _L8("</td>\n") );
       
   628 
       
   629     iWriteStream.WriteL( _L8("</tr>\n"));
       
   630     iWriteStream.WriteL( _L8("</table></td></tr>\n"));
       
   631     iWriteStream.CommitL();
       
   632     }
       
   633 
       
   634 void CFreestyleMessageHeaderHTML::ExportTimeAndExpandButtonL() const
       
   635     {
       
   636     // set the width, using the visible screen width
       
   637     TBuf8<KFreestyleMessageHeaderHTMLMaxBufferSizeForWidth> tableWidth;
       
   638     tableWidth.AppendNum( iVisibleWidth );
       
   639 
       
   640     // start first row: table with the sent info and the '+' icon
       
   641     iWriteStream.WriteL(_L8("<tr><td><table id=\"table_sent_and_plus\" border=\"0\" width=\""));
       
   642     iWriteStream.WriteL( tableWidth );
       
   643     iWriteStream.WriteL( _L8("px\">\n"));
       
   644     
       
   645     iWriteStream.WriteL(_L8("<tr>\n"));
       
   646     
       
   647     // add Sent time and date
       
   648     iWriteStream.WriteL(_L8("<td id=\"sent_initial\""));
       
   649 
       
   650     if ( !iMirrorLayout )
       
   651         {
       
   652         iWriteStream.WriteL(_L8(" align=\"left\""));
       
   653         }
       
   654     else
       
   655         {
       
   656         iWriteStream.WriteL(_L8(" align=\"right\""));
       
   657         }
       
   658     iWriteStream.WriteL(_L8(" valign=\"bottom\">"));
       
   659     
       
   660     HBufC* dateText = TFsEmailUiUtility::DateTextFromMsgLC( &iMailMessage );
       
   661     HBufC* timeText = TFsEmailUiUtility::TimeTextFromMsgLC( &iMailMessage );
       
   662 
       
   663     TInt len = dateText->Length() + KSentLineDateAndTimeSeparatorText().Length() + timeText->Length();
       
   664     HBufC* sentTimeText = HBufC::NewLC( len );
       
   665     TPtr sentTimeTextPtr = sentTimeText->Des();
       
   666     sentTimeTextPtr.Append( *dateText );
       
   667     sentTimeTextPtr.Append( KSentLineDateAndTimeSeparatorText );
       
   668     sentTimeTextPtr.Append( *timeText );
       
   669     HBufC8* sentTimeText8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( sentTimeTextPtr );
       
   670     CleanupStack::PushL( sentTimeText8 );
       
   671     iWriteStream.WriteL( *sentTimeText8 );
       
   672     CleanupStack::PopAndDestroy( sentTimeText8 );
       
   673     CleanupStack::PopAndDestroy( sentTimeText );
       
   674     CleanupStack::PopAndDestroy( timeText );
       
   675     CleanupStack::PopAndDestroy( dateText );
       
   676     
       
   677     iWriteStream.WriteL(_L8("</td>\n"));
       
   678 
       
   679     // Add "expand" button on the same line as Sent time and date
       
   680     iWriteStream.WriteL(_L8("<td valign=\"top\""));
       
   681     if ( !iMirrorLayout )
       
   682         {
       
   683         iWriteStream.WriteL(_L8(" align=\"right\""));
       
   684         iWriteStream.WriteL(_L8(" style=\"padding-right: 10px;\">\n"));
       
   685         }
       
   686     else
       
   687         {
       
   688         iWriteStream.WriteL(_L8(" align=\"left\""));
       
   689         iWriteStream.WriteL(_L8(" style=\"padding-left: 10px;\">\n"));
       
   690         }
       
   691     iWriteStream.WriteL(_L8("<input type=\"submit\" id=\"expand\" value=\"\" class=\"expand\""));
       
   692     iWriteStream.WriteL(_L8(" onClick=\"expandHeader(true)\"/>"));
       
   693     iWriteStream.WriteL(_L8("</td>\n"));
       
   694 
       
   695     // finish first row
       
   696     iWriteStream.WriteL(_L8("</tr>\n"));  
       
   697     iWriteStream.WriteL(_L8("</table></td></tr>\n"));
       
   698     iWriteStream.CommitL();
       
   699     }
       
   700 
       
   701 void CFreestyleMessageHeaderHTML::ExportSubjectL() const
       
   702     {
       
   703     iWriteStream.WriteL( _L8("<tr id=\"") );
       
   704     iWriteStream.WriteL( KSubjectFieldName );
       
   705     iWriteStream.WriteL( _L8("\">") );
       
   706 
       
   707 
       
   708     iWriteStream.WriteL( _L8("<td width=\"1\">") );
       
   709     iWriteStream.WriteL( _L8("<b>") );
       
   710     HBufC8* subjectHeadingText = HeadingTextLC( R_FREESTYLE_EMAIL_UI_VIEWER_SUBJECT );
       
   711     iWriteStream.WriteL( *subjectHeadingText );
       
   712     CleanupStack::PopAndDestroy( subjectHeadingText );
       
   713     iWriteStream.WriteL( _L8("</b>") );
       
   714     iWriteStream.WriteL( _L8("</td>") );
       
   715     iWriteStream.WriteL( _L8("</tr>\n") );
       
   716     
       
   717     // subject text
       
   718     iWriteStream.WriteL( _L8("<tr>") );
       
   719     iWriteStream.WriteL( _L8("<td>") );
       
   720 	HBufC* subject = iMailMessage.GetSubject().Alloc();
       
   721     /*
       
   722      * Writes the subject to iWriteStream and also
       
   723      * takes care of the urls and marks them as hotspots
       
   724      */
       
   725     WriteSubjectL(*subject);
       
   726 
       
   727     iWriteStream.WriteL( _L8("</td>") );
       
   728     iWriteStream.WriteL( _L8("</tr>\n") );
       
   729     // Write icons (if necessary).
       
   730     HBufC8* followUp = HTMLHeaderFollowUpIconLC( ETrue );
       
   731     HBufC8* priority = HTMLHeaderPriorityIconLC( ETrue );
       
   732    
       
   733     if ( priority )
       
   734        {
       
   735        iWriteStream.WriteL(_L8("<tr><td>"));
       
   736        iWriteStream.WriteL( *priority );
       
   737        iWriteStream.WriteL(_L8("</td></tr>"));
       
   738        CleanupStack::PopAndDestroy( priority);
       
   739        }
       
   740    
       
   741     if ( followUp )
       
   742        {
       
   743        iWriteStream.WriteL(_L8("<tr><td>"));
       
   744        iWriteStream.WriteL( *followUp );
       
   745        iWriteStream.WriteL(_L8("</td></tr>"));
       
   746        CleanupStack::PopAndDestroy( followUp );
       
   747        }
       
   748 
       
   749     iWriteStream.CommitL();
       
   750     }
       
   751 
       
   752 void CFreestyleMessageHeaderHTML::ExportSubjectCollapsedL() const
       
   753     {
       
   754     iWriteStream.WriteL(_L8("<tr>\n"));
       
   755     iWriteStream.WriteL(_L8("<td id=\"subject_initial\""));
       
   756     if ( !iMirrorLayout )
       
   757         {
       
   758         iWriteStream.WriteL(_L8(" align=\"left\""));
       
   759         }
       
   760     else
       
   761         {
       
   762         iWriteStream.WriteL(_L8(" align=\"right\""));
       
   763         }
       
   764     iWriteStream.WriteL(_L8("><b>"));
       
   765 
       
   766     HBufC* subject = iMailMessage.GetSubject().Alloc();
       
   767     /*
       
   768      * Writes the subject to iWriteStream and also
       
   769      * takes care of the urls and marks them as hotspots
       
   770      */
       
   771     WriteSubjectL(*subject);
       
   772 
       
   773     iWriteStream.WriteL(_L8("</b>"));
       
   774 
       
   775     // Write icons (if necessary).
       
   776     HBufC8* followUp = HTMLHeaderFollowUpIconLC( EFalse );
       
   777     HBufC8* priority = HTMLHeaderPriorityIconLC( EFalse );
       
   778 
       
   779     if ( priority )
       
   780         {
       
   781         iWriteStream.WriteL( *priority );
       
   782         CleanupStack::PopAndDestroy( priority);
       
   783         }
       
   784 
       
   785     if ( followUp )
       
   786         {
       
   787         iWriteStream.WriteL( *followUp );
       
   788         CleanupStack::PopAndDestroy( followUp );
       
   789         }
       
   790 
       
   791     iWriteStream.WriteL(_L8("</td></tr>\n"));  // finish subject row
       
   792     iWriteStream.CommitL();
       
   793     }
       
   794 
       
   795 void CFreestyleMessageHeaderHTML::ExportFromL() const
       
   796     {
       
   797     RPointerArray<CFSMailAddress> froms;
       
   798     CleanupClosePushL( froms );
       
   799     CFSMailAddress* from = iMailMessage.GetSender();  // ownership not transferred
       
   800     if ( from )
       
   801         {
       
   802         froms.AppendL( from );
       
   803         }
       
   804     ExportEmailAddressesL( FreestyleMessageHeaderURLFactory::EEmailAddressTypeFrom, froms, 
       
   805                            KFromFieldName, KFromTableName, R_FREESTYLE_EMAIL_UI_VIEWER_FROM );
       
   806     CleanupStack::PopAndDestroy( &froms );
       
   807     }
       
   808 
       
   809 void CFreestyleMessageHeaderHTML::ExportToL() const
       
   810     {
       
   811     RPointerArray<CFSMailAddress>& recipients = iMailMessage.GetToRecipients();
       
   812     ExportEmailAddressesL( FreestyleMessageHeaderURLFactory::EEmailAddressTypeTo, recipients,
       
   813                            KToFieldName, KToTableName, R_FREESTYLE_EMAIL_UI_VIEWER_TO );
       
   814     }
       
   815 
       
   816 void CFreestyleMessageHeaderHTML::ExportCcL() const
       
   817     {
       
   818     RPointerArray<CFSMailAddress>& recipients = iMailMessage.GetCCRecipients();
       
   819     ExportEmailAddressesL( FreestyleMessageHeaderURLFactory::EEmailAddressTypeCc, recipients,
       
   820                            KCcFieldName, KCcTableName, R_FREESTYLE_EMAIL_UI_VIEWER_CC );
       
   821     }
       
   822 
       
   823 void CFreestyleMessageHeaderHTML::ExportBccL() const
       
   824     {
       
   825     RPointerArray<CFSMailAddress>& recipients = iMailMessage.GetBCCRecipients();
       
   826     ExportEmailAddressesL( FreestyleMessageHeaderURLFactory::EEmailAddressTypeBcc, recipients,
       
   827                            KBccFieldName, KBccTableName, R_FREESTYLE_EMAIL_UI_VIEWER_BCC );
       
   828     }
       
   829 
       
   830 void CFreestyleMessageHeaderHTML::ExportSentTimeL() const
       
   831     {
       
   832 
       
   833     iWriteStream.WriteL( _L8("<tr id=\"") );
       
   834     iWriteStream.WriteL( KSentFieldName );
       
   835     iWriteStream.WriteL( _L8("\">") );
       
   836 
       
   837 
       
   838     iWriteStream.WriteL( _L8("<td width=\"1\">") );
       
   839     iWriteStream.WriteL( _L8("<b>") );
       
   840     HBufC8* sentHeadingText = HeadingTextLC( R_FREESTYLE_EMAIL_UI_VIEWER_SENT );
       
   841     iWriteStream.WriteL( *sentHeadingText );
       
   842     CleanupStack::PopAndDestroy( sentHeadingText );
       
   843     iWriteStream.WriteL( _L8("</b>") );
       
   844     iWriteStream.WriteL( _L8("</td>") );
       
   845     iWriteStream.WriteL( _L8("</tr>\n") );
       
   846 
       
   847     iWriteStream.WriteL( _L8("<tr>") );
       
   848     iWriteStream.WriteL( _L8("<td>") );
       
   849 
       
   850     HBufC* dateText = TFsEmailUiUtility::DateTextFromMsgLC( &iMailMessage );
       
   851     HBufC* timeText = TFsEmailUiUtility::TimeTextFromMsgLC( &iMailMessage );
       
   852 
       
   853     TInt len = dateText->Length() + KSentLineDateAndTimeSeparatorText().Length() + timeText->Length();
       
   854     HBufC* sentTimeText = HBufC::NewLC( len );
       
   855     TPtr sentTimeTextPtr = sentTimeText->Des();
       
   856     sentTimeTextPtr.Append( *dateText );
       
   857     sentTimeTextPtr.Append( KSentLineDateAndTimeSeparatorText );
       
   858     sentTimeTextPtr.Append( *timeText );
       
   859     HBufC8* sentTimeText8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( sentTimeTextPtr );
       
   860     CleanupStack::PushL( sentTimeText8 );
       
   861     iWriteStream.WriteL( *sentTimeText8 );
       
   862     CleanupStack::PopAndDestroy( sentTimeText8 );
       
   863     CleanupStack::PopAndDestroy( sentTimeText );
       
   864     CleanupStack::PopAndDestroy( timeText );
       
   865     CleanupStack::PopAndDestroy( dateText );
       
   866 
       
   867     iWriteStream.WriteL( _L8("</td>") );
       
   868 
       
   869     iWriteStream.WriteL( _L8("</tr>\n") );
       
   870 
       
   871     iWriteStream.CommitL();
       
   872     }
       
   873 
       
   874 void CFreestyleMessageHeaderHTML::ExportAttachmentsL() const
       
   875     {
       
   876     TInt attachmentsCount (iAttachments.Count());
       
   877     if ( attachmentsCount)
       
   878         {
       
   879         // The attachments table consists of one row that contains 2 cells
       
   880         // first cell contains the attachment icon
       
   881         // second cell contains a table which contains the attachments list
       
   882 
       
   883         // start attachments table
       
   884         iWriteStream.WriteL( _L8("<table id=\"") ); 
       
   885         iWriteStream.WriteL( KAttachmentTableName );
       
   886         iWriteStream.WriteL( _L8("\" border=\"0\" width=\"100%\">\n") );  // width is set at 100% intentionally
       
   887         
       
   888         // add attachment icon
       
   889         // start row
       
   890         iWriteStream.WriteL( _L8("<tr>\n") );
       
   891         iWriteStream.WriteL( _L8("<td width=\"1\" valign=\"top\"") );
       
   892         iWriteStream.WriteL(_L8(" align=\"left\""));
       
   893 
       
   894         iWriteStream.WriteL( _L8("><image src=\"") );
       
   895         
       
   896         iWriteStream.WriteL( KAttachementIconGeneral );
       
   897         iWriteStream.WriteL( _L8("\" ></td>\n") );
       
   898         // start table of attachments as a table within a cell
       
   899         iWriteStream.WriteL( _L8("<td>\n") );
       
   900         iWriteStream.WriteL(_L8("<table id=\"table_attachments_list\" border=\"0\" width=\"100%\">\n"));
       
   901 
       
   902         for (TInt i=0; i < attachmentsCount; i++)
       
   903             {
       
   904             AddAttachmentL( *iAttachments[i] );
       
   905             }
       
   906 
       
   907         iWriteStream.WriteL(_L8("</table>\n")); // end table_attachments_list
       
   908         iWriteStream.WriteL( _L8("</td>\n") );
       
   909         
       
   910         iWriteStream.WriteL( _L8("</tr>\n") );
       
   911         iWriteStream.WriteL(_L8("</table>\n")); // end attachments table
       
   912         }
       
   913     }
       
   914 
       
   915 void CFreestyleMessageHeaderHTML::ExportEmailAddressesL(FreestyleMessageHeaderURLFactory::TEmailAddressType aEmailAddressType, 
       
   916                                                         const RPointerArray<CFSMailAddress>& aEmailAddresses,
       
   917                                                         const TDesC8& aRowId,
       
   918                                                         const TDesC8& /*aTableId*/,
       
   919                                                         TInt aHeaderTextResourceId ) const
       
   920     {
       
   921     if ( aEmailAddresses.Count() )
       
   922         {
       
   923         // begin table row
       
   924         iWriteStream.WriteL( _L8("<tr id=\"")); 
       
   925         iWriteStream.WriteL( aRowId );
       
   926         iWriteStream.WriteL( _L8("\">") );
       
   927         
       
   928         // heading text
       
   929         iWriteStream.WriteL( _L8("<td><b>"));
       
   930         HBufC8* headingText = HeadingTextLC( aHeaderTextResourceId );
       
   931         iWriteStream.WriteL( *headingText );
       
   932         CleanupStack::PopAndDestroy( headingText );
       
   933         iWriteStream.WriteL( _L8("</b></td>"));
       
   934         
       
   935         iWriteStream.WriteL( _L8("</tr>\n") );  // end table row      
       
   936         
       
   937         // add addresses, one address per row
       
   938         TInt count( aEmailAddresses.Count() );
       
   939         for (TInt i = 0; i < count; ++i )
       
   940             {
       
   941             iWriteStream.WriteL( _L8("<tr><td style=\"padding: 0px 0px 7px 0px;\">") );
       
   942             AddEmailAddressL (aEmailAddressType, *aEmailAddresses[i] );
       
   943             iWriteStream.WriteL( _L8("</td></tr>\n") );
       
   944             }
       
   945 
       
   946         iWriteStream.CommitL();
       
   947         }
       
   948     }
       
   949 
       
   950 void CFreestyleMessageHeaderHTML::AddEmailAddressL( FreestyleMessageHeaderURLFactory::TEmailAddressType aEmailAddressType,
       
   951                                                     const CFSMailAddress& aEmailAddress ) const
       
   952     {
       
   953     CFreestyleMessageHeaderURL* emailUrl = FreestyleMessageHeaderURLFactory::CreateEmailAddressUrlL( aEmailAddressType, aEmailAddress );
       
   954     CleanupStack::PushL( emailUrl );
       
   955 
       
   956     HBufC* url = emailUrl->ExternalizeL();
       
   957     CleanupStack::PushL( url );
       
   958     HBufC8* url8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *url );
       
   959     CleanupStack::PushL( url8 );
       
   960     StartHyperlinkL( *url8 );
       
   961     CleanupStack::PopAndDestroy( url8 );
       
   962     CleanupStack::PopAndDestroy( url );
       
   963 
       
   964     HBufC8* displayName8 = NULL;
       
   965     //  ENLN-7ZVBES
       
   966     //  Display name not shown in From:, instead, email address is shown
       
   967     if ( (aEmailAddress.GetDisplayName().Length() > 0) && aEmailAddressType != FreestyleMessageHeaderURLFactory::EEmailAddressTypeFrom )
       
   968         {
       
   969         displayName8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( aEmailAddress.GetDisplayName() );
       
   970         }
       
   971     else
       
   972         {
       
   973         displayName8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( aEmailAddress.GetEmailAddress() );
       
   974         }
       
   975     CleanupStack::PushL( displayName8 );
       
   976     iWriteStream.WriteL( *displayName8 );
       
   977     CleanupStack::PopAndDestroy( displayName8 );
       
   978 
       
   979     EndHyperlinkL();
       
   980 
       
   981     CleanupStack::PopAndDestroy( emailUrl );
       
   982     }
       
   983 
       
   984 void CFreestyleMessageHeaderHTML::AddAttachmentL( CFSMailMessagePart& aAttachment ) const
       
   985     {
       
   986     iWriteStream.WriteL( _L8("<tr><td style=\"padding: 0px 0px 7px 0px;\">") ); // pad bottom to allow some space between the lines
       
   987 
       
   988     TUint id = aAttachment.GetPartId().Id();
       
   989     TBuf<32> itemId;
       
   990     itemId.AppendNum( id );
       
   991     CFreestyleMessageHeaderURL* attnUrl = FreestyleMessageHeaderURLFactory::CreateAttachmentUrlL( itemId );
       
   992     CleanupStack::PushL( attnUrl );
       
   993     HBufC* attnUrlText = attnUrl->ExternalizeL();
       
   994     CleanupStack::PushL( attnUrlText );
       
   995     HBufC8* attnUrlText8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *attnUrlText );
       
   996     CleanupStack::PushL( attnUrlText8 );
       
   997     StartHyperlinkL( *attnUrlText8 );
       
   998     CleanupStack::PopAndDestroy( attnUrlText8 );
       
   999     CleanupStack::PopAndDestroy( attnUrlText );
       
  1000     CleanupStack::PopAndDestroy( attnUrl );
       
  1001 
       
  1002     TDesC& attnName = aAttachment.AttachmentNameL();
       
  1003     HBufC8* attnName8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( attnName );
       
  1004     CleanupStack::PushL( attnName8 );
       
  1005     iWriteStream.WriteL( *attnName8 );
       
  1006     CleanupStack::PopAndDestroy( attnName8 );
       
  1007 
       
  1008     HBufC* sizeDesc = TFsEmailUiUtility::CreateSizeDescLC(aAttachment.ContentSize(), EFalse);
       
  1009 
       
  1010     TBuf8<48> sizeText;
       
  1011     
       
  1012     // Add right to left marker as "(" and ")" are messing up the html language markers
       
  1013     // and &rlm is only added in mirror layout 
       
  1014     if( iMirrorLayout )  
       
  1015         {
       
  1016     sizeText.Append( KSpace8 );
       
  1017     sizeText.Append( _L8( "&rlm;" ) );
       
  1018         }
       
  1019     
       
  1020     sizeText.Append( KSpace8 );
       
  1021     sizeText.Append( _L8("(") );
       
  1022     HBufC8* sizeDesc8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( sizeDesc->Des() );
       
  1023     CleanupStack::PushL( sizeDesc8 );
       
  1024     sizeText.Append( sizeDesc8->Des() );
       
  1025     CleanupStack::PopAndDestroy( sizeDesc8 );
       
  1026     CleanupStack::PopAndDestroy( sizeDesc );
       
  1027     sizeText.Append( _L8(")") );
       
  1028     
       
  1029     if( iMirrorLayout )
       
  1030         {
       
  1031     sizeText.Append( KSpace8 );
       
  1032     sizeText.Append( _L8( "&rlm;" ) );
       
  1033         }
       
  1034     
       
  1035     iWriteStream.WriteL( sizeText );
       
  1036 
       
  1037     EndHyperlinkL();
       
  1038 
       
  1039     iWriteStream.WriteL( _L8("</td></tr>\n") );
       
  1040     iWriteStream.CommitL();
       
  1041     }
       
  1042 
       
  1043 
       
  1044 void CFreestyleMessageHeaderHTML::StartHyperlinkL( const TDesC8& aUrl ) const
       
  1045     {
       
  1046     iWriteStream.WriteL( _L8("<a href=\"") );
       
  1047     if ( aUrl.FindF( KProtocolIdentifier() ) == KErrNotFound )
       
  1048     	{
       
  1049         iWriteStream.WriteL( _L8("http://"));
       
  1050     	}
       
  1051     iWriteStream.WriteL( aUrl );
       
  1052     iWriteStream.WriteL( _L8("\">"));
       
  1053     iWriteStream.CommitL();
       
  1054     }
       
  1055 
       
  1056 void CFreestyleMessageHeaderHTML::EndHyperlinkL() const
       
  1057     {
       
  1058     iWriteStream.WriteL( _L8("</a>") );
       
  1059     iWriteStream.CommitL();
       
  1060     }
       
  1061 
       
  1062 void CFreestyleMessageHeaderHTML::AddImageL( const TDesC8& aImageUrl ) const
       
  1063     {
       
  1064     iWriteStream.WriteL( _L8("<image border=\"0\" src=\"") );
       
  1065     iWriteStream.WriteL( aImageUrl );
       
  1066     iWriteStream.WriteL( _L8("\">"));
       
  1067     iWriteStream.CommitL();
       
  1068     }
       
  1069 
       
  1070 void CFreestyleMessageHeaderHTML::AddImageL( const TDesC8& aImageId,
       
  1071                                              const TDesC8& aImageUrl,
       
  1072                                              const TDesC8& aImageEvent ) const
       
  1073     {
       
  1074     iWriteStream.WriteL( _L8("<image id=\"") );
       
  1075     iWriteStream.WriteL( aImageId );
       
  1076     iWriteStream.WriteL( _L8("\" ") );
       
  1077     iWriteStream.WriteL( _L8("border=\"0\" src=\"") );
       
  1078     iWriteStream.WriteL( aImageUrl );
       
  1079     iWriteStream.WriteL( _L8("\" "));
       
  1080     iWriteStream.WriteL( aImageEvent );
       
  1081     iWriteStream.WriteL( _L8(">"));
       
  1082     iWriteStream.CommitL();
       
  1083     }
       
  1084 
       
  1085 void CFreestyleMessageHeaderHTML::AddJavascriptL() const
       
  1086     {
       
  1087     iWriteStream.WriteL( _L8("<script language=\"javascript\" src=\"header.js\"></script>\n"));
       
  1088     iWriteStream.CommitL();
       
  1089     }
       
  1090 
       
  1091 void CFreestyleMessageHeaderHTML::StartHeaderTableL( const TDesC8& aTableId,
       
  1092     TBool /*aVisible*/ ) const
       
  1093     {
       
  1094     iWriteStream.WriteL( _L8("<table id=\"") );
       
  1095     iWriteStream.WriteL( aTableId );
       
  1096     iWriteStream.WriteL( _L8("\" border=\"0\" width=\"100%\"") );
       
  1097     iWriteStream.WriteL( _L8(">\n") );
       
  1098     iWriteStream.CommitL();
       
  1099     }
       
  1100 
       
  1101 void CFreestyleMessageHeaderHTML::EndHeaderTableL() const
       
  1102     {
       
  1103     EndTableL();
       
  1104     }
       
  1105 
       
  1106 void CFreestyleMessageHeaderHTML::StartTableL( const TDesC8& aTableId ) const
       
  1107     {
       
  1108     iWriteStream.WriteL( _L8("<table id=\"") );
       
  1109     iWriteStream.WriteL( aTableId );
       
  1110     iWriteStream.WriteL( _L8("\" border=\"1\">\n") );
       
  1111     iWriteStream.CommitL();
       
  1112     }
       
  1113 
       
  1114 void CFreestyleMessageHeaderHTML::EndTableL() const
       
  1115     {
       
  1116     iWriteStream.WriteL( _L8("</table>\n") );
       
  1117     iWriteStream.CommitL();
       
  1118     }
       
  1119 
       
  1120 HBufC8* CFreestyleMessageHeaderHTML::ClickImageEventL( const TDesC8& aImageName ) const
       
  1121     {
       
  1122     TBuf8<KMaxEventLength> event;
       
  1123     if ( aImageName.Compare( KToImageName ) == 0 )
       
  1124         {
       
  1125         event.Append( _L8("onClick=\"toggleField('") );
       
  1126         event.Append( KToTableName );
       
  1127         event.Append( _L8("', '") );
       
  1128         event.Append( KToImageName );
       
  1129         event.Append( _L8("')\"") );
       
  1130         }
       
  1131     else if ( aImageName.Compare( KCcImageName ) == 0 )
       
  1132         {
       
  1133         event.Append( _L8("onClick=\"toggleField('") );
       
  1134         event.Append( KCcTableName );
       
  1135         event.Append( _L8("', '") );
       
  1136         event.Append( KCcImageName );
       
  1137         event.Append( _L8("')\"") );
       
  1138         }
       
  1139     else if ( aImageName.Compare( KBccImageName ) == 0 )
       
  1140         {
       
  1141         event.Append( _L8("onClick=\"toggleField('") );
       
  1142         event.Append( KBccTableName );
       
  1143         event.Append( _L8("', '") );
       
  1144         event.Append( KBccImageName );
       
  1145         event.Append( _L8("')\"") );
       
  1146         }
       
  1147     else if ( aImageName.Compare( KAttachmentImageName ) == 0 )
       
  1148         {
       
  1149         event.Append( _L8("onClick=\"toggleField('") );
       
  1150         event.Append( KAttachmentTableName );
       
  1151         event.Append( _L8("', '") );
       
  1152         event.Append( KAttachmentImageName );
       
  1153         event.Append( _L8("')\"") );
       
  1154         }
       
  1155     else
       
  1156         {
       
  1157         User::Leave(KErrNotSupported);
       
  1158         }
       
  1159     return event.AllocL();
       
  1160     }
       
  1161 
       
  1162 HBufC8* CFreestyleMessageHeaderHTML::HeadingTextLC( TInt aId ) const
       
  1163     {
       
  1164     HBufC* headingText = StringLoader::LoadLC( aId );
       
  1165     HBufC8* headingText8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *headingText );
       
  1166     CleanupStack::PopAndDestroy( headingText );
       
  1167     CleanupStack::PushL( headingText8 );
       
  1168     return headingText8;
       
  1169     }
       
  1170 
       
  1171 HBufC8* CFreestyleMessageHeaderHTML::HeadingTextLC( TInt aId, TInt aSize ) const
       
  1172     {
       
  1173     HBufC* headingText = StringLoader::LoadLC( aId, aSize );
       
  1174     HBufC8* headingText8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *headingText );
       
  1175     CleanupStack::PopAndDestroy( headingText );
       
  1176     CleanupStack::PushL( headingText8 );
       
  1177     return headingText8;
       
  1178     }
       
  1179 
       
  1180 void CFreestyleMessageHeaderHTML::AddStyleSheetL() const
       
  1181     {
       
  1182     // Add an internal style sheet
       
  1183     // If the style becomes numerous or complicated, consider using an external style sheet
       
  1184     
       
  1185     iWriteStream.WriteL( _L8("<style type=\"text/css\">\n") );
   751     iWriteStream.WriteL( _L8("<style type=\"text/css\">\n") );
  1186     
       
  1187     // define a div class "header", specifying the background color
       
  1188     // for the email header part
       
  1189     
       
  1190 #ifdef __USE_THEME_COLOR_FOR_HEADER    
   752 #ifdef __USE_THEME_COLOR_FOR_HEADER    
  1191     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
   753     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
  1192     TRgb textColor;
   754     TRgb textColor;
  1193     TRgb bgColor;
   755     TRgb bgColor;
  1194     // Should use EAknsCIFsTextColorsCG3 if background is white
   756     // Should use EAknsCIFsTextColorsCG3 if background is white
  1207          formatBuffer->Des().Format(KBodyWithColor(), textColor.Internal() & 0xFFFFFF, bgColor.Internal() & 0xFFFFFF);
   769          formatBuffer->Des().Format(KBodyWithColor(), textColor.Internal() & 0xFFFFFF, bgColor.Internal() & 0xFFFFFF);
  1208          iWriteStream.WriteL( *formatBuffer );
   770          iWriteStream.WriteL( *formatBuffer );
  1209          CleanupStack::PopAndDestroy(); // formatBuffer
   771          CleanupStack::PopAndDestroy(); // formatBuffer
  1210          }
   772          }
  1211 #else
   773 #else
  1212      iWriteStream.WriteL( _L8("body { color: black; background-color: lightblue; }\n") );
   774      //iWriteStream.WriteL( _L8("body { color: black; background-color: lightblue; }\n") );
       
   775      iWriteStream.WriteL( _L8("body { color: black; background-color: #c5c5c5; }\n") );
  1213 #endif // __USE_THEME_COLOR_FOR_HEADER    
   776 #endif // __USE_THEME_COLOR_FOR_HEADER    
  1214     
       
  1215     // set font size to 75% of the default size
       
  1216     // because, at the default size, the header text is too big relative to the text in the email body
       
  1217     // Note: since the text in the body is too small at "normal" level, 
       
  1218     // we have the text size level in the browser set to "Larger" which is 20% larger than the specified size
       
  1219     // the "larger" size affects all text which includes the header.
       
  1220     iWriteStream.WriteL( _L8("td { font-family:arial,sans-serif ; font-size:75% }\n") );
       
  1221     iWriteStream.WriteL( _L8(".button { background: url('btn_middle.png') repeat-x top left; border: 1px solid #546284; height: 32px; font-size:19px; font-weight: bold; color: #344a6c; font-family:arial,sans-serif; }\n") );
       
  1222     iWriteStream.WriteL( _L8("input { color: black; position: relative; border: 0; cursor: pointer; overflow: visible; }\n") );
       
  1223     iWriteStream.WriteL( _L8("input.expand { width: 55px; height: 36px; background: transparent url('"));
       
  1224     iWriteStream.WriteL( KExpandHeaderIconFileName );
       
  1225     iWriteStream.WriteL( _L8("') no-repeat top left; }\n") );
       
  1226     iWriteStream.WriteL( _L8("input.collapse { width: 55px; height: 36px; background: transparent url('"));
       
  1227     iWriteStream.WriteL( KCollapseHeaderIconFileName );
       
  1228     iWriteStream.WriteL( _L8("') no-repeat top left; }\n") );
       
  1229     iWriteStream.WriteL( _L8("</style>\n") );
   777     iWriteStream.WriteL( _L8("</style>\n") );
  1230     iWriteStream.CommitL();
   778     iWriteStream.CommitL();
  1231     }
   779     }
  1232 
   780 
  1233 void CFreestyleMessageHeaderHTML::StartDivL() const
   781                                 
  1234     {
       
  1235     // Add div, using "header" class
       
  1236     iWriteStream.WriteL( _L8("<div class=\"header\">\n") );
       
  1237     iWriteStream.CommitL();
       
  1238     }
       
  1239     
       
  1240 void CFreestyleMessageHeaderHTML::EndDivL() const
       
  1241     {
       
  1242     iWriteStream.WriteL( _L8("</div>\n") );
       
  1243     iWriteStream.CommitL();
       
  1244     }
       
  1245 
       
  1246