Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name :
  4. address.hxx
  5. Abstract:
  6. This module defines the CAddrList class.
  7. Author:
  8. Rohan Phillips ( Rohanp ) 11-Dec-1995
  9. Project:
  10. SMTP Server DLL
  11. Revision History:
  12. --*/
  13. #ifndef _ADDR_LIST_HXX_
  14. #define _ADDR_LIST_HXX_
  15. /************************************************************
  16. * Include Headers
  17. ************************************************************/
  18. /************************************************************
  19. * Symbolic Constants
  20. ************************************************************/
  21. #define ADDRESS_SIGNATURE_VALID 0x49414444 // IADD
  22. #define ADDRESS_SIGNATURE_FREE 0x44444149 // DDAI
  23. #define MAX_EMAIL_NAME 64
  24. #define MAX_DOMAIN_NAME 250
  25. #define MAX_INTERNET_NAME (MAX_EMAIL_NAME + MAX_DOMAIN_NAME + 2) // 2 for @ and \0
  26. /************************************************************
  27. * Type Definitions
  28. ************************************************************/
  29. #define ADDRESS_LOCAL 0x00000001 // A local address (e.g. MSN.COM)
  30. #define ADDRESS_NO_DOMAIN 0x00000002 // No domain specified
  31. #define ADDRESS_EXPANDED 0x00000004 // Expands (contains % or equiv.)
  32. #define ADDRESS_INTERNET 0x00000008 // Has been processed by munging
  33. #define ADDRESS_SAME_DOMAIN 0x00000010 // Same domain as predecessor
  34. #define ADDRESS_REMOVE_PENDING 0x00000020 // Remove pending
  35. #define ADDRESS_OUTSTANDING 0x00000040 // Address still in use
  36. #define ADDRESS_DONT_SEND 0x00000080 // Don't send this address
  37. #define ADDRESS_HASHED_ENTRY 0x00000100 // Don't send this address
  38. enum ADDRTYPE {FROMADDR, TOADDR, CLEANDOMAIN};
  39. /* struct CAddr
  40. This structure is used for keeping track of addresses that
  41. we need to send mail to. m_Flags can take on the values
  42. above.
  43. --*/
  44. class CAddr
  45. {
  46. private:
  47. DWORD m_Signature;
  48. DWORD m_PlainAddrSize;//strlen of m_PlainAddress
  49. DWORD m_Error; //error as to why this address could not receive mail
  50. DWORD m_Flags; //can be any of the following above ORed together
  51. char m_PlainAddress[MAX_INTERNET_NAME + 1]; //address given to us by client
  52. char * m_DomainOffset; //domain offset in m_PlainAddress
  53. void * m_HashInfo; //contains address book info
  54. DWORD m_dwAbInfoId; //intermediate info passing from AbResolveAddress
  55. // to AbResolveAddressEx (Note: the m_dwAbInfoId
  56. // may not correspond to its CAddr)
  57. //hide the comstructors
  58. CAddr(VOID);
  59. CAddr(char * Address);
  60. BOOL InitializeAddress(char * Address, ADDRTYPE NameType);
  61. public:
  62. //use CPool for better memory management
  63. static CPool Pool;
  64. // override the mem functions to use CPool functions
  65. void *operator new (size_t cSize)
  66. { return Pool.Alloc(); }
  67. void operator delete (void *pInstance)
  68. { Pool.Free(pInstance); }
  69. //LIST_ENTRY object for storing address in a list.
  70. LIST_ENTRY m_listEntry;
  71. ~CAddr( VOID);
  72. DWORD GetAddrSize(void) const {return m_PlainAddrSize;}
  73. char * GetAddress(void) const {return (char *) m_PlainAddress;}
  74. DWORD GetFlags(void) const {return m_Flags;}
  75. void SetFlags (DWORD Flag) {m_Flags |= Flag;}
  76. void ClearFlag (DWORD Flag) {m_Flags &= ~Flag;}
  77. BOOL IsDomainOffset(void) const {return (m_DomainOffset != NULL);}
  78. char * GetDomainOffset(void) const {return (char*) m_DomainOffset;}
  79. void SetHashInfo(void * pHashInfo) {m_HashInfo = pHashInfo;}
  80. void * GetHashInfo(void) const {return m_HashInfo;}
  81. DWORD GetErrorCode(void)const
  82. {_ASSERT(IsValid());
  83. return m_Error;
  84. }
  85. void SetErrorCode(DWORD ErrorCode) {m_Error = ErrorCode;}
  86. BOOL IsSameDomainAsPredecessor() const {return ((m_Flags & ADDRESS_SAME_DOMAIN) == ADDRESS_SAME_DOMAIN);}
  87. BOOL IsValid( VOID) const{return ( m_Signature == ADDRESS_SIGNATURE_VALID); }
  88. LIST_ENTRY & QueryListEntry(void) {return ( m_listEntry);}
  89. static CAddr * CreateAddress (char * Address, ADDRTYPE NameType = TOADDR);
  90. static CAddr * CreateKnownAddress (char * Address);
  91. BOOL ReplaceAddress(const char * NewAddress);
  92. static CAddr * GetFirstAddress(PLIST_ENTRY HeadOfList, PLIST_ENTRY * AddressLink);
  93. static CAddr * GetNextAddress(PLIST_ENTRY HeadOfList, PLIST_ENTRY * AddressLink);
  94. static void RemoveAllAddrs(PLIST_ENTRY HeadOfList);
  95. static void RemoveAddress(IN OUT CAddr * pEntry);
  96. static void InsertAddrHeadList(PLIST_ENTRY HeadOfList, IN CAddr *pEntry);
  97. static void InsertAddrTailList(PLIST_ENTRY HeadOfList, IN CAddr *pEntry);
  98. //
  99. // Address validation/cleanup methods
  100. //
  101. static BOOL ExtractCleanEmailName(char *lpszCleanEmail,
  102. char **ppszDomainOffset,
  103. DWORD *lpdwCleanEmailLength,
  104. char *lpszSource);
  105. static BOOL ValidateCleanEmailName(char *lpszCleanEmailName,
  106. char *lpszDomainOffset);
  107. static BOOL ValidateDomainName(char *lpszDomainName);
  108. static BOOL ValidateEmailName(char *lpszEmailName,
  109. BOOL fDomainOptional = FALSE);
  110. static CHAR * FindStartOfDomain(CHAR *lpszCleanEmail);
  111. //Counts the number of addresses in a RFC822 address list
  112. static DWORD GetRFC822AddressCount(char *szAddressList);
  113. static BOOL IsRecipientInRFC822AddressList(char *szAddressList,
  114. char *szRecip);
  115. };
  116. #endif