LCOV - code coverage report
Current view: top level - libreoffice/tools/inc/tools - inetmsg.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 72 0.0 %
Date: 2012-12-27 Functions: 0 30 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : #ifndef _TOOLS_INETMSG_HXX
      20             : #define _TOOLS_INETMSG_HXX
      21             : 
      22             : #include "tools/toolsdllapi.h"
      23             : #include <rtl/string.hxx>
      24             : #include <rtl/textenc.h>
      25             : #include <rtl/ustring.hxx>
      26             : #include <tools/inetmime.hxx>
      27             : #include <tools/stream.hxx>
      28             : 
      29             : #include <vector>
      30             : 
      31             : class DateTime;
      32             : 
      33             : class INetMessageHeader
      34             : {
      35             :     OString m_aName;
      36             :     OString m_aValue;
      37             : 
      38             : public:
      39           0 :     INetMessageHeader()
      40           0 :     {}
      41             : 
      42           0 :     INetMessageHeader (
      43             :         const OString& rName, const OString& rValue)
      44           0 :         : m_aName (rName), m_aValue (rValue)
      45           0 :     {}
      46             : 
      47           0 :     INetMessageHeader (
      48             :         const INetMessageHeader& rHdr)
      49           0 :         : m_aName (rHdr.m_aName), m_aValue (rHdr.m_aValue)
      50           0 :     {}
      51             : 
      52           0 :     ~INetMessageHeader()
      53           0 :     {}
      54             : 
      55             :     INetMessageHeader& operator= (const INetMessageHeader& rHdr)
      56             :     {
      57             :         m_aName  = rHdr.m_aName;
      58             :         m_aValue = rHdr.m_aValue;
      59             :         return *this;
      60             :     }
      61             : 
      62           0 :     const OString& GetName() const { return m_aName; }
      63           0 :     const OString& GetValue() const { return m_aValue; }
      64             : 
      65           0 :     friend SvStream& operator<< (
      66             :         SvStream& rStrm, const INetMessageHeader& rHdr)
      67             :     {
      68           0 :         write_lenPrefixed_uInt8s_FromOString<sal_uInt16>(rStrm, rHdr.m_aName);
      69           0 :         write_lenPrefixed_uInt8s_FromOString<sal_uInt16>(rStrm, rHdr.m_aValue);
      70           0 :         return rStrm;
      71             :     }
      72             : 
      73           0 :     friend SvStream& operator>> (
      74             :         SvStream& rStrm, INetMessageHeader& rHdr)
      75             :     {
      76           0 :         rHdr.m_aName = read_lenPrefixed_uInt8s_ToOString<sal_uInt16>(rStrm);
      77           0 :         rHdr.m_aValue = read_lenPrefixed_uInt8s_ToOString<sal_uInt16>(rStrm);
      78           0 :         return rStrm;
      79             :     }
      80             : };
      81             : 
      82             : typedef ::std::vector< INetMessageHeader* > HeaderList_impl;
      83             : 
      84             : class INetMessage
      85             : {
      86             :     HeaderList_impl m_aHeaderList;
      87             : 
      88             :     sal_uIntPtr     m_nDocSize;
      89             :     OUString        m_aDocName;
      90             :     SvLockBytesRef  m_xDocLB;
      91             : 
      92             :     void ListCleanup_Impl();
      93             :     void ListCopy (const INetMessage& rMsg);
      94             : 
      95             : protected:
      96             :     OUString GetHeaderName_Impl (
      97             :         sal_uIntPtr nIndex, rtl_TextEncoding eEncoding) const
      98             :     {
      99             :         if ( nIndex < m_aHeaderList.size() ) {
     100             :             return OStringToOUString(m_aHeaderList[ nIndex ]->GetName(), eEncoding);
     101             :         } else {
     102             :             return OUString();
     103             :         }
     104             :     }
     105             : 
     106           0 :     OUString GetHeaderValue_Impl (
     107             :         sal_uIntPtr nIndex, INetMIME::HeaderFieldType eType) const
     108             :     {
     109           0 :         if ( nIndex < m_aHeaderList.size() ) {
     110           0 :             return INetMIME::decodeHeaderFieldBody(eType, m_aHeaderList[ nIndex ]->GetValue());
     111             :         } else {
     112           0 :             return OUString();
     113             :         }
     114             :     }
     115             : 
     116           0 :     void SetHeaderField_Impl (
     117             :         const INetMessageHeader &rHeader, sal_uIntPtr &rnIndex)
     118             :     {
     119           0 :         INetMessageHeader *p = new INetMessageHeader (rHeader);
     120           0 :         if (m_aHeaderList.size() <= rnIndex)
     121             :         {
     122           0 :             rnIndex = m_aHeaderList.size();
     123           0 :             m_aHeaderList.push_back( p );
     124             :         }
     125             :         else
     126             :         {
     127           0 :             delete m_aHeaderList[ rnIndex ];
     128           0 :             m_aHeaderList[ rnIndex ] = p;
     129             :         }
     130           0 :     }
     131             : 
     132             :     void SetHeaderField_Impl (
     133             :         INetMIME::HeaderFieldType  eType,
     134             :         const OString &rName,
     135             :         const OUString &rValue,
     136             :         sal_uIntPtr &rnIndex);
     137             : 
     138             :     virtual SvStream& operator<< (SvStream& rStrm) const;
     139             :     virtual SvStream& operator>> (SvStream& rStrm);
     140             : 
     141             : public:
     142           0 :     INetMessage() : m_nDocSize(0) {}
     143             :     virtual ~INetMessage();
     144             : 
     145           0 :     INetMessage (const INetMessage& rMsg)
     146             :         : m_nDocSize (rMsg.m_nDocSize),
     147             :           m_aDocName (rMsg.m_aDocName),
     148           0 :           m_xDocLB   (rMsg.m_xDocLB)
     149             :     {
     150           0 :         ListCopy (rMsg);
     151           0 :     }
     152             : 
     153           0 :     INetMessage& operator= (const INetMessage& rMsg)
     154             :     {
     155           0 :         m_nDocSize = rMsg.m_nDocSize;
     156           0 :         m_aDocName = rMsg.m_aDocName;
     157           0 :         m_xDocLB   = rMsg.m_xDocLB;
     158           0 :         ListCopy (rMsg);
     159           0 :         return *this;
     160             :     }
     161             : 
     162           0 :     sal_uIntPtr GetHeaderCount() const { return m_aHeaderList.size(); }
     163             : 
     164             :     OUString GetHeaderName (sal_uIntPtr nIndex) const
     165             :     {
     166             :         return GetHeaderName_Impl (nIndex, RTL_TEXTENCODING_ASCII_US);
     167             :     }
     168             : 
     169           0 :     OUString GetHeaderValue (sal_uIntPtr nIndex) const
     170             :     {
     171           0 :         return GetHeaderValue_Impl (nIndex, INetMIME::HEADER_FIELD_TEXT);
     172             :     }
     173             : 
     174           0 :     INetMessageHeader GetHeaderField (sal_uIntPtr nIndex) const
     175             :     {
     176           0 :         if ( nIndex < m_aHeaderList.size() ) {
     177           0 :             return INetMessageHeader( *m_aHeaderList[ nIndex ] );
     178             :         } else {
     179           0 :             return INetMessageHeader();
     180             :         }
     181             :     }
     182             : 
     183             :     virtual sal_uIntPtr SetHeaderField (
     184             :         const INetMessageHeader &rField,
     185             :         sal_uIntPtr nIndex = ((sal_uIntPtr)-1)
     186             :     );
     187             : 
     188           0 :     sal_uIntPtr GetDocumentSize() const { return m_nDocSize; }
     189           0 :     void  SetDocumentSize (sal_uIntPtr nSize) { m_nDocSize = nSize; }
     190             : 
     191             :     const OUString& GetDocumentName() const { return m_aDocName; }
     192             :     void  SetDocumentName (const OUString& rName) { m_aDocName = rName; }
     193             : 
     194           0 :     SvLockBytes* GetDocumentLB() const { return m_xDocLB; }
     195           0 :     void         SetDocumentLB (SvLockBytes *pDocLB) { m_xDocLB = pDocLB; }
     196             : 
     197             :     friend SvStream& operator<< (
     198             :         SvStream& rStrm, const INetMessage& rMsg)
     199             :     {
     200             :         return rMsg.operator<< (rStrm);
     201             :     }
     202             : 
     203             :     friend SvStream& operator>> (
     204             :         SvStream& rStrm, INetMessage& rMsg)
     205             :     {
     206             :         return rMsg.operator>> (rStrm);
     207             :     }
     208             : };
     209             : 
     210             : #define INETMSG_RFC822_BCC                 0
     211             : #define INETMSG_RFC822_CC                  1
     212             : #define INETMSG_RFC822_COMMENTS            2
     213             : #define INETMSG_RFC822_DATE                3
     214             : #define INETMSG_RFC822_FROM                4
     215             : #define INETMSG_RFC822_IN_REPLY_TO         5
     216             : #define INETMSG_RFC822_KEYWORDS            6
     217             : #define INETMSG_RFC822_MESSAGE_ID          7
     218             : #define INETMSG_RFC822_REFERENCES          8
     219             : #define INETMSG_RFC822_REPLY_TO            9
     220             : #define INETMSG_RFC822_RETURN_PATH        10
     221             : #define INETMSG_RFC822_SENDER             11
     222             : #define INETMSG_RFC822_SUBJECT            12
     223             : #define INETMSG_RFC822_TO                 13
     224             : #define INETMSG_RFC822_X_MAILER           14
     225             : #define INETMSG_RFC822_RETURN_RECEIPT_TO  15
     226             : #define INETMSG_RFC822_NUMHDR             16
     227             : 
     228             : class TOOLS_DLLPUBLIC INetRFC822Message : public INetMessage
     229             : {
     230             :     sal_uIntPtr m_nIndex[INETMSG_RFC822_NUMHDR];
     231             : 
     232             : protected:
     233             :     virtual SvStream& operator<< (SvStream& rStrm) const;
     234             :     virtual SvStream& operator>> (SvStream& rStrm);
     235             : 
     236             : public:
     237             :     INetRFC822Message();
     238             :     INetRFC822Message (const INetRFC822Message& rMsg);
     239             :     virtual ~INetRFC822Message();
     240             : 
     241             :     INetRFC822Message& operator= (const INetRFC822Message& rMsg);
     242             : 
     243             :     static bool ParseDateField (
     244             :         const OUString& rDateField, DateTime& rDateTime);
     245             : 
     246             :     using INetMessage::SetHeaderField;
     247             :     virtual sal_uIntPtr SetHeaderField (
     248             :         const INetMessageHeader &rHeader,
     249             :         sal_uIntPtr nIndex = ((sal_uIntPtr)-1)
     250             :     );
     251             : 
     252             :     // Header fields.
     253             : 
     254             :     OUString GetBCC() const
     255             :     {
     256             :         return GetHeaderValue_Impl (
     257             :             m_nIndex[INETMSG_RFC822_BCC],
     258             :             INetMIME::HEADER_FIELD_ADDRESS);
     259             :     }
     260             : 
     261             :     OUString GetCC() const
     262             :     {
     263             :         return GetHeaderValue_Impl (
     264             :             m_nIndex[INETMSG_RFC822_CC],
     265             :             INetMIME::HEADER_FIELD_ADDRESS);
     266             :     }
     267             : 
     268             :     OUString GetComments() const
     269             :     {
     270             :         return GetHeaderValue_Impl (
     271             :             m_nIndex[INETMSG_RFC822_COMMENTS],
     272             :             INetMIME::HEADER_FIELD_TEXT);
     273             :     }
     274             : 
     275             :     OUString GetDate() const
     276             :     {
     277             :         return GetHeaderValue_Impl (
     278             :             m_nIndex[INETMSG_RFC822_DATE],
     279             :             INetMIME::HEADER_FIELD_STRUCTURED);
     280             :     }
     281             : 
     282             :     OUString GetFrom() const
     283             :     {
     284             :         return GetHeaderValue_Impl (
     285             :             m_nIndex[INETMSG_RFC822_FROM],
     286             :             INetMIME::HEADER_FIELD_ADDRESS);
     287             :     }
     288             : 
     289             :     OUString GetInReplyTo() const
     290             :     {
     291             :         return GetHeaderValue_Impl (
     292             :             m_nIndex[INETMSG_RFC822_IN_REPLY_TO],
     293             :             INetMIME::HEADER_FIELD_ADDRESS); // ??? MESSAGE_ID ???
     294             :     }
     295             : 
     296             :     OUString GetKeywords() const
     297             :     {
     298             :         return GetHeaderValue_Impl (
     299             :             m_nIndex[INETMSG_RFC822_KEYWORDS],
     300             :             INetMIME::HEADER_FIELD_PHRASE);
     301             :     }
     302             : 
     303             :     OUString GetMessageID() const
     304             :     {
     305             :         return GetHeaderValue_Impl (
     306             :             m_nIndex[INETMSG_RFC822_MESSAGE_ID],
     307             :             INetMIME::HEADER_FIELD_MESSAGE_ID);
     308             :     }
     309             : 
     310             :     OUString GetReferences() const
     311             :     {
     312             :         return GetHeaderValue_Impl (
     313             :             m_nIndex[INETMSG_RFC822_REFERENCES],
     314             :             INetMIME::HEADER_FIELD_ADDRESS);
     315             :     }
     316             : 
     317             :     OUString GetReplyTo() const
     318             :     {
     319             :         return GetHeaderValue_Impl (
     320             :             m_nIndex[INETMSG_RFC822_REPLY_TO],
     321             :             INetMIME::HEADER_FIELD_ADDRESS);
     322             :     }
     323             : 
     324             :     OUString GetReturnPath() const
     325             :     {
     326             :         return GetHeaderValue_Impl (
     327             :             m_nIndex[INETMSG_RFC822_RETURN_PATH],
     328             :             INetMIME::HEADER_FIELD_ADDRESS);
     329             :     }
     330             : 
     331             :     OUString GetReturnReceiptTo() const
     332             :     {
     333             :         return GetHeaderValue_Impl (
     334             :             m_nIndex[INETMSG_RFC822_RETURN_RECEIPT_TO],
     335             :             INetMIME::HEADER_FIELD_ADDRESS);
     336             :     }
     337             : 
     338             :     OUString GetSender() const
     339             :     {
     340             :         return GetHeaderValue_Impl (
     341             :             m_nIndex[INETMSG_RFC822_SENDER],
     342             :             INetMIME::HEADER_FIELD_ADDRESS);
     343             :     }
     344             : 
     345             :     OUString GetSubject() const
     346             :     {
     347             :         return GetHeaderValue_Impl (
     348             :             m_nIndex[INETMSG_RFC822_SUBJECT],
     349             :             INetMIME::HEADER_FIELD_TEXT);
     350             :     }
     351             : 
     352             :     OUString GetTo() const
     353             :     {
     354             :         return GetHeaderValue_Impl (
     355             :             m_nIndex[INETMSG_RFC822_TO],
     356             :             INetMIME::HEADER_FIELD_TEXT);
     357             :     }
     358             : 
     359             :     // Stream operators.
     360             : 
     361             :     friend SvStream& operator<< (
     362             :         SvStream& rStrm, const INetRFC822Message& rMsg)
     363             :     {
     364             :         return rMsg.operator<< (rStrm);
     365             :     }
     366             : 
     367             :     friend SvStream& operator>> (
     368             :         SvStream& rStrm, INetRFC822Message& rMsg)
     369             :     {
     370             :         return rMsg.operator>> (rStrm);
     371             :     }
     372             : };
     373             : 
     374             : #define INETMSG_MIME_VERSION                    0
     375             : #define INETMSG_MIME_CONTENT_DESCRIPTION        1
     376             : #define INETMSG_MIME_CONTENT_DISPOSITION        2
     377             : #define INETMSG_MIME_CONTENT_ID                 3
     378             : #define INETMSG_MIME_CONTENT_TYPE               4
     379             : #define INETMSG_MIME_CONTENT_TRANSFER_ENCODING  5
     380             : #define INETMSG_MIME_NUMHDR                     6
     381             : 
     382             : enum INetMessageContainerType
     383             : {
     384             :     INETMSG_MESSAGE_RFC822,
     385             :     INETMSG_MULTIPART_MIXED,
     386             :     INETMSG_MULTIPART_ALTERNATIVE,
     387             :     INETMSG_MULTIPART_DIGEST,
     388             :     INETMSG_MULTIPART_PARALLEL,
     389             :     INETMSG_MULTIPART_RELATED,
     390             :     INETMSG_MULTIPART_FORM_DATA
     391             : };
     392             : 
     393             : class INetMIMEMessage;
     394             : typedef ::std::vector< INetMIMEMessage* > INetMIMEMessgeList_impl;
     395             : 
     396             : class TOOLS_DLLPUBLIC INetMIMEMessage : public INetRFC822Message
     397             : {
     398             :     sal_uIntPtr             m_nIndex[INETMSG_MIME_NUMHDR];
     399             :     INetMIMEMessage*        pParent;
     400             :     INetMIMEMessgeList_impl aChildren;
     401             :     OString                 m_aBoundary;
     402             :     bool                    bHeaderParsed;
     403             : 
     404             :     friend class INetMIMEMessageStream;
     405             : 
     406           0 :     const OString& GetMultipartBoundary() const { return m_aBoundary; }
     407           0 :     void SetMultipartBoundary (const OString& rBnd) { m_aBoundary = rBnd; }
     408             : 
     409             :     void CleanupImp();
     410             :     void CopyImp    (const INetMIMEMessage& rMsg);
     411           0 :     void SetHeaderParsed() { bHeaderParsed = sal_True; }
     412             : 
     413             : protected:
     414             :     virtual SvStream& operator<< (SvStream& rStrm) const;
     415             :     virtual SvStream& operator>> (SvStream& rStrm);
     416             : 
     417             : public:
     418             :     INetMIMEMessage();
     419             :     INetMIMEMessage (const INetMIMEMessage& rMsg);
     420             :     virtual ~INetMIMEMessage();
     421             : 
     422             :     INetMIMEMessage& operator= (const INetMIMEMessage& rMsg);
     423             : 
     424             :     bool HeaderParsed() const { return bHeaderParsed; }
     425             : 
     426             :     virtual INetMIMEMessage* CreateMessage (
     427             :         const INetMIMEMessage& rMsg) const;
     428             : 
     429             :     using INetRFC822Message::SetHeaderField;
     430             :     virtual sal_uIntPtr SetHeaderField (
     431             :         const INetMessageHeader &rHeader,
     432             :         sal_uIntPtr nIndex = ((sal_uIntPtr)-1)
     433             :     );
     434             : 
     435             :     // Header fields.
     436             : 
     437             :     void     SetMIMEVersion (const OUString& rVersion);
     438             :     OUString GetMIMEVersion() const
     439             :     {
     440             :         return GetHeaderValue (m_nIndex[INETMSG_MIME_VERSION]);
     441             :     }
     442             : 
     443             :     OUString GetContentDescription() const
     444             :     {
     445             :         return GetHeaderValue (m_nIndex[INETMSG_MIME_CONTENT_DESCRIPTION]);
     446             :     }
     447             : 
     448             :     void     SetContentDisposition (const OUString& rDisposition);
     449             :     OUString GetContentDisposition() const
     450             :     {
     451             :         return GetHeaderValue (m_nIndex[INETMSG_MIME_CONTENT_DISPOSITION]);
     452             :     }
     453             : 
     454             :     OUString GetContentID() const
     455             :     {
     456             :         return GetHeaderValue (m_nIndex[INETMSG_MIME_CONTENT_ID]);
     457             :     }
     458             : 
     459             :     void     SetContentType (const OUString& rType);
     460           0 :     OUString GetContentType() const
     461             :     {
     462           0 :         return GetHeaderValue (m_nIndex[INETMSG_MIME_CONTENT_TYPE]);
     463             :     }
     464             : 
     465             :     void     SetContentTransferEncoding (const OUString& rEncoding);
     466           0 :     OUString GetContentTransferEncoding() const
     467             :     {
     468           0 :         return GetHeaderValue (m_nIndex[INETMSG_MIME_CONTENT_TRANSFER_ENCODING]);
     469             :     }
     470             : 
     471             :     OUString GetDefaultContentType ();
     472             : 
     473             :     // Message container methods.
     474             : 
     475           0 :     bool IsContainer() const
     476             :     {
     477           0 :         return (IsMessage() || IsMultipart());
     478             :     }
     479           0 :     bool IsMessage() const
     480             :     {
     481           0 :         OUString aType (GetContentType());
     482           0 :         return aType.matchIgnoreAsciiCase("message/");
     483             :     }
     484           0 :     bool IsMultipart() const
     485             :     {
     486           0 :         OUString aType (GetContentType());
     487           0 :         return aType.matchIgnoreAsciiCase("multipart/");
     488             :     }
     489             : 
     490           0 :     INetMIMEMessage* GetChild (sal_uIntPtr nIndex) const
     491             :     {
     492           0 :         return ( nIndex < aChildren.size() ) ? aChildren[ nIndex ] : NULL;
     493             :     }
     494           0 :     INetMIMEMessage* GetParent() const { return pParent; }
     495             : 
     496             :     bool EnableAttachChild (
     497             :         INetMessageContainerType eType = INETMSG_MULTIPART_MIXED);
     498             :     bool AttachChild (
     499             :         INetMIMEMessage& rChildMsg, bool bOwner = true );
     500             : 
     501             :     // Stream operators.
     502             : 
     503             :     friend SvStream& operator<< (
     504             :         SvStream& rStrm, const INetMIMEMessage& rMsg)
     505             :     {
     506             :         return rMsg.operator<< (rStrm);
     507             :     }
     508             : 
     509             :     friend SvStream& operator>> (
     510             :         SvStream& rStrm, INetMIMEMessage& rMsg)
     511             :     {
     512             :         return rMsg.operator>> (rStrm);
     513             :     }
     514             : };
     515             : 
     516             : #endif
     517             : 
     518             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10