Leaked source code of windows server 2003
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.

688 lines
17 KiB

  1. // groups.cpp : Implementation of CnntpadmApp and DLL registration.
  2. #include "stdafx.h"
  3. #include "nntpcmn.h"
  4. #include "oleutil.h"
  5. #include "groups.h"
  6. #include <lmapibuf.h>
  7. // Must define THIS_FILE_* macros to use NntpCreateException()
  8. #define THIS_FILE_HELP_CONTEXT 0
  9. #define THIS_FILE_PROG_ID _T("Nntpadm.Groups.1")
  10. #define THIS_FILE_IID IID_INntpAdminGroups
  11. #define DEFAULT_NEWSGROUP_NAME _T("")
  12. #define DEFAULT_NEWSGROUP_DESCRIPTION _T("")
  13. #define DEFAULT_NEWSGROUP_PRETTYNAME _T("")
  14. #define DEFAULT_NEWSGROUP_MODERATED FALSE
  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(NntpAdminGroups, CNntpAdminGroups, IID_INntpAdminGroups)
  23. STDMETHODIMP CNntpAdminGroups::InterfaceSupportsErrorInfo(REFIID riid)
  24. {
  25. static const IID* arr[] =
  26. {
  27. &IID_INntpAdminGroups,
  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. CNntpAdminGroups::CNntpAdminGroups () :
  37. m_fModerated ( FALSE ),
  38. m_fReadOnly ( FALSE ),
  39. m_dateCreation ( 0 ),
  40. m_pFindList ( NULL ),
  41. m_cMatchingGroups ( 0 )
  42. // CComBSTR's are initialized to NULL by default.
  43. {
  44. InitAsyncTrace ( );
  45. m_iadsImpl.SetService ( MD_SERVICE_NAME );
  46. m_iadsImpl.SetName ( _T("Groups") );
  47. m_iadsImpl.SetClass ( _T("IIsNntpGroups") );
  48. }
  49. CNntpAdminGroups::~CNntpAdminGroups ()
  50. {
  51. if ( m_pFindList ) {
  52. ::NetApiBufferFree ( m_pFindList );
  53. }
  54. // All CComBSTR's are freed automatically.
  55. TermAsyncTrace ( );
  56. }
  57. //
  58. // IADs methods:
  59. //
  60. DECLARE_SIMPLE_IADS_IMPLEMENTATION(CNntpAdminGroups,m_iadsImpl)
  61. //////////////////////////////////////////////////////////////////////
  62. // Properties:
  63. //////////////////////////////////////////////////////////////////////
  64. // Enumeration Properties:
  65. STDMETHODIMP CNntpAdminGroups::get_Count ( long * plCount )
  66. {
  67. return StdPropertyGet ( m_cMatchingGroups, plCount );
  68. }
  69. STDMETHODIMP CNntpAdminGroups::get_Newsgroup ( BSTR * pstrNewsgroup )
  70. {
  71. return StdPropertyGet ( m_strNewsgroup, pstrNewsgroup );
  72. }
  73. STDMETHODIMP CNntpAdminGroups::put_Newsgroup ( BSTR strNewsgroup )
  74. {
  75. return StdPropertyPut ( &m_strNewsgroup, strNewsgroup );
  76. }
  77. STDMETHODIMP CNntpAdminGroups::get_Description ( BSTR * pstrDescription )
  78. {
  79. return StdPropertyGet ( m_strDescription, pstrDescription );
  80. }
  81. STDMETHODIMP CNntpAdminGroups::put_Description ( BSTR strDescription )
  82. {
  83. return StdPropertyPut ( &m_strDescription, strDescription );
  84. }
  85. STDMETHODIMP CNntpAdminGroups::get_PrettyName ( BSTR * pstrPrettyName )
  86. {
  87. return StdPropertyGet ( m_strPrettyName, pstrPrettyName );
  88. }
  89. STDMETHODIMP CNntpAdminGroups::put_PrettyName ( BSTR strPrettyName )
  90. {
  91. if ( strPrettyName && wcschr ( strPrettyName, _T('\n') ) ) {
  92. return E_INVALIDARG;
  93. }
  94. return StdPropertyPut ( &m_strPrettyName, strPrettyName );
  95. }
  96. STDMETHODIMP CNntpAdminGroups::get_IsModerated ( BOOL * pfIsModerated )
  97. {
  98. return StdPropertyGet ( m_fModerated, pfIsModerated );
  99. }
  100. STDMETHODIMP CNntpAdminGroups::put_IsModerated ( BOOL fIsModerated )
  101. {
  102. return StdPropertyPut ( &m_fModerated, fIsModerated );
  103. }
  104. STDMETHODIMP CNntpAdminGroups::get_Moderator ( BSTR * pstrModerator )
  105. {
  106. return StdPropertyGet ( m_strModerator, pstrModerator );
  107. }
  108. STDMETHODIMP CNntpAdminGroups::put_Moderator ( BSTR strModerator )
  109. {
  110. return StdPropertyPut ( &m_strModerator, strModerator );
  111. }
  112. STDMETHODIMP CNntpAdminGroups::get_ReadOnly ( BOOL * pfReadOnly )
  113. {
  114. return StdPropertyGet ( m_fReadOnly, pfReadOnly );
  115. }
  116. STDMETHODIMP CNntpAdminGroups::put_ReadOnly ( BOOL fReadOnly )
  117. {
  118. return StdPropertyPut ( &m_fReadOnly, fReadOnly );
  119. }
  120. STDMETHODIMP CNntpAdminGroups::get_CreationTime ( DATE * pdateCreation )
  121. {
  122. return StdPropertyGet ( m_dateCreation, pdateCreation );
  123. }
  124. STDMETHODIMP CNntpAdminGroups::put_CreationTime ( DATE dateCreation )
  125. {
  126. return StdPropertyPut ( &m_dateCreation, dateCreation );
  127. }
  128. STDMETHODIMP CNntpAdminGroups::get_MatchingCount ( long * plMatchingCount )
  129. {
  130. return StdPropertyGet ( m_cMatchingGroups, plMatchingCount );
  131. }
  132. //////////////////////////////////////////////////////////////////////
  133. // Methods:
  134. //////////////////////////////////////////////////////////////////////
  135. STDMETHODIMP CNntpAdminGroups::Default ( )
  136. {
  137. TraceFunctEnter ( "CNntpAdminGroups::Default" );
  138. SYSTEMTIME st;
  139. m_strNewsgroup = DEFAULT_NEWSGROUP_NAME;
  140. m_strDescription = DEFAULT_NEWSGROUP_DESCRIPTION;
  141. m_strPrettyName = DEFAULT_NEWSGROUP_PRETTYNAME;
  142. m_fModerated = DEFAULT_NEWSGROUP_MODERATED;
  143. m_strModerator = DEFAULT_NEWSGROUP_MODERATOR;
  144. m_fReadOnly = DEFAULT_NEWSGROUP_READONLY;
  145. GetLocalTime ( &st );
  146. SystemTimeToVariantTime ( &st, &m_dateCreation );
  147. if (
  148. !m_strNewsgroup ||
  149. !m_strDescription ||
  150. !m_strModerator
  151. ) {
  152. FatalTrace ( (LPARAM) this, "Out of memory" );
  153. return E_OUTOFMEMORY;
  154. }
  155. TraceFunctLeave ();
  156. return NOERROR;
  157. }
  158. STDMETHODIMP CNntpAdminGroups::Add ( )
  159. {
  160. TraceFunctEnter ( "CNntpAdminGroups::Add" );
  161. HRESULT hr = NOERROR;
  162. DWORD dwError = NOERROR;
  163. LPSTR szPrettyName = NULL;
  164. NNTP_NEWSGROUP_INFO newsgroup;
  165. ZeroMemory ( &newsgroup, sizeof ( newsgroup ) );
  166. _ASSERT ( m_strNewsgroup );
  167. hr = UnicodeToMime2 ( m_strPrettyName, &szPrettyName );
  168. BAIL_ON_FAILURE(hr);
  169. newsgroup.Newsgroup = (PUCHAR) (LPWSTR) m_strNewsgroup;
  170. newsgroup.cbNewsgroup = STRING_BYTE_LENGTH ( m_strNewsgroup );
  171. if ( szPrettyName && *szPrettyName ) {
  172. newsgroup.Prettyname = (PUCHAR) szPrettyName;
  173. newsgroup.cbPrettyname = strlen (szPrettyName) + sizeof(char);
  174. }
  175. else {
  176. newsgroup.Prettyname = NULL;
  177. newsgroup.cbPrettyname = 0;
  178. }
  179. newsgroup.Description = (PUCHAR) (LPWSTR) m_strDescription;
  180. newsgroup.cbDescription = STRING_BYTE_LENGTH ( m_strDescription );
  181. newsgroup.fIsModerated = m_fModerated;
  182. if ( m_strModerator == NULL || *m_strModerator == NULL ) {
  183. newsgroup.Moderator = NULL;
  184. newsgroup.cbModerator = 0;
  185. }
  186. else {
  187. newsgroup.Moderator = (PUCHAR) (LPWSTR) m_strModerator;
  188. newsgroup.cbModerator = STRING_BYTE_LENGTH ( m_strModerator );
  189. }
  190. newsgroup.ReadOnly = m_fReadOnly;
  191. dwError = NntpCreateNewsgroup (
  192. m_iadsImpl.QueryComputer(),
  193. m_iadsImpl.QueryInstance(),
  194. &newsgroup
  195. );
  196. if ( dwError != NOERROR ) {
  197. ErrorTrace ( (LPARAM) this, "Failed to add newsgroup: %x", dwError );
  198. hr = RETURNCODETOHRESULT ( dwError );
  199. goto Exit;
  200. }
  201. Exit:
  202. if ( szPrettyName ) {
  203. m_pMimeAlloc->Free ( szPrettyName );
  204. }
  205. TRACE_HRESULT(hr);
  206. TraceFunctLeave ();
  207. return hr;
  208. }
  209. STDMETHODIMP CNntpAdminGroups::Remove ( BSTR strNewsgroup )
  210. {
  211. TraceFunctEnter ( "CNntpAdminGroups::Remove" );
  212. _ASSERT ( IS_VALID_STRING ( strNewsgroup ) );
  213. HRESULT hr = NOERROR;
  214. DWORD dwError = NOERROR;
  215. NNTP_NEWSGROUP_INFO newsgroup;
  216. ZeroMemory ( &newsgroup, sizeof ( newsgroup ) );
  217. newsgroup.Newsgroup = (PUCHAR) (LPWSTR) strNewsgroup;
  218. newsgroup.cbNewsgroup = STRING_BYTE_LENGTH ( strNewsgroup );
  219. dwError = NntpDeleteNewsgroup (
  220. m_iadsImpl.QueryComputer(),
  221. m_iadsImpl.QueryInstance(),
  222. &newsgroup
  223. );
  224. if ( dwError != NOERROR ) {
  225. ErrorTrace ( (LPARAM) this, "Failed to remove newsgroup: %x", dwError );
  226. hr = RETURNCODETOHRESULT ( dwError );
  227. goto Exit;
  228. }
  229. Exit:
  230. TRACE_HRESULT(hr);
  231. TraceFunctLeave ();
  232. return hr;
  233. }
  234. STDMETHODIMP CNntpAdminGroups::Get ( BSTR strNewsgroup )
  235. {
  236. TraceFunctEnter ( "CNntpAdminGroups::Get" );
  237. _ASSERT ( IS_VALID_STRING ( strNewsgroup ) );
  238. HRESULT hr = NOERROR;
  239. DWORD dwError = NOERROR;
  240. NNTP_NEWSGROUP_INFO newsgroup;
  241. LPNNTP_NEWSGROUP_INFO pNewsgroup = &newsgroup;
  242. SYSTEMTIME st;
  243. FILETIME ftLocal;
  244. ZeroMemory ( &newsgroup, sizeof ( newsgroup ) );
  245. newsgroup.Newsgroup = (PUCHAR) (LPWSTR) strNewsgroup;
  246. newsgroup.cbNewsgroup = STRING_BYTE_LENGTH ( strNewsgroup );
  247. dwError = NntpGetNewsgroup (
  248. m_iadsImpl.QueryComputer(),
  249. m_iadsImpl.QueryInstance(),
  250. &pNewsgroup
  251. );
  252. if ( dwError != NOERROR ) {
  253. ErrorTrace ( (LPARAM) this, "Failed to get newsgroup: %x", dwError );
  254. hr = RETURNCODETOHRESULT ( dwError );
  255. goto Exit;
  256. }
  257. _ASSERT ( IS_VALID_STRING ( (LPWSTR) pNewsgroup->Newsgroup ) );
  258. m_strNewsgroup = pNewsgroup->Newsgroup ? (LPWSTR) pNewsgroup->Newsgroup : _T("");
  259. m_strDescription = pNewsgroup->Description ? (LPWSTR) pNewsgroup->Description : _T("");
  260. m_fModerated = pNewsgroup->fIsModerated;
  261. m_strModerator = pNewsgroup->Moderator ? (LPWSTR) pNewsgroup->Moderator : _T("");
  262. m_fReadOnly = pNewsgroup->ReadOnly;
  263. FileTimeToLocalFileTime ( &pNewsgroup->ftCreationDate, &ftLocal );
  264. FileTimeToSystemTime ( &ftLocal, &st );
  265. SystemTimeToVariantTime ( &st, &m_dateCreation );
  266. if ( pNewsgroup->Prettyname && *pNewsgroup->Prettyname ) {
  267. hr = Mime2ToUnicode ( (LPSTR) pNewsgroup->Prettyname, m_strPrettyName );
  268. if ( FAILED(hr) ) {
  269. m_strPrettyName = _T("");
  270. hr = NOERROR;
  271. }
  272. }
  273. else {
  274. m_strPrettyName = _T("");
  275. }
  276. if (
  277. !m_strNewsgroup ||
  278. !m_strDescription ||
  279. !m_strPrettyName ||
  280. !m_strModerator
  281. ) {
  282. FatalTrace ( (LPARAM) this, "Out of memory" );
  283. hr = E_OUTOFMEMORY;
  284. goto Exit;
  285. }
  286. Exit:
  287. if ( pNewsgroup && pNewsgroup != &newsgroup ) {
  288. NetApiBufferFree ( pNewsgroup );
  289. }
  290. TraceFunctLeave ();
  291. return hr;
  292. }
  293. STDMETHODIMP CNntpAdminGroups::Set ( )
  294. {
  295. TraceFunctEnter ( "CNntpAdminGroups::Set" );
  296. HRESULT hr = NOERROR;
  297. DWORD dwError = NOERROR;
  298. LPSTR szPrettyName = NULL;
  299. NNTP_NEWSGROUP_INFO newsgroup;
  300. SYSTEMTIME st;
  301. FILETIME ftLocal;
  302. ZeroMemory ( &newsgroup, sizeof ( newsgroup ) );
  303. _ASSERT ( m_strNewsgroup );
  304. hr = UnicodeToMime2 ( m_strPrettyName, &szPrettyName );
  305. BAIL_ON_FAILURE(hr);
  306. newsgroup.Newsgroup = (PUCHAR) (LPWSTR) m_strNewsgroup;
  307. newsgroup.cbNewsgroup = STRING_BYTE_LENGTH ( m_strNewsgroup );
  308. newsgroup.Description = (PUCHAR) (LPWSTR) m_strDescription;
  309. newsgroup.cbDescription = STRING_BYTE_LENGTH ( m_strDescription );
  310. if ( szPrettyName && *szPrettyName ) {
  311. newsgroup.Prettyname = (PUCHAR) szPrettyName;
  312. newsgroup.cbPrettyname = strlen (szPrettyName) + sizeof(char);
  313. }
  314. else {
  315. newsgroup.Prettyname = NULL;
  316. newsgroup.cbPrettyname = 0;
  317. }
  318. newsgroup.fIsModerated = m_fModerated;
  319. if ( m_strModerator == NULL || *m_strModerator == NULL ) {
  320. newsgroup.Moderator = NULL;
  321. newsgroup.cbModerator = 0;
  322. }
  323. else {
  324. newsgroup.Moderator = (PUCHAR) (LPWSTR) m_strModerator;
  325. newsgroup.cbModerator = STRING_BYTE_LENGTH ( m_strModerator );
  326. }
  327. newsgroup.ReadOnly = m_fReadOnly;
  328. VariantTimeToSystemTime ( m_dateCreation, &st );
  329. SystemTimeToFileTime ( &st, &ftLocal );
  330. LocalFileTimeToFileTime ( &ftLocal, &newsgroup.ftCreationDate );
  331. dwError = NntpSetNewsgroup (
  332. m_iadsImpl.QueryComputer(),
  333. m_iadsImpl.QueryInstance(),
  334. &newsgroup
  335. );
  336. if ( dwError != NOERROR ) {
  337. ErrorTrace ( (LPARAM) this, "Failed to set newsgroup: %x", dwError );
  338. hr = RETURNCODETOHRESULT ( dwError );
  339. goto Exit;
  340. }
  341. Exit:
  342. if ( szPrettyName ) {
  343. m_pMimeAlloc->Free ( szPrettyName );
  344. }
  345. TRACE_HRESULT(hr);
  346. TraceFunctLeave ();
  347. return hr;
  348. }
  349. STDMETHODIMP CNntpAdminGroups::MatchingGroup ( long iGroup, BSTR * pstrNewsgroup )
  350. {
  351. TraceFunctEnter ( "CNntpAdminGroups::MatchingGroup" );
  352. _ASSERT ( IS_VALID_OUT_PARAM ( pstrNewsgroup ) );
  353. HRESULT hr = NOERROR;
  354. if ( pstrNewsgroup == NULL ) {
  355. FatalTrace ( (LPARAM) this, "Bad return pointer" );
  356. TraceFunctLeave ();
  357. return E_POINTER;
  358. }
  359. *pstrNewsgroup = NULL;
  360. // Did we enumerate first?
  361. if ( m_pFindList == NULL ) {
  362. ErrorTrace ( (LPARAM) this, "Failed to call find first" );
  363. TraceFunctLeave ();
  364. return NntpCreateException ( IDS_NNTPEXCEPTION_DIDNT_FIND );
  365. }
  366. // Is the index valid?
  367. if ( iGroup < 0 || (DWORD) iGroup >= m_cMatchingGroups ) {
  368. ErrorTraceX ( (LPARAM) this, "Invalid index: %d", iGroup );
  369. TraceFunctLeave ();
  370. return NntpCreateException ( IDS_NNTPEXCEPTION_INVALID_INDEX );
  371. }
  372. _ASSERT ( IS_VALID_STRING ( m_pFindList->aFindEntry [ iGroup ].lpszName ) );
  373. // Copy the property into the result:
  374. *pstrNewsgroup = ::SysAllocString ( m_pFindList->aFindEntry [ iGroup ].lpszName );
  375. if ( *pstrNewsgroup == NULL ) {
  376. // Allocation failed.
  377. FatalTrace ( 0, "Out of memory" );
  378. hr = E_OUTOFMEMORY;
  379. }
  380. TRACE_HRESULT(hr);
  381. TraceFunctLeave ();
  382. return hr;
  383. }
  384. STDMETHODIMP CNntpAdminGroups::Find (
  385. BSTR strWildmat,
  386. long cMaxResults
  387. )
  388. {
  389. TraceFunctEnter ( "CNntpAdminGroups::Find" );
  390. HRESULT hr = NOERROR;
  391. DWORD dwError = NOERROR;
  392. // Free the old newsgroup list:
  393. if ( m_pFindList ) {
  394. ::NetApiBufferFree ( m_pFindList );
  395. m_pFindList = NULL;
  396. }
  397. m_cMatchingGroups = 0;
  398. dwError = NntpFindNewsgroup (
  399. m_iadsImpl.QueryComputer(),
  400. m_iadsImpl.QueryInstance(),
  401. strWildmat,
  402. cMaxResults,
  403. &m_cMatchingGroups,
  404. &m_pFindList
  405. );
  406. if ( dwError != 0 ) {
  407. ErrorTraceX ( (LPARAM) this, "Failed to find groups: %x", dwError );
  408. hr = RETURNCODETOHRESULT ( dwError );
  409. goto Exit;
  410. }
  411. Exit:
  412. TRACE_HRESULT(hr);
  413. TraceFunctLeave ();
  414. return hr;
  415. }
  416. HRESULT
  417. CNntpAdminGroups::CancelMessage (
  418. BSTR strMessageID
  419. )
  420. {
  421. TraceFunctEnter ( "CNntpAdminGroups::CancelMessage" );
  422. HRESULT hr = NOERROR;
  423. DWORD dwError = NOERROR;
  424. LPSTR szMessageID = NULL;
  425. int cchMessageID = 0;
  426. if ( !strMessageID ) {
  427. BAIL_WITH_FAILURE( hr, E_INVALIDARG );
  428. }
  429. cchMessageID = WideCharToMultiByte ( CP_ACP, 0, strMessageID, -1, NULL, 0, NULL, NULL );
  430. szMessageID = new char [ cchMessageID ];
  431. if ( !szMessageID ) {
  432. BAIL_WITH_FAILURE(hr, E_OUTOFMEMORY);
  433. }
  434. WideCharToMultiByte ( CP_ACP, 0, strMessageID, -1, szMessageID, cchMessageID, NULL, NULL );
  435. dwError = NntpCancelMessageID (
  436. m_iadsImpl.QueryComputer (),
  437. m_iadsImpl.QueryInstance (),
  438. szMessageID
  439. );
  440. if ( dwError != 0 ) {
  441. BAIL_WITH_FAILURE ( hr, RETURNCODETOHRESULT ( dwError ) );
  442. }
  443. Exit:
  444. delete [] szMessageID;
  445. TRACE_HRESULT(hr);
  446. TraceFunctLeave ();
  447. return hr;
  448. }
  449. HRESULT CNntpAdminGroups::AllocateMimeOleObjects ( )
  450. {
  451. HRESULT hr = NOERROR;
  452. if ( !m_pMimeAlloc ) {
  453. hr = CoCreateInstance ( CLSID_IMimeAllocator,
  454. NULL,
  455. CLSCTX_INPROC_SERVER,
  456. IID_IMimeAllocator,
  457. (void **) &m_pMimeAlloc
  458. );
  459. BAIL_ON_FAILURE(hr);
  460. }
  461. if ( !m_pMimeInternational ) {
  462. hr = CoCreateInstance ( CLSID_IMimeInternational,
  463. NULL,
  464. CLSCTX_INPROC_SERVER,
  465. IID_IMimeInternational,
  466. (void **) &m_pMimeInternational
  467. );
  468. BAIL_ON_FAILURE(hr);
  469. }
  470. Exit:
  471. return hr;
  472. }
  473. HRESULT CNntpAdminGroups::UnicodeToMime2 ( LPCWSTR wszUnicode, LPSTR * pszMime2 )
  474. {
  475. TraceQuietEnter("CNntpAdminGroups::UnicodeToMime2");
  476. _ASSERT ( IS_VALID_OUT_PARAM ( pszMime2 ) );
  477. HRESULT hr = S_OK;
  478. PROPVARIANT pvSrc;
  479. RFC1522INFO rfc1522info;
  480. HCHARSET hCharset = NULL;
  481. ZeroMemory ( &pvSrc, sizeof (pvSrc) );
  482. ZeroMemory ( &rfc1522info, sizeof (rfc1522info) );
  483. if ( !wszUnicode || !*wszUnicode ) {
  484. *pszMime2 = NULL;
  485. goto Exit;
  486. }
  487. _ASSERT ( IS_VALID_STRING ( wszUnicode ) );
  488. hr = AllocateMimeOleObjects ();
  489. BAIL_ON_FAILURE(hr);
  490. pvSrc.vt = VT_LPWSTR;
  491. pvSrc.pwszVal = const_cast<LPWSTR> (wszUnicode);
  492. rfc1522info.fRfc1522Used = TRUE;
  493. rfc1522info.fRfc1522Allowed = TRUE;
  494. rfc1522info.fAllow8bit = FALSE;
  495. // Try to get the UTF-8 character set
  496. hr = m_pMimeInternational->FindCharset("UTF-8", &hCharset);
  497. if (FAILED(hr)) {
  498. ErrorTrace(0, "Error getting UTF-8 character set, %x", hr);
  499. hCharset = NULL;
  500. }
  501. hr = m_pMimeInternational->EncodeHeader (
  502. hCharset,
  503. &pvSrc,
  504. pszMime2,
  505. &rfc1522info
  506. );
  507. _ASSERT ( SUCCEEDED(hr) );
  508. BAIL_ON_FAILURE(hr);
  509. Exit:
  510. return hr;
  511. }
  512. HRESULT CNntpAdminGroups::Mime2ToUnicode ( LPCSTR szMime2, CComBSTR & strUnicode )
  513. {
  514. _ASSERT ( IS_VALID_IN_PARAM (szMime2) );
  515. HRESULT hr = S_OK;
  516. PROPVARIANT pvDest;
  517. RFC1522INFO rfc1522info;
  518. ZeroMemory ( &pvDest, sizeof (pvDest) );
  519. ZeroMemory ( &rfc1522info, sizeof (rfc1522info) );
  520. if ( !szMime2 || !*szMime2 ) {
  521. strUnicode = _T("");
  522. goto Exit;
  523. }
  524. hr = AllocateMimeOleObjects ();
  525. BAIL_ON_FAILURE(hr);
  526. pvDest.vt = VT_LPWSTR;
  527. rfc1522info.fRfc1522Used = TRUE;
  528. rfc1522info.fRfc1522Allowed = TRUE;
  529. rfc1522info.fAllow8bit = TRUE;
  530. hr = m_pMimeInternational->DecodeHeader (
  531. NULL,
  532. const_cast<LPSTR> (szMime2),
  533. &pvDest,
  534. &rfc1522info
  535. );
  536. _ASSERT ( SUCCEEDED(hr) );
  537. BAIL_ON_FAILURE(hr);
  538. _ASSERT ( pvDest.vt == VT_LPWSTR );
  539. strUnicode = pvDest.pwszVal;
  540. if ( !strUnicode ) {
  541. BAIL_WITH_FAILURE(hr, E_OUTOFMEMORY);
  542. }
  543. Exit:
  544. m_pMimeAlloc->PropVariantClear ( &pvDest );
  545. return hr;
  546. }