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 INCLUDED_TOOLS_INETMSG_HXX 20 #define INCLUDED_TOOLS_INETMSG_HXX 21 22 #include 23 #include 24 #include 25 #include 26 #include 27 #include 28 29 #include 30 #include 31 32 class DateTime; 33 34 class INetMessageHeader 35 { 36 OString m_aName; 37 OString m_aValue; 38 39 public: 40 INetMessageHeader() 41 {} 42 43 INetMessageHeader ( 44 const OString& rName, const OString& rValue) 45 : m_aName (rName), m_aValue (rValue) 46 {} 47 48 INetMessageHeader ( 49 const INetMessageHeader& rHdr) 50 : m_aName (rHdr.m_aName), m_aValue (rHdr.m_aValue) 51 {} 52 53 ~INetMessageHeader() 54 {} 55 56 INetMessageHeader& operator= (const INetMessageHeader& rHdr) 57 { 58 m_aName = rHdr.m_aName; 59 m_aValue = rHdr.m_aValue; 60 return *this; 61 } 62 63 const OString& GetName() const { return m_aName; } 64 const OString& GetValue() const { return m_aValue; } 65 66 friend SvStream& WriteINetMessageHeader( 67 SvStream& rStrm, const INetMessageHeader& rHdr) 68 { 69 write_uInt16_lenPrefixed_uInt8s_FromOString(rStrm, rHdr.m_aName); 70 write_uInt16_lenPrefixed_uInt8s_FromOString(rStrm, rHdr.m_aValue); 71 return rStrm; 72 } 73 74 friend SvStream& ReadINetMessageHeader ( 75 SvStream& rStrm, INetMessageHeader& rHdr) 76 { 77 rHdr.m_aName = read_uInt16_lenPrefixed_uInt8s_ToOString(rStrm); 78 rHdr.m_aValue = read_uInt16_lenPrefixed_uInt8s_ToOString(rStrm); 79 return rStrm; 80 } 81 }; 82 83 typedef ::std::vector< INetMessageHeader* > HeaderList_impl; 84 85 /** 86 RFC822 fields 87 */ 88 enum class InetMessageField 89 { 90 BCC = 0, 91 CC = 1, 92 COMMENTS = 2, 93 DATE = 3, 94 FROM = 4, 95 IN_REPLY_TO = 5, 96 KEYWORDS = 6, 97 MESSAGE_ID = 7, 98 REFERENCES = 8, 99 REPLY_TO = 9, 100 RETURN_PATH = 10, 101 SENDER = 11, 102 SUBJECT = 12, 103 TO = 13, 104 X_MAILER = 14, 105 RETURN_RECEIPT_TO = 15, 106 NUMHDR = 16, 107 }; 108 109 enum class InetMessageMime 110 { 111 VERSION = 0, 112 CONTENT_DESCRIPTION = 1, 113 CONTENT_DISPOSITION = 2, 114 CONTENT_ID = 3, 115 CONTENT_TYPE = 4, 116 CONTENT_TRANSFER_ENCODING = 5, 117 NUMHDR = 6, 118 }; 119 120 enum INetMessageContainerType 121 { 122 INETMSG_MESSAGE_RFC822, 123 INETMSG_MULTIPART_MIXED, 124 INETMSG_MULTIPART_ALTERNATIVE, 125 INETMSG_MULTIPART_DIGEST, 126 INETMSG_MULTIPART_PARALLEL, 127 INETMSG_MULTIPART_RELATED, 128 INETMSG_MULTIPART_FORM_DATA 129 }; 130 131 class INetMIMEMessage; 132 typedef ::std::vector< INetMIMEMessage* > INetMIMEMessgeList_impl; 133 134 class TOOLS_DLLPUBLIC INetMIMEMessage 135 { 136 HeaderList_impl m_aHeaderList; 137 138 sal_uIntPtr m_nDocSize; 139 OUString m_aDocName; 140 SvLockBytesRef m_xDocLB; 141 142 void ListCleanup_Impl(); 143 void ListCopy (const INetMIMEMessage& rMsg); 144 145 ::std::map m_nRFC822Index; 146 147 ::std::map m_nMIMEIndex; 148 INetMIMEMessage* pParent; 149 INetMIMEMessgeList_impl aChildren; 150 OString m_aBoundary; 151 bool bHeaderParsed; 152 153 friend class INetMIMEMessageStream; 154 155 const OString& GetMultipartBoundary() const { return m_aBoundary; } 156 void SetMultipartBoundary (const OString& rBnd) { m_aBoundary = rBnd; } 157 158 void CleanupImp(); 159 void CopyImp (const INetMIMEMessage& rMsg); 160 void SetHeaderParsed() { bHeaderParsed = true; } 161 162 OUString GetHeaderName_Impl ( 163 sal_uInt64 nIndex, rtl_TextEncoding eEncoding) const 164 { 165 if ( nIndex < m_aHeaderList.size() ) { 166 return OStringToOUString(m_aHeaderList[ nIndex ]->GetName(), eEncoding); 167 } else { 168 return OUString(); 169 } 170 } 171 172 OUString GetHeaderValue_Impl ( 173 sal_uInt64 nIndex, INetMIME::HeaderFieldType eType) const 174 { 175 if ( nIndex < m_aHeaderList.size() ) { 176 return INetMIME::decodeHeaderFieldBody(eType, m_aHeaderList[ nIndex ]->GetValue()); 177 } else { 178 return OUString(); 179 } 180 } 181 182 void SetHeaderField_Impl ( 183 const INetMessageHeader &rHeader, sal_uIntPtr &rnIndex) 184 { 185 INetMessageHeader *p = new INetMessageHeader (rHeader); 186 if (m_aHeaderList.size() <= rnIndex) 187 { 188 rnIndex = m_aHeaderList.size(); 189 m_aHeaderList.push_back( p ); 190 } 191 else 192 { 193 delete m_aHeaderList[ rnIndex ]; 194 m_aHeaderList[ rnIndex ] = p; 195 } 196 } 197 198 void SetHeaderField_Impl ( 199 INetMIME::HeaderFieldType eType, 200 const OString &rName, 201 const OUString &rValue, 202 sal_uIntPtr &rnIndex); 203 204 sal_uIntPtr SetRFC822HeaderField ( 205 const INetMessageHeader &rHeader, sal_uIntPtr nNewIndex); 206 207 public: 208 INetMIMEMessage(); 209 INetMIMEMessage (const INetMIMEMessage& rMsg); 210 ~INetMIMEMessage(); 211 212 INetMIMEMessage& operator= (const INetMIMEMessage& rMsg); 213 214 sal_uInt64 GetHeaderCount() const { return m_aHeaderList.size(); } 215 216 OUString GetHeaderName (sal_uInt64 nIndex) const 217 { 218 return GetHeaderName_Impl (nIndex, RTL_TEXTENCODING_ASCII_US); 219 } 220 221 OUString GetHeaderValue (sal_uInt64 nIndex) const 222 { 223 return GetHeaderValue_Impl (nIndex, INetMIME::HEADER_FIELD_TEXT); 224 } 225 226 INetMessageHeader GetHeaderField (sal_uInt64 nIndex) const 227 { 228 if ( nIndex < m_aHeaderList.size() ) { 229 return INetMessageHeader( *m_aHeaderList[ nIndex ] ); 230 } else { 231 return INetMessageHeader(); 232 } 233 } 234 235 sal_uIntPtr SetHeaderField ( 236 const INetMessageHeader &rField, 237 sal_uIntPtr nIndex = ((sal_uIntPtr)-1) 238 ); 239 240 sal_uInt64 GetDocumentSize() const { return m_nDocSize; } 241 void SetDocumentSize (sal_uInt64 nSize) { m_nDocSize = nSize; } 242 243 const OUString& GetDocumentName() const { return m_aDocName; } 244 void SetDocumentName (const OUString& rName) { m_aDocName = rName; } 245 246 SvLockBytes* GetDocumentLB() const { return m_xDocLB; } 247 void SetDocumentLB (SvLockBytes *pDocLB) { m_xDocLB = pDocLB; } 248 249 static bool ParseDateField ( 250 const OUString& rDateField, DateTime& rDateTime); 251 252 bool HeaderParsed() const { return bHeaderParsed; } 253 254 INetMIMEMessage* CreateMessage ( 255 const INetMIMEMessage& rMsg) const; 256 257 // Header fields. 258 259 OUString GetBCC() const 260 { 261 return GetHeaderValue_Impl ( 262 m_nRFC822Index.at(InetMessageField::BCC), 263 INetMIME::HEADER_FIELD_ADDRESS); 264 } 265 266 OUString GetCC() const 267 { 268 return GetHeaderValue_Impl ( 269 m_nRFC822Index.at(InetMessageField::CC), 270 INetMIME::HEADER_FIELD_ADDRESS); 271 } 272 273 OUString GetComments() const 274 { 275 return GetHeaderValue_Impl ( 276 m_nRFC822Index.at(InetMessageField::COMMENTS), 277 INetMIME::HEADER_FIELD_TEXT); 278 } 279 280 OUString GetDate() const 281 { 282 return GetHeaderValue_Impl ( 283 m_nRFC822Index.at(InetMessageField::DATE), 284 INetMIME::HEADER_FIELD_STRUCTURED); 285 } 286 287 OUString GetFrom() const 288 { 289 return GetHeaderValue_Impl ( 290 m_nRFC822Index.at(InetMessageField::FROM), 291 INetMIME::HEADER_FIELD_ADDRESS); 292 } 293 294 OUString GetInReplyTo() const 295 { 296 return GetHeaderValue_Impl ( 297 m_nRFC822Index.at(InetMessageField::REPLY_TO), 298 INetMIME::HEADER_FIELD_ADDRESS); // ??? MESSAGE_ID ??? 299 } 300 301 OUString GetKeywords() const 302 { 303 return GetHeaderValue_Impl ( 304 m_nRFC822Index.at(InetMessageField::KEYWORDS), 305 INetMIME::HEADER_FIELD_PHRASE); 306 } 307 308 OUString GetMessageID() const 309 { 310 return GetHeaderValue_Impl ( 311 m_nRFC822Index.at(InetMessageField::MESSAGE_ID), 312 INetMIME::HEADER_FIELD_MESSAGE_ID); 313 } 314 315 OUString GetReferences() const 316 { 317 return GetHeaderValue_Impl ( 318 m_nRFC822Index.at(InetMessageField::REFERENCES), 319 INetMIME::HEADER_FIELD_ADDRESS); 320 } 321 322 OUString GetReplyTo() const 323 { 324 return GetHeaderValue_Impl ( 325 m_nRFC822Index.at(InetMessageField::REPLY_TO), 326 INetMIME::HEADER_FIELD_ADDRESS); 327 } 328 329 OUString GetReturnPath() const 330 { 331 return GetHeaderValue_Impl ( 332 m_nRFC822Index.at(InetMessageField::RETURN_PATH), 333 INetMIME::HEADER_FIELD_ADDRESS); 334 } 335 336 OUString GetReturnReceiptTo() const 337 { 338 return GetHeaderValue_Impl ( 339 m_nRFC822Index.at(InetMessageField::RETURN_RECEIPT_TO), 340 INetMIME::HEADER_FIELD_ADDRESS); 341 } 342 343 OUString GetSender() const 344 { 345 return GetHeaderValue_Impl ( 346 m_nRFC822Index.at(InetMessageField::SENDER), 347 INetMIME::HEADER_FIELD_ADDRESS); 348 } 349 350 OUString GetSubject() const 351 { 352 return GetHeaderValue_Impl ( 353 m_nRFC822Index.at(InetMessageField::SUBJECT), 354 INetMIME::HEADER_FIELD_TEXT); 355 } 356 357 OUString GetTo() const 358 { 359 return GetHeaderValue_Impl ( 360 m_nRFC822Index.at(InetMessageField::TO), 361 INetMIME::HEADER_FIELD_TEXT); 362 } 363 364 void SetMIMEVersion (const OUString& rVersion); 365 OUString GetMIMEVersion() const 366 { 367 return GetHeaderValue (m_nMIMEIndex.at(InetMessageMime::VERSION)); 368 } 369 370 OUString GetContentDescription() const 371 { 372 return GetHeaderValue (m_nMIMEIndex.at(InetMessageMime::CONTENT_DESCRIPTION)); 373 } 374 375 void SetContentDisposition (const OUString& rDisposition); 376 OUString GetContentDisposition() const 377 { 378 return GetHeaderValue (m_nMIMEIndex.at(InetMessageMime::CONTENT_DISPOSITION)); 379 } 380 381 OUString GetContentID() const 382 { 383 return GetHeaderValue (m_nMIMEIndex.at(InetMessageMime::CONTENT_ID)); 384 } 385 386 void SetContentType (const OUString& rType); 387 OUString GetContentType() const 388 { 389 return GetHeaderValue (m_nMIMEIndex.at(InetMessageMime::CONTENT_TYPE)); 390 } 391 392 void SetContentTransferEncoding (const OUString& rEncoding); 393 OUString GetContentTransferEncoding() const 394 { 395 return GetHeaderValue (m_nMIMEIndex.at(InetMessageMime::CONTENT_TRANSFER_ENCODING)); 396 } 397 398 OUString GetDefaultContentType (); 399 400 // Message container methods. 401 402 bool IsContainer() const 403 { 404 return (IsMessage() || IsMultipart()); 405 } 406 bool IsMessage() const 407 { 408 OUString aType (GetContentType()); 409 return aType.matchIgnoreAsciiCase("message/"); 410 } 411 bool IsMultipart() const 412 { 413 OUString aType (GetContentType()); 414 return aType.matchIgnoreAsciiCase("multipart/"); 415 } 416 417 INetMIMEMessage* GetChild (sal_uInt64 nIndex) const 418 { 419 return ( nIndex < aChildren.size() ) ? aChildren[ nIndex ] : NULL; 420 } 421 INetMIMEMessage* GetParent() const { return pParent; } 422 423 bool EnableAttachChild ( 424 INetMessageContainerType eType = INETMSG_MULTIPART_MIXED); 425 bool AttachChild ( 426 INetMIMEMessage& rChildMsg, bool bOwner = true ); 427 }; 428 429 #endif 430 431 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 432