inc/mmsattachmenthandler.h
changeset 23 238255e8b033
equal deleted inserted replaced
5:4697dfb2d7ad 23:238255e8b033
       
     1 /*
       
     2 * Copyright (c) 2004-2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *     Attachment handling helper functions functions
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #ifndef MMSATTACHMENTHANDLER_H
       
    22 #define MMSATTACHMENTHANDLER_H
       
    23 
       
    24 // INCLUDES
       
    25 #include <e32def.h>
       
    26 #include <cmsvattachment.h> // for TMsvAttachmentId
       
    27 
       
    28 // CONSTANTS
       
    29 
       
    30 // MACROS
       
    31 
       
    32 // DATA TYPES
       
    33 
       
    34 // FUNCTION PROTOTYPES
       
    35 
       
    36 // FORWARD DECLARATIONS
       
    37 class CMsvStore;
       
    38 class RFs;
       
    39 class RFile;
       
    40 class TDesC8;
       
    41 class TDriveUnit;
       
    42 class CMsvMimeHeaders;
       
    43 
       
    44 // CLASS DECLARATION
       
    45 
       
    46 /**
       
    47 * Attachment handling functions that can be called from both client and
       
    48 * server side
       
    49 *
       
    50 * @lib mmsgenutil.lib
       
    51 * @since 3.2
       
    52 */
       
    53 NONSHARABLE_CLASS( CMmsAttachmentHandler ):public CBase
       
    54     {
       
    55     public:  // Constructors and destructor
       
    56         
       
    57         /**
       
    58         * Two-phased constructor.
       
    59         * @param aEntryWrapper MMS entry wrapper hiding difference between
       
    60         *     CMsvServerEntry and CMsvEntry.
       
    61         */
       
    62         IMPORT_C static CMmsAttachmentHandler* NewL();
       
    63         
       
    64         /**
       
    65         * Destructor.
       
    66         */
       
    67         virtual ~CMmsAttachmentHandler();
       
    68 
       
    69     public: // New functions
       
    70 
       
    71         /**
       
    72         * Returns total size of all attachments including mime headers
       
    73         * and binary attachment data. Linked attachments are included
       
    74         * This function is needed to allocate the encoding buffer.
       
    75         * @param aStore Read store for the message entry
       
    76         * @return combined size of all attachments, including linked attachments
       
    77         */
       
    78         IMPORT_C static TInt AttachmentsSizeL( CMsvStore& aStore );
       
    79         
       
    80         /**
       
    81         * Check if aFileName would be a valid filename.
       
    82         * Cannot use path because absolute path is not known. Only filename is checked
       
    83         * @param aFs open file system handle.
       
    84         * @param aFileName suggestion of a filename.
       
    85         * @return ETrue if filename is valid, EFalse if not.
       
    86         */
       
    87         IMPORT_C static TBool IsValidFilename( RFs& aFs, const TPtrC& aFileName );
       
    88 
       
    89         /**
       
    90         * Create attachment entry and copy specified file to binary file storage.
       
    91         * @param aStore an open EditStore. Caller must commit store
       
    92         *     (several attachments can be added before committing store)
       
    93         * @param aFile opened file handle, source of the attachment.
       
    94         *     File must be in public location to be accessible.
       
    95         *     Caller must close the file afterwards.
       
    96         * @param aFs File session handle. Needed to check disk space
       
    97         * @param aMessageDrive the drive the message store is on.
       
    98         *     (needed for disk space check)
       
    99         * @param aMimeType mime type of the attachmet.
       
   100         * @param aMimeHeaders mime headers for the attachment. If content type is not
       
   101         *     defined, function adds the mime type and subtype from aMimeType
       
   102         *     Suggested filename in mimeHeaders is used as attachment name
       
   103         * @param aAttachmentInfo must be initialized to a CMsvAttachment::EMsvFile
       
   104         *     on return contains data about the attachment.
       
   105         *     Ownership of attachmentinfo is transferred to attachment manager,
       
   106         *     it must not be deleted by caller.
       
   107         *     Attachment manager will be destroyed when store is deleted.
       
   108         *     After that aAttachmentInfo will no longer be available.
       
   109         * @param aAttaId attachment id of the newly created attachment
       
   110         */
       
   111         IMPORT_C static void CreateAttachmentL(
       
   112             CMsvStore& aStore,
       
   113             RFile& aFile,
       
   114             RFs& aFs,
       
   115             TDriveUnit aMessageDrive,
       
   116             TDesC8& aMimeType,
       
   117             CMsvMimeHeaders& aMimeHeaders,
       
   118             CMsvAttachment* aAttachmentInfo,
       
   119             TMsvAttachmentId& aAttaId);
       
   120             
       
   121         /**
       
   122         * Create text/plain attachment. <br>
       
   123         * Creates a text attachment from descriptor.
       
   124         * Has option to convert all unicode paragraph separator marks to line feeds.
       
   125         * Converts text from unicode (ucs-2) to utf-8 before storing it.
       
   126         * @param aStore an open EditStore. Caller must commit store
       
   127         *     (several attachments can be added before committing store)
       
   128         * @param aAttachmentId returned ID of the new attachment entry
       
   129         * @param aText UNICODE text to be added as a text/plain attachment.
       
   130         * @param aFile suggested filename for the attachment
       
   131         * @param aFs File session handle. Needed to check disk space
       
   132         * @param aMessageDrive the drive the message store is on.
       
   133         *     (needed for disk space check)
       
   134         * @param aConvertParagraphSeparator flag to tell if the function 
       
   135         *     will search for all 0x2029 characters (Unicode paragraph
       
   136         *     separator) and replace them with 0x000a (line feed).
       
   137         *     aConvertParagraphSeparator == ETrue: convert
       
   138         *     aConvertParagraphSeparator == EFalse: do not convert
       
   139         */
       
   140         IMPORT_C static void CreateTextAttachmentL(
       
   141             CMsvStore& aStore,
       
   142             TMsvAttachmentId& aAttachmentId,
       
   143             const TDesC& aText,
       
   144             const TDesC& aFile,
       
   145             RFs& aFs,
       
   146             TDriveUnit aMessageDrive,
       
   147             TBool aConvertParagraphSeparator = ETrue );
       
   148             
       
   149         /**
       
   150         * Create text/plain attachment. <br>
       
   151         * Creates a text attachment from descriptor.
       
   152         * Has option to convert all unicode paragraph separator marks to line feeds.
       
   153         * Converts text from unicode (ucs-2) to utf-8 before storing it.
       
   154         * @param aStore an open EditStore. Caller must commit store
       
   155         *     (several attachments can be added before committing store)
       
   156         * @param aAttachmentId returned ID of the new attachment entry
       
   157         * @param aFile open file read handle to unicode plain text file
       
   158         * @param aFs File session handle. Needed to check disk space
       
   159         * @param aMessageDrive the drive the message store is on.
       
   160         *     (needed for disk space check)
       
   161         */
       
   162         IMPORT_C static void CreateUTF8TextAttachmentFromFileL(
       
   163             CMsvStore& aStore,
       
   164             TMsvAttachmentId& aAttachmentId,
       
   165             RFile& aFile,
       
   166             RFs& aFs,
       
   167             TDriveUnit aMessageDrive
       
   168             );
       
   169             
       
   170         
       
   171     public: // Functions from base classes
       
   172 
       
   173     protected:  // New functions
       
   174         
       
   175     protected:  // Functions from base classes
       
   176         
       
   177     private:
       
   178 
       
   179         /**
       
   180         * C++ constructor.
       
   181         * @param aEntryWrapper MMS entry wrapper hiding difference between
       
   182         *     CMsvServerEntry and CMsvEntry
       
   183         */
       
   184         CMmsAttachmentHandler( );
       
   185 
       
   186         /**
       
   187         * Constructor.
       
   188         */
       
   189         void ConstructL();
       
   190         
       
   191         /**
       
   192         * Remove an attachment by attaId.
       
   193         * Symbian synchronous attachment manager can only remove by index.
       
   194         * 
       
   195         * @param aAttaId id of the attachment to be removed
       
   196         * @param aStore reference to open edit store
       
   197         */
       
   198         static void RemoveAttachmentL( TMsvAttachmentId aAttaId, CMsvStore& aStore );
       
   199         
       
   200         
       
   201     };
       
   202     
       
   203 /**
       
   204 * Reads and writes single lines of text to or from a file.
       
   205 *
       
   206 * @lib mmsgenutil.lib
       
   207 * @since 3.2
       
   208 */
       
   209 
       
   210 NONSHARABLE_CLASS ( TMmsFileText )
       
   211 	{
       
   212 public:
       
   213 	enum TFileState
       
   214 		{
       
   215 		EStartOfFile,
       
   216 		ENormal,
       
   217 		EReverse
       
   218 		};
       
   219 public:
       
   220 	TMmsFileText();
       
   221 	void Set(RFile& aFile);
       
   222 	TInt Read(TDes& aDes);
       
   223 private:
       
   224 	TInt CheckForTerminator(TBool& anAnswer);
       
   225 	TInt FillBuffer();
       
   226 private:
       
   227 	const TText* iNext;
       
   228 	const TText* iEnd;
       
   229 	TFileState iState;
       
   230 	RFile iFile;
       
   231 	TBuf8<0x100> iReadBuf; 
       
   232 	};
       
   233 	
       
   234 #endif      // MMSATTACHMENTHANDLER_H   
       
   235             
       
   236 // End of File