1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #ifndef _TOOLS_INETMSG_HXX 28 #define _TOOLS_INETMSG_HXX 29 30 #include "tools/toolsdllapi.h" 31 #include <sal/types.h> 32 33 #ifndef _RTL_TEXTENC_H_ 34 #include <rtl/textenc.h> 35 #endif 36 37 #ifndef _TOOLS_INETMIME_HXX 38 #include <tools/inetmime.hxx> 39 #endif 40 #include <tools/list.hxx> 41 #include <tools/stream.hxx> 42 #include <tools/string.hxx> 43 44 class DateTime; 45 46 /*======================================================================= 47 * 48 * INetMessageHeader Interface. 49 * 50 *=====================================================================*/ 51 class INetMessageHeader 52 { 53 ByteString m_aName; 54 ByteString m_aValue; 55 56 public: 57 INetMessageHeader (void) 58 {} 59 60 INetMessageHeader ( 61 const ByteString& rName, const ByteString& rValue) 62 : m_aName (rName), m_aValue (rValue) 63 {} 64 65 INetMessageHeader ( 66 const INetMessageHeader& rHdr) 67 : m_aName (rHdr.m_aName), m_aValue (rHdr.m_aValue) 68 {} 69 70 ~INetMessageHeader (void) 71 {} 72 73 INetMessageHeader& operator= (const INetMessageHeader& rHdr) 74 { 75 m_aName = rHdr.m_aName; 76 m_aValue = rHdr.m_aValue; 77 return *this; 78 } 79 80 const ByteString& GetName (void) const { return m_aName; } 81 const ByteString& GetValue (void) const { return m_aValue; } 82 83 friend SvStream& operator<< ( 84 SvStream& rStrm, const INetMessageHeader& rHdr) 85 { 86 #ifdef ENABLE_BYTESTRING_STREAM_OPERATORS 87 rStrm << rHdr.m_aName; 88 rStrm << rHdr.m_aValue; 89 #else 90 rStrm.WriteByteString (rHdr.m_aName); 91 rStrm.WriteByteString (rHdr.m_aValue); 92 #endif 93 return rStrm; 94 } 95 96 friend SvStream& operator>> ( 97 SvStream& rStrm, INetMessageHeader& rHdr) 98 { 99 #ifdef ENABLE_BYTESTRING_STREAM_OPERATORS 100 rStrm >> rHdr.m_aName; 101 rStrm >> rHdr.m_aValue; 102 #else 103 rStrm.ReadByteString (rHdr.m_aName); 104 rStrm.ReadByteString (rHdr.m_aValue); 105 #endif 106 return rStrm; 107 } 108 }; 109 110 /*======================================================================= 111 * 112 * INetMessage Interface. 113 * 114 *=====================================================================*/ 115 class INetMessage 116 { 117 List m_aHeaderList; 118 119 sal_uIntPtr m_nDocSize; 120 UniString m_aDocName; 121 SvLockBytesRef m_xDocLB; 122 123 void ListCleanup_Impl (void); 124 void ListCopy (const INetMessage& rMsg); 125 126 protected: 127 UniString GetHeaderName_Impl ( 128 sal_uIntPtr nIndex, rtl_TextEncoding eEncoding) const 129 { 130 INetMessageHeader *p = 131 (INetMessageHeader*)(m_aHeaderList.GetObject(nIndex)); 132 if (p) 133 return UniString(p->GetName(), eEncoding); 134 else 135 return UniString(); 136 } 137 138 UniString GetHeaderValue_Impl ( 139 sal_uIntPtr nIndex, INetMIME::HeaderFieldType eType) const 140 { 141 INetMessageHeader *p = 142 (INetMessageHeader*)(m_aHeaderList.GetObject(nIndex)); 143 if (p) 144 return INetMIME::decodeHeaderFieldBody (eType, p->GetValue()); 145 else 146 return UniString(); 147 } 148 149 void SetHeaderField_Impl ( 150 const INetMessageHeader &rHeader, sal_uIntPtr &rnIndex) 151 { 152 INetMessageHeader *p = new INetMessageHeader (rHeader); 153 if (m_aHeaderList.Count() <= rnIndex) 154 { 155 m_aHeaderList.Insert (p, LIST_APPEND); 156 rnIndex = m_aHeaderList.Count() - 1; 157 } 158 else 159 { 160 p = (INetMessageHeader*)(m_aHeaderList.Replace(p, rnIndex)); 161 delete p; 162 } 163 } 164 165 void SetHeaderField_Impl ( 166 INetMIME::HeaderFieldType eType, 167 const ByteString &rName, 168 const UniString &rValue, 169 sal_uIntPtr &rnIndex); 170 171 virtual SvStream& operator<< (SvStream& rStrm) const; 172 virtual SvStream& operator>> (SvStream& rStrm); 173 174 public: 175 INetMessage (void) : m_nDocSize(0) {} 176 virtual ~INetMessage (void); 177 178 INetMessage (const INetMessage& rMsg) 179 : m_nDocSize (rMsg.m_nDocSize), 180 m_aDocName (rMsg.m_aDocName), 181 m_xDocLB (rMsg.m_xDocLB) 182 { 183 ListCopy (rMsg); 184 } 185 186 INetMessage& operator= (const INetMessage& rMsg) 187 { 188 m_nDocSize = rMsg.m_nDocSize; 189 m_aDocName = rMsg.m_aDocName; 190 m_xDocLB = rMsg.m_xDocLB; 191 ListCopy (rMsg); 192 return *this; 193 } 194 195 sal_uIntPtr GetHeaderCount (void) const { return m_aHeaderList.Count(); } 196 197 UniString GetHeaderName (sal_uIntPtr nIndex) const 198 { 199 return GetHeaderName_Impl (nIndex, RTL_TEXTENCODING_ASCII_US); 200 } 201 202 UniString GetHeaderValue (sal_uIntPtr nIndex) const 203 { 204 return GetHeaderValue_Impl (nIndex, INetMIME::HEADER_FIELD_TEXT); 205 } 206 207 INetMessageHeader GetHeaderField (sal_uIntPtr nIndex) const 208 { 209 INetMessageHeader *p = 210 (INetMessageHeader*)(m_aHeaderList.GetObject(nIndex)); 211 if (p) 212 return INetMessageHeader(*p); 213 else 214 return INetMessageHeader(); 215 } 216 217 sal_uIntPtr SetHeaderField ( 218 const UniString& rName, 219 const UniString& rValue, 220 sal_uIntPtr nIndex = LIST_APPEND); 221 222 virtual sal_uIntPtr SetHeaderField ( 223 const INetMessageHeader &rField, sal_uIntPtr nIndex = LIST_APPEND); 224 225 sal_uIntPtr GetDocumentSize (void) const { return m_nDocSize; } 226 void SetDocumentSize (sal_uIntPtr nSize) { m_nDocSize = nSize; } 227 228 const UniString& GetDocumentName (void) const { return m_aDocName; } 229 void SetDocumentName (const UniString& rName) { m_aDocName = rName; } 230 231 SvLockBytes* GetDocumentLB (void) const { return m_xDocLB; } 232 void SetDocumentLB (SvLockBytes *pDocLB) { m_xDocLB = pDocLB; } 233 234 friend SvStream& operator<< ( 235 SvStream& rStrm, const INetMessage& rMsg) 236 { 237 return rMsg.operator<< (rStrm); 238 } 239 240 friend SvStream& operator>> ( 241 SvStream& rStrm, INetMessage& rMsg) 242 { 243 return rMsg.operator>> (rStrm); 244 } 245 }; 246 247 /*======================================================================= 248 * 249 * INetMessageHeaderIterator Interface. 250 * 251 *=====================================================================*/ 252 class INetMessageHeaderIterator 253 { 254 sal_uIntPtr nValueCount; 255 List aValueList; 256 UniString aEmptyString; 257 258 public: 259 INetMessageHeaderIterator ( 260 const INetMessage& rMsg, const UniString& rHdrName); 261 virtual ~INetMessageHeaderIterator (void); 262 263 sal_uIntPtr GetValueCount (void) const { return nValueCount; } 264 const UniString& GetValue (sal_uIntPtr nIndex) const 265 { 266 if (nIndex < nValueCount) 267 { 268 return *((UniString*)(aValueList.GetObject(nIndex))); 269 } 270 else 271 { 272 return aEmptyString; 273 } 274 } 275 }; 276 277 /*======================================================================= 278 * 279 * INetRFC822Message Interface. 280 * 281 *=====================================================================*/ 282 #define INETMSG_RFC822_BCC 0 283 #define INETMSG_RFC822_CC 1 284 #define INETMSG_RFC822_COMMENTS 2 285 #define INETMSG_RFC822_DATE 3 286 #define INETMSG_RFC822_FROM 4 287 #define INETMSG_RFC822_IN_REPLY_TO 5 288 #define INETMSG_RFC822_KEYWORDS 6 289 #define INETMSG_RFC822_MESSAGE_ID 7 290 #define INETMSG_RFC822_REFERENCES 8 291 #define INETMSG_RFC822_REPLY_TO 9 292 #define INETMSG_RFC822_RETURN_PATH 10 293 #define INETMSG_RFC822_SENDER 11 294 #define INETMSG_RFC822_SUBJECT 12 295 #define INETMSG_RFC822_TO 13 296 297 #define INETMSG_RFC822_X_MAILER 14 298 #define INETMSG_RFC822_RETURN_RECEIPT_TO 15 299 300 #define INETMSG_RFC822_NUMHDR 16 301 302 class TOOLS_DLLPUBLIC INetRFC822Message : public INetMessage 303 { 304 sal_uIntPtr m_nIndex[INETMSG_RFC822_NUMHDR]; 305 306 protected: 307 virtual SvStream& operator<< (SvStream& rStrm) const; 308 virtual SvStream& operator>> (SvStream& rStrm); 309 310 public: 311 INetRFC822Message (void); 312 INetRFC822Message (const INetRFC822Message& rMsg); 313 virtual ~INetRFC822Message (void); 314 315 INetRFC822Message& operator= (const INetRFC822Message& rMsg); 316 317 static sal_Bool GenerateDateField ( 318 const DateTime& rDateTime, UniString& rDateField); 319 static sal_Bool ParseDateField ( 320 const UniString& rDateField, DateTime& rDateTime); 321 322 using INetMessage::SetHeaderField; 323 virtual sal_uIntPtr SetHeaderField ( 324 const INetMessageHeader &rHeader, sal_uIntPtr nIndex = LIST_APPEND); 325 326 /** Header fields. 327 */ 328 void SetBCC (const UniString& rBCC); 329 UniString GetBCC (void) const 330 { 331 return GetHeaderValue_Impl ( 332 m_nIndex[INETMSG_RFC822_BCC], 333 INetMIME::HEADER_FIELD_ADDRESS); 334 } 335 336 void SetCC (const UniString& rCC); 337 UniString GetCC (void) const 338 { 339 return GetHeaderValue_Impl ( 340 m_nIndex[INETMSG_RFC822_CC], 341 INetMIME::HEADER_FIELD_ADDRESS); 342 } 343 344 void SetComments (const UniString& rComments); 345 UniString GetComments (void) const 346 { 347 return GetHeaderValue_Impl ( 348 m_nIndex[INETMSG_RFC822_COMMENTS], 349 INetMIME::HEADER_FIELD_TEXT); 350 } 351 352 void SetDate (const UniString& rDate); 353 UniString GetDate (void) const 354 { 355 return GetHeaderValue_Impl ( 356 m_nIndex[INETMSG_RFC822_DATE], 357 INetMIME::HEADER_FIELD_STRUCTURED); 358 } 359 360 void SetFrom (const UniString& rFrom); 361 UniString GetFrom (void) const 362 { 363 return GetHeaderValue_Impl ( 364 m_nIndex[INETMSG_RFC822_FROM], 365 INetMIME::HEADER_FIELD_ADDRESS); 366 } 367 368 void SetInReplyTo (const UniString& rInReplyTo); 369 UniString GetInReplyTo (void) const 370 { 371 return GetHeaderValue_Impl ( 372 m_nIndex[INETMSG_RFC822_IN_REPLY_TO], 373 INetMIME::HEADER_FIELD_ADDRESS); // ??? MESSAGE_ID ??? 374 } 375 376 void SetKeywords (const UniString& rKeywords); 377 UniString GetKeywords (void) const 378 { 379 return GetHeaderValue_Impl ( 380 m_nIndex[INETMSG_RFC822_KEYWORDS], 381 INetMIME::HEADER_FIELD_PHRASE); 382 } 383 384 void SetMessageID (const UniString& rMessageID); 385 UniString GetMessageID (void) const 386 { 387 return GetHeaderValue_Impl ( 388 m_nIndex[INETMSG_RFC822_MESSAGE_ID], 389 INetMIME::HEADER_FIELD_MESSAGE_ID); 390 } 391 392 void SetReferences (const UniString& rReferences); 393 UniString GetReferences (void) const 394 { 395 return GetHeaderValue_Impl ( 396 m_nIndex[INETMSG_RFC822_REFERENCES], 397 INetMIME::HEADER_FIELD_ADDRESS); 398 } 399 400 void SetReplyTo (const UniString& rReplyTo); 401 UniString GetReplyTo (void) const 402 { 403 return GetHeaderValue_Impl ( 404 m_nIndex[INETMSG_RFC822_REPLY_TO], 405 INetMIME::HEADER_FIELD_ADDRESS); 406 } 407 408 void SetReturnPath (const UniString& rReturnPath); 409 UniString GetReturnPath (void) const 410 { 411 return GetHeaderValue_Impl ( 412 m_nIndex[INETMSG_RFC822_RETURN_PATH], 413 INetMIME::HEADER_FIELD_ADDRESS); 414 } 415 416 void SetReturnReceiptTo (const UniString& rReturnReceiptTo); 417 UniString GetReturnReceiptTo (void) const 418 { 419 return GetHeaderValue_Impl ( 420 m_nIndex[INETMSG_RFC822_RETURN_RECEIPT_TO], 421 INetMIME::HEADER_FIELD_ADDRESS); 422 } 423 424 void SetSender (const UniString& rSender); 425 UniString GetSender (void) const 426 { 427 return GetHeaderValue_Impl ( 428 m_nIndex[INETMSG_RFC822_SENDER], 429 INetMIME::HEADER_FIELD_ADDRESS); 430 } 431 432 void SetSubject (const UniString& rSubject); 433 UniString GetSubject (void) const 434 { 435 return GetHeaderValue_Impl ( 436 m_nIndex[INETMSG_RFC822_SUBJECT], 437 INetMIME::HEADER_FIELD_TEXT); 438 } 439 440 void SetTo (const UniString& rTo); 441 UniString GetTo (void) const 442 { 443 return GetHeaderValue_Impl ( 444 m_nIndex[INETMSG_RFC822_TO], 445 INetMIME::HEADER_FIELD_TEXT); 446 } 447 448 void SetXMailer (const UniString& rXMailer); 449 UniString GetXMailer (void) const 450 { 451 return GetHeaderValue_Impl ( 452 m_nIndex[INETMSG_RFC822_X_MAILER], 453 INetMIME::HEADER_FIELD_TEXT); 454 } 455 456 /** Stream operators. 457 */ 458 friend SvStream& operator<< ( 459 SvStream& rStrm, const INetRFC822Message& rMsg) 460 { 461 return rMsg.operator<< (rStrm); 462 } 463 464 friend SvStream& operator>> ( 465 SvStream& rStrm, INetRFC822Message& rMsg) 466 { 467 return rMsg.operator>> (rStrm); 468 } 469 }; 470 471 /*======================================================================= 472 * 473 * INetMIMEMessage Interface. 474 * 475 *=====================================================================*/ 476 #define INETMSG_MIME_VERSION 0 477 #define INETMSG_MIME_CONTENT_DESCRIPTION 1 478 #define INETMSG_MIME_CONTENT_DISPOSITION 2 479 #define INETMSG_MIME_CONTENT_ID 3 480 #define INETMSG_MIME_CONTENT_TYPE 4 481 #define INETMSG_MIME_CONTENT_TRANSFER_ENCODING 5 482 483 #define INETMSG_MIME_NUMHDR 6 484 485 enum INetMessageContainerType 486 { 487 INETMSG_MESSAGE_RFC822, 488 INETMSG_MULTIPART_MIXED, 489 INETMSG_MULTIPART_ALTERNATIVE, 490 INETMSG_MULTIPART_DIGEST, 491 INETMSG_MULTIPART_PARALLEL, 492 INETMSG_MULTIPART_RELATED, 493 INETMSG_MULTIPART_FORM_DATA 494 }; 495 496 class TOOLS_DLLPUBLIC INetMIMEMessage : public INetRFC822Message 497 { 498 sal_uIntPtr m_nIndex[INETMSG_MIME_NUMHDR]; 499 500 INetMIMEMessage *pParent; 501 sal_uIntPtr nNumChildren; 502 List aChildren; 503 ByteString m_aBoundary; 504 sal_Bool bHeaderParsed; 505 506 friend class INetMIMEMessageStream; 507 508 void SetChildCount (sal_uIntPtr nCount) { nNumChildren = nCount; } 509 const ByteString& GetMultipartBoundary (void) const { return m_aBoundary; } 510 void SetMultipartBoundary (const ByteString& rBnd) { m_aBoundary = rBnd; } 511 512 void CleanupImp (void); 513 void CopyImp (const INetMIMEMessage& rMsg); 514 void SetHeaderParsed() { bHeaderParsed = sal_True; } 515 516 protected: 517 virtual SvStream& operator<< (SvStream& rStrm) const; 518 virtual SvStream& operator>> (SvStream& rStrm); 519 520 public: 521 INetMIMEMessage (void); 522 INetMIMEMessage (const INetMIMEMessage& rMsg); 523 virtual ~INetMIMEMessage (void); 524 525 INetMIMEMessage& operator= (const INetMIMEMessage& rMsg); 526 527 sal_Bool HeaderParsed() const { return bHeaderParsed; } 528 529 virtual INetMIMEMessage* CreateMessage ( 530 const INetMIMEMessage& rMsg) const; 531 532 using INetRFC822Message::SetHeaderField; 533 virtual sal_uIntPtr SetHeaderField ( 534 const INetMessageHeader &rHeader, sal_uIntPtr nIndex = LIST_APPEND); 535 536 /** Header fields. 537 */ 538 void SetMIMEVersion (const UniString& rVersion); 539 UniString GetMIMEVersion (void) const 540 { 541 return GetHeaderValue (m_nIndex[INETMSG_MIME_VERSION]); 542 } 543 544 void SetContentDescription (const UniString& rDescription); 545 UniString GetContentDescription (void) const 546 { 547 return GetHeaderValue (m_nIndex[INETMSG_MIME_CONTENT_DESCRIPTION]); 548 } 549 550 void SetContentDisposition (const UniString& rDisposition); 551 UniString GetContentDisposition (void) const 552 { 553 return GetHeaderValue (m_nIndex[INETMSG_MIME_CONTENT_DISPOSITION]); 554 } 555 556 void SetContentID (const UniString& rID); 557 UniString GetContentID (void) const 558 { 559 return GetHeaderValue (m_nIndex[INETMSG_MIME_CONTENT_ID]); 560 } 561 562 void SetContentType (const UniString& rType); 563 UniString GetContentType (void) const 564 { 565 return GetHeaderValue (m_nIndex[INETMSG_MIME_CONTENT_TYPE]); 566 } 567 568 void SetContentTransferEncoding (const UniString& rEncoding); 569 UniString GetContentTransferEncoding (void) const 570 { 571 return GetHeaderValue (m_nIndex[INETMSG_MIME_CONTENT_TRANSFER_ENCODING]); 572 } 573 574 virtual void GetDefaultContentType (UniString& rContentType); 575 576 /** Message container methods. 577 */ 578 sal_Bool IsContainer (void) const 579 { 580 return (IsMessage() || IsMultipart()); 581 } 582 sal_Bool IsMessage (void) const 583 { 584 UniString aType (GetContentType()); 585 return (aType.CompareIgnoreCaseToAscii("message/", 8) == 0); 586 } 587 sal_Bool IsMultipart (void) const 588 { 589 UniString aType (GetContentType()); 590 return (aType.CompareIgnoreCaseToAscii("multipart/", 10) == 0); 591 } 592 593 sal_uIntPtr GetChildCount (void) const { return nNumChildren; } 594 INetMIMEMessage* GetChild (sal_uIntPtr nIndex) const 595 { 596 return ((INetMIMEMessage *)(aChildren.GetObject (nIndex))); 597 } 598 INetMIMEMessage* GetParent (void) const { return pParent; } 599 600 sal_Bool EnableAttachChild ( 601 INetMessageContainerType eType = INETMSG_MULTIPART_MIXED); 602 sal_Bool AttachChild ( 603 INetMIMEMessage& rChildMsg, sal_Bool bOwner = sal_True); 604 sal_Bool DetachChild ( 605 sal_uIntPtr nIndex, INetMIMEMessage& rChildMsg) const; 606 607 /** Stream operators. 608 */ 609 friend SvStream& operator<< ( 610 SvStream& rStrm, const INetMIMEMessage& rMsg) 611 { 612 return rMsg.operator<< (rStrm); 613 } 614 615 friend SvStream& operator>> ( 616 SvStream& rStrm, INetMIMEMessage& rMsg) 617 { 618 return rMsg.operator>> (rStrm); 619 } 620 }; 621 622 #endif /* !_TOOLS_INETMSG_HXX */ 623 624