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.

205 lines
4.5 KiB

  1. // groups.cpp : Implementation of CsmtpadmApp and DLL registration.
  2. #include "stdafx.h"
  3. #include "smtpadm.h"
  4. #include "alias.h"
  5. #include "oleutil.h"
  6. #include "smtpapi.h"
  7. #include <lmapibuf.h>
  8. #include "smtpcmn.h"
  9. // Must define THIS_FILE_* macros to use SmtpCreateException()
  10. #define THIS_FILE_HELP_CONTEXT 0
  11. #define THIS_FILE_PROG_ID _T("Smtpadm.Alias.1")
  12. #define THIS_FILE_IID IID_ISmtpAdminAlias
  13. #define DEFAULT_NEWSGROUP_NAME _T("")
  14. #define DEFAULT_NEWSGROUP_DESCRIPTION _T("")
  15. #define DEFAULT_NEWSGROUP_MODERATOR _T("")
  16. #define DEFAULT_NEWSGROUP_READONLY FALSE
  17. /////////////////////////////////////////////////////////////////////////////
  18. //
  19. //
  20. // Use a macro to define all the default methods
  21. //
  22. DECLARE_METHOD_IMPLEMENTATION_FOR_STANDARD_EXTENSION_INTERFACES(SmtpAdminAlias, CSmtpAdminAlias, IID_ISmtpAdminAlias)
  23. STDMETHODIMP CSmtpAdminAlias::InterfaceSupportsErrorInfo(REFIID riid)
  24. {
  25. static const IID* arr[] =
  26. {
  27. &IID_ISmtpAdminAlias,
  28. };
  29. for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
  30. {
  31. if (InlineIsEqualGUID(*arr[i],riid))
  32. return S_OK;
  33. }
  34. return S_FALSE;
  35. }
  36. CSmtpAdminAlias::CSmtpAdminAlias () :
  37. m_lCount ( 0 ),
  38. m_lType ( NAME_TYPE_USER )
  39. // CComBSTR's are initialized to NULL by default.
  40. {
  41. InitAsyncTrace ( );
  42. m_pSmtpNameList = NULL;
  43. m_iadsImpl.SetService ( MD_SERVICE_NAME );
  44. m_iadsImpl.SetName ( _T("Alias") );
  45. m_iadsImpl.SetClass ( _T("IIsSmtpAlias") );
  46. }
  47. CSmtpAdminAlias::~CSmtpAdminAlias ()
  48. {
  49. if ( m_pSmtpNameList ) {
  50. ::NetApiBufferFree ( m_pSmtpNameList );
  51. }
  52. // All CComBSTR's are freed automatically.
  53. }
  54. //
  55. // IADs methods:
  56. //
  57. DECLARE_SIMPLE_IADS_IMPLEMENTATION(CSmtpAdminAlias,m_iadsImpl)
  58. //////////////////////////////////////////////////////////////////////
  59. // Properties:
  60. //////////////////////////////////////////////////////////////////////
  61. STDMETHODIMP CSmtpAdminAlias::get_Count ( long* plCount )
  62. {
  63. return StdPropertyGet ( m_lCount, plCount );
  64. }
  65. // The current alias's properties:
  66. STDMETHODIMP CSmtpAdminAlias::get_EmailId ( BSTR * pstrEmailId )
  67. {
  68. return StdPropertyGet ( m_strEmailId, pstrEmailId );
  69. }
  70. STDMETHODIMP CSmtpAdminAlias::put_EmailId ( BSTR strEmailId )
  71. {
  72. return StdPropertyPut ( &strEmailId, strEmailId );
  73. }
  74. STDMETHODIMP CSmtpAdminAlias::get_Domain ( BSTR * pstrDomain )
  75. {
  76. return StdPropertyGet ( m_strDomain, pstrDomain );
  77. }
  78. STDMETHODIMP CSmtpAdminAlias::put_Domain ( BSTR strDomain )
  79. {
  80. return StdPropertyPut ( &m_strDomain, strDomain );
  81. }
  82. STDMETHODIMP CSmtpAdminAlias::get_Type ( long* plType )
  83. {
  84. return StdPropertyGet ( m_lType, plType );
  85. }
  86. STDMETHODIMP CSmtpAdminAlias::put_Type ( long lType )
  87. {
  88. return StdPropertyPut ( &m_lType, lType );
  89. }
  90. //////////////////////////////////////////////////////////////////////
  91. // Methods:
  92. //////////////////////////////////////////////////////////////////////
  93. STDMETHODIMP CSmtpAdminAlias::Find (
  94. BSTR strWildmat,
  95. long cMaxResults
  96. )
  97. {
  98. TraceFunctEnter ( "CSmtpAdminAlias::Find" );
  99. HRESULT hr = NOERROR;
  100. DWORD dwErr = NOERROR;
  101. // Free the old newsgroup list:
  102. if ( m_pSmtpNameList ) {
  103. ::NetApiBufferFree ( m_pSmtpNameList );
  104. m_pSmtpNameList = NULL;
  105. }
  106. m_lCount = 0;
  107. dwErr = SmtpGetNameList (
  108. m_iadsImpl.QueryComputer(),
  109. strWildmat,
  110. NAME_TYPE_ALL,
  111. cMaxResults,
  112. TRUE,
  113. &m_pSmtpNameList,
  114. m_iadsImpl.QueryInstance());
  115. if ( dwErr != 0 ) {
  116. ErrorTraceX ( (LPARAM) this, "Failed to find alias: %x", dwErr );
  117. SetLastError( dwErr );
  118. hr = SmtpCreateExceptionFromWin32Error ( dwErr );
  119. goto Exit;
  120. }
  121. m_lCount = m_pSmtpNameList->cEntries;
  122. Exit:
  123. TraceFunctLeave ();
  124. return hr;
  125. }
  126. STDMETHODIMP CSmtpAdminAlias::GetNth( long lIndex )
  127. {
  128. _ASSERT( lIndex >=0 && lIndex < m_lCount );
  129. WCHAR* pchStartOfDomain = NULL;
  130. WCHAR* p = NULL;
  131. LPSMTP_NAME_ENTRY pNameEntry;
  132. if( !m_pSmtpNameList )
  133. {
  134. return SmtpCreateException (IDS_SMTPEXCEPTION_DIDNT_ENUMERATE);
  135. }
  136. if( lIndex < 0 || lIndex >= m_lCount )
  137. {
  138. return SmtpCreateException (IDS_SMTPEXCEPTION_INVALID_INDEX);
  139. }
  140. //_ASSERT( CAddr::ValidateEmailName(m_pSmtpNameList[lIndex].lpszName) );
  141. pNameEntry = &m_pSmtpNameList->aNameEntry[lIndex];
  142. p = pNameEntry->lpszName;
  143. while( *p && *p != '@' ) p++;
  144. _ASSERT( *p );
  145. if( !*p )
  146. {
  147. return SmtpCreateException (IDS_SMTPEXCEPTION_INVALID_ADDRESS);
  148. }
  149. pchStartOfDomain = p+1;
  150. m_lType = pNameEntry->dwType;
  151. m_strDomain = (LPCWSTR) pchStartOfDomain;
  152. *(pchStartOfDomain-1) = '\0';
  153. m_strEmailId = pNameEntry->lpszName; // converted to UNICODE
  154. *(pchStartOfDomain-1) = '@'; // turn it back
  155. return NOERROR;
  156. }