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.

2985 lines
85 KiB

  1. // --------------------------------------------------------------------------------
  2. // Contain.cpp
  3. // Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  4. // --------------------------------------------------------------------------------
  5. #include "pch.hxx"
  6. #include "containx.h"
  7. #include "internat.h"
  8. #include "inetstm.h"
  9. #include "dllmain.h"
  10. #include "olealloc.h"
  11. #include "objheap.h"
  12. #include "vstream.h"
  13. #include "addparse.h"
  14. #include "enumhead.h"
  15. #include "addrenum.h"
  16. #include "stackstr.h"
  17. #include "stmlock.h"
  18. #include "enumprop.h"
  19. #ifndef WIN16
  20. #include "wchar.h"
  21. #endif // !WIN16
  22. #include "symcache.h"
  23. #ifdef MAC
  24. #include <stdio.h>
  25. #endif // MAC
  26. #include "mimeapi.h"
  27. #ifndef MAC
  28. #include <shlwapi.h>
  29. #endif // !MAC
  30. //#define TRACEPARSE 1
  31. // --------------------------------------------------------------------------------
  32. // Hash Table Stats
  33. // --------------------------------------------------------------------------------
  34. #ifdef DEBUG
  35. extern DWORD g_cSetPidLookups;
  36. extern DWORD g_cHashLookups;
  37. extern DWORD g_cHashInserts;
  38. extern DWORD g_cHashCollides;
  39. #endif
  40. // --------------------------------------------------------------------------------
  41. // Default Header Options
  42. // --------------------------------------------------------------------------------
  43. extern const HEADOPTIONS g_rDefHeadOptions;
  44. // --------------------------------------------------------------------------------
  45. // ENCODINGTABLE
  46. // --------------------------------------------------------------------------------
  47. static const ENCODINGTABLE g_rgEncoding[] = {
  48. { STR_ENC_7BIT, IET_7BIT },
  49. { STR_ENC_QP, IET_QP },
  50. { STR_ENC_BASE64, IET_BASE64 },
  51. { STR_ENC_UUENCODE, IET_UUENCODE },
  52. { STR_ENC_XUUENCODE, IET_UUENCODE },
  53. { STR_ENC_XUUE, IET_UUENCODE },
  54. { STR_ENC_8BIT, IET_8BIT },
  55. { STR_ENC_BINARY, IET_BINARY }
  56. };
  57. // --------------------------------------------------------------------------------
  58. // CMimePropertyContainer::HrResolveURL
  59. // --------------------------------------------------------------------------------
  60. HRESULT CMimePropertyContainer::HrResolveURL(LPRESOLVEURLINFO pURL)
  61. {
  62. // Locals
  63. HRESULT hr=S_OK;
  64. LPPROPSTRINGA pBase=NULL;
  65. LPPROPSTRINGA pContentID=NULL;
  66. LPPROPSTRINGA pLocation=NULL;
  67. LPSTR pszAbsURL1=NULL;
  68. LPSTR pszAbsURL2=NULL;
  69. // Invalid Arg
  70. Assert(pURL);
  71. // Init Stack Strings
  72. STACKSTRING_DEFINE(rCleanCID, 255);
  73. // Thread Safety
  74. EnterCriticalSection(&m_cs);
  75. // Content-Location
  76. if (m_prgIndex[PID_HDR_CNTLOC])
  77. {
  78. Assert(ISSTRINGA(&m_prgIndex[PID_HDR_CNTLOC]->rValue));
  79. pLocation = &m_prgIndex[PID_HDR_CNTLOC]->rValue.rStringA;
  80. }
  81. // Content-ID
  82. if (m_prgIndex[PID_HDR_CNTID])
  83. {
  84. Assert(ISSTRINGA(&m_prgIndex[PID_HDR_CNTID]->rValue));
  85. pContentID = &m_prgIndex[PID_HDR_CNTID]->rValue.rStringA;
  86. }
  87. // Content-Base
  88. if (m_prgIndex[PID_HDR_CNTBASE])
  89. {
  90. Assert(ISSTRINGA(&m_prgIndex[PID_HDR_CNTBASE]->rValue));
  91. pBase = &m_prgIndex[PID_HDR_CNTBASE]->rValue.rStringA;
  92. }
  93. // Both Null, no match
  94. if (!pLocation && !pContentID)
  95. {
  96. hr = TrapError(MIME_E_NOT_FOUND);
  97. goto exit;
  98. }
  99. // If URL is a CID
  100. if (TRUE == pURL->fIsCID)
  101. {
  102. // If we have a Content-Location
  103. if (pLocation)
  104. {
  105. // Match char for char
  106. if (MimeOleCompareUrl(pLocation->pszVal, TRUE, pURL->pszURL, FALSE) == S_OK)
  107. goto exit;
  108. }
  109. // Otherwise, compare against pContentId
  110. else
  111. {
  112. // Match char for char minus cid:
  113. if (lstrcmpi(pURL->pszURL + 4, pContentID->pszVal) == 0)
  114. goto exit;
  115. // Get Stack Stream Read for
  116. STACKSTRING_SETSIZE(rCleanCID, lstrlen(pURL->pszURL));
  117. // Format the Cleaned CID
  118. wsprintf(rCleanCID.pszVal, "<%s>", pURL->pszURL + 4);
  119. // Match char for char minus cid:
  120. if (lstrcmpi(rCleanCID.pszVal, pContentID->pszVal) == 0)
  121. goto exit;
  122. }
  123. }
  124. // Otherwise, non-CID resolution
  125. else if (pLocation)
  126. {
  127. // Part Has Base
  128. if (NULL != pBase)
  129. {
  130. // Combine URLs
  131. CHECKHR(hr = MimeOleCombineURL(pBase->pszVal, pBase->cchVal, pLocation->pszVal, pLocation->cchVal, TRUE, &pszAbsURL1));
  132. // URI has no base
  133. if (NULL == pURL->pszBase)
  134. {
  135. // Compare
  136. if (lstrcmpi(pURL->pszURL, pszAbsURL1) == 0)
  137. goto exit;
  138. }
  139. // URI Has a Base
  140. else
  141. {
  142. // Combine URLs
  143. CHECKHR(hr = MimeOleCombineURL(pURL->pszBase, lstrlen(pURL->pszBase), pURL->pszURL, lstrlen(pURL->pszURL), FALSE, &pszAbsURL2));
  144. // Compare
  145. if (lstrcmpi(pszAbsURL1, pszAbsURL2) == 0)
  146. goto exit;
  147. }
  148. }
  149. // Part has no base
  150. else
  151. {
  152. // URI has no base
  153. if (NULL == pURL->pszBase)
  154. {
  155. // Compare
  156. if (MimeOleCompareUrl(pLocation->pszVal, TRUE, pURL->pszURL, FALSE) == S_OK)
  157. goto exit;
  158. }
  159. // URI Has a Base
  160. else
  161. {
  162. // Combine URLs
  163. CHECKHR(hr = MimeOleCombineURL(pURL->pszBase, lstrlen(pURL->pszBase), pURL->pszURL, lstrlen(pURL->pszURL), FALSE, &pszAbsURL2));
  164. // Compare
  165. if (MimeOleCompareUrl(pLocation->pszVal, TRUE, pszAbsURL2, FALSE) == S_OK)
  166. goto exit;
  167. }
  168. }
  169. }
  170. // Not Found
  171. hr = TrapError(MIME_E_NOT_FOUND);
  172. exit:
  173. // Cleanup
  174. STACKSTRING_FREE(rCleanCID);
  175. SafeMemFree(pszAbsURL1);
  176. SafeMemFree(pszAbsURL2);
  177. // Thread Safety
  178. LeaveCriticalSection(&m_cs);
  179. // Done
  180. return hr;
  181. }
  182. // --------------------------------------------------------------------------------
  183. // CMimePropertyContainer::IsContentType
  184. // --------------------------------------------------------------------------------
  185. HRESULT CMimePropertyContainer::IsContentType(LPCSTR pszPriType, LPCSTR pszSubType)
  186. {
  187. // Locals
  188. HRESULT hr=S_OK;
  189. // Wildcard everyting
  190. if (NULL == pszPriType && NULL == pszSubType)
  191. return S_OK;
  192. // Thread Safety
  193. EnterCriticalSection(&m_cs);
  194. // Get Known
  195. LPPROPERTY pCntType = m_prgIndex[PID_ATT_PRITYPE];
  196. LPPROPERTY pSubType = m_prgIndex[PID_ATT_SUBTYPE];
  197. // No Data
  198. if (NULL == pCntType || NULL == pSubType || !ISSTRINGA(&pCntType->rValue) || !ISSTRINGA(&pSubType->rValue))
  199. {
  200. // Compare Against STR_CNT_TEXT
  201. if (pszPriType && lstrcmpi(pszPriType, STR_CNT_TEXT) != 0)
  202. {
  203. hr = S_FALSE;
  204. goto exit;
  205. }
  206. // Compare Against STR_CNT_TEXT
  207. if (pszSubType && lstrcmpi(pszSubType, STR_SUB_PLAIN) != 0)
  208. {
  209. hr = S_FALSE;
  210. goto exit;
  211. }
  212. }
  213. else
  214. {
  215. // Comparing pszPriType
  216. if (pszPriType && lstrcmpi(pszPriType, pCntType->rValue.rStringA.pszVal) != 0)
  217. {
  218. hr = S_FALSE;
  219. goto exit;
  220. }
  221. // Comparing pszSubType
  222. if (pszSubType && lstrcmpi(pszSubType, pSubType->rValue.rStringA.pszVal) != 0)
  223. {
  224. hr = S_FALSE;
  225. goto exit;
  226. }
  227. }
  228. exit:
  229. // Thread Safety
  230. LeaveCriticalSection(&m_cs);
  231. // Done
  232. return hr;
  233. }
  234. // --------------------------------------------------------------------------------
  235. // CMimePropertyContainer::Clone
  236. // --------------------------------------------------------------------------------
  237. HRESULT CMimePropertyContainer::Clone(IMimePropertySet **ppPropertySet)
  238. {
  239. // Locals
  240. HRESULT hr=S_OK;
  241. LPCONTAINER pContainer=NULL;
  242. // InvalidArg
  243. if (NULL == ppPropertySet)
  244. return TrapError(E_INVALIDARG);
  245. // Init
  246. *ppPropertySet = NULL;
  247. // Thread Safety
  248. EnterCriticalSection(&m_cs);
  249. // Ask the container to clone itself
  250. CHECKHR(hr = Clone(&pContainer));
  251. // Bind to the IID_IMimeHeaderTable View
  252. CHECKHR(hr = pContainer->QueryInterface(IID_IMimePropertySet, (LPVOID *)ppPropertySet));
  253. exit:
  254. // Cleanup
  255. SafeRelease(pContainer);
  256. // Thread Safety
  257. LeaveCriticalSection(&m_cs);
  258. // Done
  259. return hr;
  260. }
  261. // --------------------------------------------------------------------------------
  262. // CMimePropertyContainer::Clone
  263. // --------------------------------------------------------------------------------
  264. HRESULT CMimePropertyContainer::Clone(LPCONTAINER *ppContainer)
  265. {
  266. // Locals
  267. HRESULT hr=S_OK;
  268. LPCONTAINER pContainer=NULL;
  269. // Invalid ARg
  270. if (NULL == ppContainer)
  271. return TrapError(E_INVALIDARG);
  272. // Init
  273. *ppContainer = NULL;
  274. // Thread Safety
  275. EnterCriticalSection(&m_cs);
  276. // Create new container, NULL == no outer property set
  277. CHECKALLOC(pContainer = new CMimePropertyContainer);
  278. // Init that new container
  279. CHECKHR(hr = pContainer->InitNew());
  280. // Interate the Properties
  281. CHECKHR(hr = _HrClonePropertiesTo(pContainer));
  282. // If I have a stream, give it to the new table
  283. if (m_pStmLock)
  284. {
  285. // Just pass m_pStmLock into pTable
  286. pContainer->m_pStmLock = m_pStmLock;
  287. pContainer->m_pStmLock->AddRef();
  288. pContainer->m_cbStart = m_cbStart;
  289. pContainer->m_cbSize = m_cbSize;
  290. }
  291. // Give it my state
  292. pContainer->m_dwState = m_dwState;
  293. // Give it my options
  294. pContainer->m_rOptions.pDefaultCharset = m_rOptions.pDefaultCharset;
  295. pContainer->m_rOptions.cbMaxLine = m_rOptions.cbMaxLine;
  296. pContainer->m_rOptions.fAllow8bit = m_rOptions.fAllow8bit;
  297. // Return Clone
  298. (*ppContainer) = pContainer;
  299. (*ppContainer)->AddRef();
  300. exit:
  301. // Cleanup
  302. SafeRelease(pContainer);
  303. // Thread Safety
  304. LeaveCriticalSection(&m_cs);
  305. // Done
  306. return hr;
  307. }
  308. // --------------------------------------------------------------------------------
  309. // CMimePropertyContainer::_HrClonePropertiesTo
  310. // --------------------------------------------------------------------------------
  311. HRESULT CMimePropertyContainer::_HrClonePropertiesTo(LPCONTAINER pContainer)
  312. {
  313. // Locals
  314. HRESULT hr=S_OK;
  315. LPPROPERTY pCurrHash, pCurrValue, pDestProp;
  316. // Invalid Arg
  317. Assert(pContainer);
  318. // Loop through the item table
  319. for (ULONG i=0; i<CBUCKETS; i++)
  320. {
  321. // Walk the Hash Chain
  322. for (pCurrHash=m_prgHashTable[i]; pCurrHash!=NULL; pCurrHash=pCurrHash->pNextHash)
  323. {
  324. // Walk multiple Values
  325. for (pCurrValue=pCurrHash; pCurrValue!=NULL; pCurrValue=pCurrValue->pNextValue)
  326. {
  327. // Linked Attributes are Not Copied
  328. if (ISFLAGSET(pCurrValue->pSymbol->dwFlags, MPF_ATTRIBUTE) && NULL != pCurrValue->pSymbol->pLink)
  329. continue;
  330. // Does the Property need to be parsed ?
  331. if (ISFLAGSET(pCurrValue->pSymbol->dwFlags, MPF_ADDRESS))
  332. {
  333. // Make sure the address is parsed
  334. CHECKHR(hr = _HrParseInternetAddress(pCurrValue));
  335. }
  336. // Insert Copy of pCurrValue into pContiner
  337. CHECKHR(hr = pContainer->HrInsertCopy(pCurrValue));
  338. }
  339. }
  340. }
  341. exit:
  342. // Done
  343. return hr;
  344. }
  345. // --------------------------------------------------------------------------------
  346. // CMimePropertyContainer::_HrCopyProperty
  347. // --------------------------------------------------------------------------------
  348. HRESULT CMimePropertyContainer::_HrCopyProperty(LPPROPERTY pProperty, LPCONTAINER pDest)
  349. {
  350. // Locals
  351. HRESULT hr=S_OK;
  352. LPPROPERTY pCurrValue;
  353. // Walk multiple Values
  354. for (pCurrValue=pProperty; pCurrValue!=NULL; pCurrValue=pCurrValue->pNextValue)
  355. {
  356. // Does the Property need to be parsed ?
  357. if (ISFLAGSET(pCurrValue->pSymbol->dwFlags, MPF_ADDRESS))
  358. {
  359. // Make sure the address is parsed
  360. CHECKHR(hr = _HrParseInternetAddress(pCurrValue));
  361. }
  362. // Insert pProperty into pDest
  363. CHECKHR(hr = pDest->HrInsertCopy(pCurrValue));
  364. }
  365. // If pCurrHash has Parameters, copy those over as well
  366. if (ISFLAGSET(pProperty->pSymbol->dwFlags, MPF_HASPARAMS))
  367. {
  368. // Copy Parameters
  369. CHECKHR(hr = _HrCopyParameters(pProperty, pDest));
  370. }
  371. exit:
  372. // Done
  373. return hr;
  374. }
  375. // --------------------------------------------------------------------------------
  376. // CMimePropertyContainer::_HrCopyParameters
  377. // --------------------------------------------------------------------------------
  378. HRESULT CMimePropertyContainer::_HrCopyParameters(LPPROPERTY pProperty, LPCONTAINER pDest)
  379. {
  380. // Locals
  381. HRESULT hr=S_OK;
  382. HRESULT hrFind;
  383. FINDPROPERTY rFind;
  384. LPPROPERTY pParameter;
  385. // Invalid Arg
  386. Assert(pProperty && ISFLAGSET(pProperty->pSymbol->dwFlags, MPF_HASPARAMS));
  387. // Initialize rFind
  388. ZeroMemory(&rFind, sizeof(FINDPROPERTY));
  389. rFind.pszPrefix = "par:";
  390. rFind.cchPrefix = 4;
  391. rFind.pszName = pProperty->pSymbol->pszName;
  392. rFind.cchName = pProperty->pSymbol->cchName;
  393. // Find First..
  394. hrFind = _HrFindFirstProperty(&rFind, &pParameter);
  395. // While we find them, delete them
  396. while (SUCCEEDED(hrFind) && pParameter)
  397. {
  398. // Remove the parameter
  399. CHECKHR(hr = pDest->HrInsertCopy(pParameter));
  400. // Find Next
  401. hrFind = _HrFindNextProperty(&rFind, &pParameter);
  402. }
  403. exit:
  404. // Done
  405. return hr;
  406. }
  407. // --------------------------------------------------------------------------------
  408. // CMimePropertyContainer::HrInsertCopy
  409. // --------------------------------------------------------------------------------
  410. HRESULT CMimePropertyContainer::HrInsertCopy(LPPROPERTY pSource)
  411. {
  412. // Locals
  413. HRESULT hr=S_OK;
  414. LPPROPERTY pDest;
  415. LPMIMEADDRESS pAddress;
  416. LPMIMEADDRESS pNew;
  417. // Invalid Arg
  418. Assert(pSource);
  419. // Thread Safety
  420. EnterCriticalSection(&m_cs);
  421. // Append a new property to the
  422. CHECKHR(hr = _HrAppendProperty(pSource->pSymbol, &pDest));
  423. // If this is an address...
  424. if (ISFLAGSET(pSource->pSymbol->dwFlags, MPF_ADDRESS))
  425. {
  426. // Both Address Group Better Exist
  427. Assert(pSource->pGroup && pDest->pGroup && !ISFLAGSET(pSource->dwState, PRSTATE_NEEDPARSE));
  428. // Loop Infos...
  429. for (pAddress=pSource->pGroup->pHead; pAddress!=NULL; pAddress=pAddress->pNext)
  430. {
  431. // Append pDest->pGroup
  432. CHECKHR(hr = _HrAppendAddressGroup(pDest->pGroup, &pNew));
  433. // Copy Current to New
  434. CHECKHR(hr = HrMimeAddressCopy(pAddress, pNew));
  435. }
  436. }
  437. // Otheriwse, just set the variant data on pDest
  438. else
  439. {
  440. // Set It
  441. CHECKHR(hr = _HrSetPropertyValue(pDest, 0, &pSource->rValue));
  442. }
  443. // Copy the State
  444. pDest->dwState = pSource->dwState;
  445. pDest->dwRowNumber = pSource->dwRowNumber;
  446. pDest->cboffStart = pSource->cboffStart;
  447. pDest->cboffColon = pSource->cboffColon;
  448. pDest->cboffEnd = pSource->cboffEnd;
  449. exit:
  450. // Thread Safety
  451. LeaveCriticalSection(&m_cs);
  452. // Done
  453. return hr;
  454. }
  455. // --------------------------------------------------------------------------------
  456. // CMimePropertyContainer::CopyProps
  457. // --------------------------------------------------------------------------------
  458. HRESULT CMimePropertyContainer::CopyProps(ULONG cNames, LPCSTR *prgszName, IMimePropertySet *pPropertySet)
  459. {
  460. // Locals
  461. HRESULT hr=S_OK;
  462. ULONG i;
  463. LPPROPSYMBOL pSymbol;
  464. LPPROPERTY pProperty,
  465. pCurrValue,
  466. pCurrHash,
  467. pNextHash;
  468. LPCONTAINER pDest=NULL;
  469. // Invalid ARg
  470. if ((0 == cNames && NULL != prgszName) || (NULL == prgszName && 0 != cNames) || NULL == pPropertySet)
  471. return TrapError(E_INVALIDARG);
  472. // Thread Safety
  473. EnterCriticalSection(&m_cs);
  474. // QI for destination continer
  475. CHECKHR(hr = pPropertySet->BindToObject(IID_CMimePropertyContainer, (LPVOID *)&pDest));
  476. // Move All Properties
  477. if (0 == cNames)
  478. {
  479. // Loop through the item table
  480. for (i=0; i<CBUCKETS; i++)
  481. {
  482. // Init First Item
  483. for (pCurrHash=m_prgHashTable[i]; pCurrHash!=NULL; pCurrHash=pCurrHash->pNextHash)
  484. {
  485. // Delete from Destination Container
  486. pDest->DeleteProp(pCurrHash->pSymbol);
  487. // Copy the Property To
  488. CHECKHR(hr = _HrCopyProperty(pCurrHash, pDest));
  489. }
  490. }
  491. }
  492. // Otherwise, copy selected properties
  493. else
  494. {
  495. // Call Into InetPropSet
  496. for (i=0; i<cNames; i++)
  497. {
  498. // Bad Name..
  499. if (NULL == prgszName[i])
  500. {
  501. Assert(FALSE);
  502. continue;
  503. }
  504. // Open Property Symbol
  505. if (SUCCEEDED(g_pSymCache->HrOpenSymbol(prgszName[i], FALSE, &pSymbol)))
  506. {
  507. // Find the Property
  508. if (SUCCEEDED(_HrFindProperty(pSymbol, &pProperty)))
  509. {
  510. // Delete from Destination Container
  511. pDest->DeleteProp(pSymbol);
  512. // Copy the Property To
  513. CHECKHR(hr = _HrCopyProperty(pProperty, pDest));
  514. }
  515. }
  516. }
  517. }
  518. exit:
  519. // Cleanup
  520. SafeRelease(pDest);
  521. // Thread Safety
  522. LeaveCriticalSection(&m_cs);
  523. // Done
  524. return hr;
  525. }
  526. // --------------------------------------------------------------------------------
  527. // CMimePropertyContainer::MoveProps
  528. // --------------------------------------------------------------------------------
  529. HRESULT CMimePropertyContainer::MoveProps(ULONG cNames, LPCSTR *prgszName, IMimePropertySet *pPropertySet)
  530. {
  531. // Locals
  532. HRESULT hr=S_OK;
  533. ULONG i;
  534. LPPROPSYMBOL pSymbol;
  535. LPPROPERTY pProperty;
  536. LPPROPERTY pCurrHash;
  537. LPCONTAINER pDest=NULL;
  538. // Invalid ARg
  539. if ((0 == cNames && NULL != prgszName) || (NULL == prgszName && 0 != cNames) || NULL == pPropertySet)
  540. return TrapError(E_INVALIDARG);
  541. // Thread Safety
  542. EnterCriticalSection(&m_cs);
  543. // QI for destination continer
  544. CHECKHR(hr = pPropertySet->BindToObject(IID_CMimePropertyContainer, (LPVOID *)&pDest));
  545. // Move All Properties
  546. if (0 == cNames)
  547. {
  548. // Loop through the item table
  549. for (i=0; i<CBUCKETS; i++)
  550. {
  551. // Init First Item
  552. pCurrHash = m_prgHashTable[i];
  553. // Walk the Hash Chain
  554. while(pCurrHash)
  555. {
  556. // Delete Property from the destination
  557. pDest->DeleteProp(pCurrHash->pSymbol);
  558. // Copy the Property To
  559. CHECKHR(hr = _HrCopyProperty(pCurrHash, pDest));
  560. // Delete pProperty
  561. _UnlinkProperty(pCurrHash, &pCurrHash);
  562. }
  563. }
  564. }
  565. // Otherwise, selective move
  566. else
  567. {
  568. // Call Into InetPropSet
  569. for (i=0; i<cNames; i++)
  570. {
  571. // Bad Name..
  572. if (NULL == prgszName[i])
  573. {
  574. Assert(FALSE);
  575. continue;
  576. }
  577. // Open Property Symbol
  578. if (SUCCEEDED(g_pSymCache->HrOpenSymbol(prgszName[i], FALSE, &pSymbol)))
  579. {
  580. // Find the Property
  581. if (SUCCEEDED(_HrFindProperty(pSymbol, &pProperty)))
  582. {
  583. // Delete from Destination Container
  584. pDest->DeleteProp(pSymbol);
  585. // Copy the Property To
  586. CHECKHR(hr = _HrCopyProperty(pProperty, pDest));
  587. // Delete pProperty
  588. _UnlinkProperty(pProperty);
  589. }
  590. }
  591. }
  592. }
  593. // Dirty
  594. FLAGSET(m_dwState, COSTATE_DIRTY);
  595. exit:
  596. // Cleanup
  597. SafeRelease(pDest);
  598. // Thread Safety
  599. LeaveCriticalSection(&m_cs);
  600. // Done
  601. return hr;
  602. }
  603. // --------------------------------------------------------------------------------
  604. // CMimePropertyContainer::SetOption
  605. // --------------------------------------------------------------------------------
  606. HRESULT CMimePropertyContainer::SetOption(const TYPEDID oid, LPCPROPVARIANT pVariant)
  607. {
  608. // Locals
  609. HRESULT hr=S_OK;
  610. // check params
  611. if (NULL == pVariant)
  612. return TrapError(E_INVALIDARG);
  613. // Thread Safety
  614. EnterCriticalSection(&m_cs);
  615. // Handle Optid
  616. switch(oid)
  617. {
  618. // -----------------------------------------------------------------------
  619. case OID_HEADER_RELOAD_TYPE:
  620. if (pVariant->ulVal > RELOAD_HEADER_REPLACE)
  621. {
  622. hr = TrapError(MIME_E_INVALID_OPTION_VALUE);
  623. goto exit;
  624. }
  625. if (m_rOptions.ReloadType != (RELOADTYPE)pVariant->ulVal)
  626. {
  627. FLAGSET(m_dwState, COSTATE_DIRTY);
  628. m_rOptions.ReloadType = (RELOADTYPE)pVariant->ulVal;
  629. }
  630. break;
  631. // -----------------------------------------------------------------------
  632. case OID_NO_DEFAULT_CNTTYPE:
  633. if (m_rOptions.fNoDefCntType != (pVariant->boolVal ? TRUE : FALSE))
  634. m_rOptions.fNoDefCntType = pVariant->boolVal ? TRUE : FALSE;
  635. break;
  636. // -----------------------------------------------------------------------
  637. case OID_ALLOW_8BIT_HEADER:
  638. if (m_rOptions.fAllow8bit != (pVariant->boolVal ? TRUE : FALSE))
  639. {
  640. FLAGSET(m_dwState, COSTATE_DIRTY);
  641. m_rOptions.fAllow8bit = pVariant->boolVal ? TRUE : FALSE;
  642. }
  643. break;
  644. // -----------------------------------------------------------------------
  645. case OID_CBMAX_HEADER_LINE:
  646. if (pVariant->ulVal < MIN_CBMAX_HEADER_LINE || pVariant->ulVal > MAX_CBMAX_HEADER_LINE)
  647. {
  648. hr = TrapError(MIME_E_INVALID_OPTION_VALUE);
  649. goto exit;
  650. }
  651. if (m_rOptions.cbMaxLine != pVariant->ulVal)
  652. {
  653. FLAGSET(m_dwState, COSTATE_DIRTY);
  654. m_rOptions.cbMaxLine = pVariant->ulVal;
  655. }
  656. break;
  657. // -----------------------------------------------------------------------
  658. case OID_SAVE_FORMAT:
  659. if (SAVE_RFC822 != pVariant->ulVal && SAVE_RFC1521 != pVariant->ulVal)
  660. {
  661. hr = TrapError(MIME_E_INVALID_OPTION_VALUE);
  662. goto exit;
  663. }
  664. if (m_rOptions.savetype != (MIMESAVETYPE)pVariant->ulVal)
  665. {
  666. FLAGSET(m_dwState, COSTATE_DIRTY);
  667. m_rOptions.savetype = (MIMESAVETYPE)pVariant->ulVal;
  668. }
  669. break;
  670. // -----------------------------------------------------------------------
  671. default:
  672. hr = TrapError(MIME_E_INVALID_OPTION_ID);
  673. goto exit;
  674. }
  675. exit:
  676. // Thread Safety
  677. LeaveCriticalSection(&m_cs);
  678. // Done
  679. return hr;
  680. }
  681. // --------------------------------------------------------------------------------
  682. // CMimePropertyContainer::GetOption
  683. // --------------------------------------------------------------------------------
  684. HRESULT CMimePropertyContainer::GetOption(const TYPEDID oid, LPPROPVARIANT pVariant)
  685. {
  686. // Locals
  687. HRESULT hr=S_OK;
  688. // check params
  689. if (NULL == pVariant)
  690. return TrapError(E_INVALIDARG);
  691. pVariant->vt = TYPEDID_TYPE(oid);
  692. // Thread Safety
  693. EnterCriticalSection(&m_cs);
  694. // Handle Optid
  695. switch(oid)
  696. {
  697. // -----------------------------------------------------------------------
  698. case OID_HEADER_RELOAD_TYPE:
  699. pVariant->ulVal = m_rOptions.ReloadType;
  700. break;
  701. // -----------------------------------------------------------------------
  702. case OID_NO_DEFAULT_CNTTYPE:
  703. pVariant->boolVal = m_rOptions.fNoDefCntType;
  704. break;
  705. // -----------------------------------------------------------------------
  706. case OID_ALLOW_8BIT_HEADER:
  707. pVariant->boolVal = m_rOptions.fAllow8bit;
  708. break;
  709. // -----------------------------------------------------------------------
  710. case OID_CBMAX_HEADER_LINE:
  711. pVariant->ulVal = m_rOptions.cbMaxLine;
  712. break;
  713. // -----------------------------------------------------------------------
  714. case OID_SAVE_FORMAT:
  715. pVariant->ulVal = (ULONG)m_rOptions.savetype;
  716. break;
  717. // -----------------------------------------------------------------------
  718. default:
  719. pVariant->vt = VT_NULL;
  720. hr = TrapError(MIME_E_INVALID_OPTION_ID);
  721. goto exit;
  722. }
  723. exit:
  724. // Thread Safety
  725. LeaveCriticalSection(&m_cs);
  726. // Done
  727. return hr;
  728. }
  729. // --------------------------------------------------------------------------------
  730. // CMimePropertyContainer::DwGetMessageFlags
  731. // --------------------------------------------------------------------------------
  732. DWORD CMimePropertyContainer::DwGetMessageFlags(BOOL fHideTnef)
  733. {
  734. // Locals
  735. DWORD dwFlags=0;
  736. // Thread Safety
  737. EnterCriticalSection(&m_cs);
  738. // Get pritype/subtype
  739. LPCSTR pszPriType = PSZDEFPROPSTRINGA(m_prgIndex[PID_ATT_PRITYPE], STR_CNT_TEXT);
  740. LPCSTR pszSubType = PSZDEFPROPSTRINGA(m_prgIndex[PID_ATT_SUBTYPE], STR_SUB_PLAIN);
  741. LPCSTR pszCntDisp = PSZDEFPROPSTRINGA(m_prgIndex[PID_HDR_CNTDISP], STR_DIS_INLINE);
  742. // Mime
  743. if (m_prgIndex[PID_HDR_MIMEVER])
  744. FLAGSET(dwFlags, IMF_MIME);
  745. // IMF_NEWS
  746. if (m_prgIndex[PID_HDR_XNEWSRDR] || m_prgIndex[PID_HDR_NEWSGROUPS] || m_prgIndex[PID_HDR_NEWSGROUP] || m_prgIndex[PID_HDR_PATH])
  747. FLAGSET(dwFlags, IMF_NEWS);
  748. // text
  749. if (lstrcmpi(pszPriType, STR_CNT_TEXT) == 0)
  750. {
  751. // There is text
  752. FLAGSET(dwFlags, IMF_TEXT);
  753. // text/plain
  754. if (lstrcmpi(pszSubType, STR_SUB_PLAIN) == 0)
  755. FLAGSET(dwFlags, IMF_PLAIN);
  756. // text/html
  757. else if (lstrcmpi(pszSubType, STR_SUB_HTML) == 0)
  758. FLAGSET(dwFlags, IMF_HTML);
  759. }
  760. // multipart
  761. else if (lstrcmpi(pszPriType, STR_CNT_MULTIPART) == 0)
  762. {
  763. // Multipart
  764. FLAGSET(dwFlags, IMF_MULTIPART);
  765. // multipart/related
  766. if (lstrcmpi(pszSubType, STR_SUB_RELATED) == 0)
  767. FLAGSET(dwFlags, IMF_MHTML);
  768. // multipart/signed
  769. else if (0 == lstrcmpi(pszSubType, STR_SUB_SIGNED))
  770. FLAGSET(dwFlags, IMF_SIGNED | IMF_SECURE);
  771. }
  772. // message/partial
  773. else if (lstrcmpi(pszPriType, STR_CNT_MESSAGE) == 0 && lstrcmpi(pszSubType, STR_SUB_PARTIAL) == 0)
  774. FLAGSET(dwFlags, IMF_PARTIAL);
  775. // application
  776. else if (lstrcmpi(pszPriType, STR_CNT_APPLICATION) == 0)
  777. {
  778. // application/ms-tnef
  779. if (0 == lstrcmpi(pszSubType, STR_SUB_MSTNEF))
  780. FLAGSET(dwFlags, IMF_TNEF);
  781. // application/x-pkcs7-mime
  782. else if (0 == lstrcmpi(pszSubType, STR_SUB_XPKCS7MIME) ||
  783. 0 == lstrcmpi(pszSubType, STR_SUB_PKCS7MIME)) // nonstandard
  784. FLAGSET(dwFlags, IMF_SECURE);
  785. }
  786. // Raid-37086 - Cset Tagged
  787. if (ISFLAGSET(m_dwState, COSTATE_CSETTAGGED))
  788. FLAGSET(dwFlags, IMF_CSETTAGGED);
  789. // Attachment...
  790. if (!ISFLAGSET(dwFlags, IMF_MULTIPART) && (FALSE == fHideTnef || !ISFLAGSET(dwFlags, IMF_TNEF)))
  791. {
  792. // Marked as an attachment ?
  793. if (!ISFLAGSET(dwFlags, IMF_SECURE) && 0 != lstrcmpi(pszSubType, STR_SUB_PKCS7SIG))
  794. {
  795. // Not Rendered Yet
  796. if (NULL == m_prgIndex[PID_ATT_RENDERED])
  797. {
  798. // Marked as an Attachment
  799. if (lstrcmpi(pszCntDisp, STR_DIS_ATTACHMENT) == 0)
  800. FLAGSET(dwFlags, IMF_ATTACHMENTS);
  801. // Is there a Content-Type: xxx; name=xxx
  802. else if (NULL != m_prgIndex[PID_PAR_NAME])
  803. FLAGSET(dwFlags, IMF_ATTACHMENTS);
  804. // Is there a Content-Disposition: xxx; filename=xxx
  805. else if (NULL != m_prgIndex[PID_PAR_FILENAME])
  806. FLAGSET(dwFlags, IMF_ATTACHMENTS);
  807. // Else if it is not marked as text
  808. else if (ISFLAGSET(dwFlags, IMF_TEXT) == FALSE)
  809. FLAGSET(dwFlags, IMF_ATTACHMENTS);
  810. // If not text/plain and not text/html
  811. else if (lstrcmpi(pszSubType, STR_SUB_PLAIN) != 0 && lstrcmpi(pszSubType, STR_SUB_HTML) != 0 && lstrcmpi(pszSubType, STR_SUB_ENRICHED) != 0)
  812. FLAGSET(dwFlags, IMF_ATTACHMENTS);
  813. }
  814. }
  815. }
  816. // Thread Safety
  817. LeaveCriticalSection(&m_cs);
  818. // Done
  819. return dwFlags;
  820. }
  821. // --------------------------------------------------------------------------------
  822. // CMimePropertyContainer::GetEncodingType
  823. // --------------------------------------------------------------------------------
  824. ENCODINGTYPE CMimePropertyContainer::GetEncodingType(void)
  825. {
  826. // Locals
  827. ENCODINGTYPE ietEncoding=IET_7BIT;
  828. // Thread Safety
  829. EnterCriticalSection(&m_cs);
  830. // Get pritype/subtype
  831. LPPROPERTY pCntXfer = m_prgIndex[PID_HDR_CNTXFER];
  832. // Do we have data the I like ?
  833. if (pCntXfer && ISSTRINGA(&pCntXfer->rValue))
  834. {
  835. // Local
  836. CStringParser cString;
  837. // cString...
  838. cString.Init(pCntXfer->rValue.rStringA.pszVal, pCntXfer->rValue.rStringA.cchVal, PSF_NOTRAILWS | PSF_NOFRONTWS | PSF_NOCOMMENTS);
  839. // Parse to end, remove white space and comments
  840. SideAssert('\0' == cString.ChParse(""));
  841. // Loop the table
  842. for (ULONG i=0; i<ARRAYSIZE(g_rgEncoding); i++)
  843. {
  844. // Match Encoding Strings
  845. if (lstrcmpi(g_rgEncoding[i].pszEncoding, cString.PszValue()) == 0)
  846. {
  847. ietEncoding = g_rgEncoding[i].ietEncoding;
  848. break;
  849. }
  850. }
  851. }
  852. // Thread Safety
  853. LeaveCriticalSection(&m_cs);
  854. // Done
  855. return ietEncoding;
  856. }
  857. // --------------------------------------------------------------------------------
  858. // CMimePropertyContainer::_HrGetInlineSymbol
  859. // --------------------------------------------------------------------------------
  860. HRESULT CMimePropertyContainer::_HrGetInlineSymbol(LPCSTR pszData, LPPROPSYMBOL *ppSymbol, ULONG *pcboffColon)
  861. {
  862. // Locals
  863. HRESULT hr=S_OK;
  864. CHAR szHeader[255];
  865. LPSTR pszHeader=NULL;
  866. // Invalid Arg
  867. Assert(pszData && ppSymbol);
  868. // _HrParseInlineHeaderName
  869. CHECKHR(hr = _HrParseInlineHeaderName(pszData, szHeader, sizeof(szHeader), &pszHeader, pcboffColon));
  870. // Find Global Property
  871. CHECKHR(hr = g_pSymCache->HrOpenSymbol(pszHeader, TRUE, ppSymbol));
  872. exit:
  873. // Cleanup
  874. if (pszHeader != szHeader)
  875. SafeMemFree(pszHeader);
  876. // Done
  877. return hr;
  878. }
  879. // --------------------------------------------------------------------------------
  880. // CMimePropertyContainer::_HrParseInlineHeaderName
  881. // --------------------------------------------------------------------------------
  882. HRESULT CMimePropertyContainer::_HrParseInlineHeaderName(LPCSTR pszData, LPSTR pszScratch, ULONG cchScratch,
  883. LPSTR *ppszHeader, ULONG *pcboffColon)
  884. {
  885. // Locals
  886. HRESULT hr=S_OK;
  887. LPSTR psz=(LPSTR)pszData,
  888. pszStart;
  889. ULONG i=0;
  890. // Invalid Arg
  891. Assert(pszData && pszScratch && ppszHeader && pcboffColon);
  892. // Lets Parse the name out and find the symbol
  893. while (*psz && (' ' == *psz || '\t' == *psz))
  894. {
  895. i++;
  896. psz++;
  897. }
  898. // Done
  899. if ('\0' == *psz)
  900. {
  901. hr = TrapError(MIME_E_INVALID_HEADER_NAME);
  902. goto exit;
  903. }
  904. // Seek to the colon
  905. pszStart = psz;
  906. while (*psz && ':' != *psz)
  907. {
  908. i++;
  909. psz++;
  910. }
  911. // Set Colon Position
  912. (*pcboffColon) = i;
  913. // Done
  914. if ('\0' == *psz || 0 == i)
  915. {
  916. hr = TrapError(MIME_E_INVALID_HEADER_NAME);
  917. goto exit;
  918. }
  919. // Copy the name
  920. if (i + 1 <= cchScratch)
  921. *ppszHeader = pszScratch;
  922. // Otherwise, allocate
  923. else
  924. {
  925. // Allocate space for the name
  926. *ppszHeader = PszAllocA(i + 1);
  927. if (NULL == *ppszHeader)
  928. {
  929. hr = TrapError(E_OUTOFMEMORY);
  930. goto exit;
  931. }
  932. }
  933. // Copy the data
  934. CopyMemory(*ppszHeader, pszStart, i);
  935. // Null
  936. *((*ppszHeader) + i) = '\0';
  937. exit:
  938. // Done
  939. return hr;
  940. }
  941. // --------------------------------------------------------------------------------
  942. // CMimePropertyContainer::FindFirstRow
  943. // --------------------------------------------------------------------------------
  944. STDMETHODIMP CMimePropertyContainer::FindFirstRow(LPFINDHEADER pFindHeader, LPHHEADERROW phRow)
  945. {
  946. // Invalid Arg
  947. if (NULL == pFindHeader)
  948. return TrapError(E_INVALIDARG);
  949. // Init pFindHeader
  950. pFindHeader->dwReserved = 0;
  951. // FindNext
  952. return FindNextRow(pFindHeader, phRow);
  953. }
  954. // --------------------------------------------------------------------------------
  955. // CMimePropertyContainer::FindNextRow
  956. // --------------------------------------------------------------------------------
  957. STDMETHODIMP CMimePropertyContainer::FindNextRow(LPFINDHEADER pFindHeader, LPHHEADERROW phRow)
  958. {
  959. // Locals
  960. HRESULT hr=S_OK;
  961. LPPROPERTY pRow;
  962. // InvalidArg
  963. if (NULL == pFindHeader || NULL == phRow)
  964. return TrapError(E_INVALIDARG);
  965. // Init
  966. *phRow = NULL;
  967. // Thread Safety
  968. EnterCriticalSection(&m_cs);
  969. // Loop through the table
  970. for (ULONG i=pFindHeader->dwReserved; i<m_rHdrTable.cRows; i++)
  971. {
  972. // Next Row
  973. pRow = m_rHdrTable.prgpRow[i];
  974. if (NULL == pRow)
  975. continue;
  976. // Is this the header
  977. if (NULL == pFindHeader->pszHeader || lstrcmpi(pRow->pSymbol->pszName, pFindHeader->pszHeader) == 0)
  978. {
  979. // Save Index of next item to search
  980. pFindHeader->dwReserved = i + 1;
  981. // Return the handle
  982. *phRow = pRow->hRow;
  983. // Done
  984. goto exit;
  985. }
  986. }
  987. // Not Found
  988. pFindHeader->dwReserved = m_rHdrTable.cRows;
  989. hr = MIME_E_NOT_FOUND;
  990. exit:
  991. // Thread Safety
  992. LeaveCriticalSection(&m_cs);
  993. // Done
  994. return hr;
  995. }
  996. // --------------------------------------------------------------------------------
  997. // CMimePropertyContainer::CountRows
  998. // --------------------------------------------------------------------------------
  999. STDMETHODIMP CMimePropertyContainer::CountRows(LPCSTR pszHeader, ULONG *pcRows)
  1000. {
  1001. // Locals
  1002. LPPROPERTY pRow;
  1003. // InvalidArg
  1004. if (NULL == pcRows)
  1005. return TrapError(E_INVALIDARG);
  1006. // Init
  1007. *pcRows = 0;
  1008. // Thread Safety
  1009. EnterCriticalSection(&m_cs);
  1010. // Loop through the table
  1011. for (ULONG i=0; i<m_rHdrTable.cRows; i++)
  1012. {
  1013. // Next Row
  1014. pRow = m_rHdrTable.prgpRow[i];
  1015. if (NULL == pRow)
  1016. continue;
  1017. // Is this the header
  1018. if (NULL == pszHeader || lstrcmpi(pRow->pSymbol->pszName, pszHeader) == 0)
  1019. (*pcRows)++;
  1020. }
  1021. // Thread Safety
  1022. LeaveCriticalSection(&m_cs);
  1023. // Done
  1024. return S_OK;
  1025. }
  1026. // --------------------------------------------------------------------------------
  1027. // CMimePropertyContainer::AppendRow
  1028. // --------------------------------------------------------------------------------
  1029. STDMETHODIMP CMimePropertyContainer::AppendRow(LPCSTR pszHeader, DWORD dwFlags, LPCSTR pszData, ULONG cchData,
  1030. LPHHEADERROW phRow)
  1031. {
  1032. // Locals
  1033. HRESULT hr=S_OK;
  1034. LPPROPSYMBOL pSymbol=NULL;
  1035. ULONG cboffColon;
  1036. LPPROPERTY pProperty;
  1037. // InvalidArg
  1038. if (NULL == pszData || '\0' != pszData[cchData])
  1039. return TrapError(E_INVALIDARG);
  1040. // Init
  1041. if (phRow)
  1042. *phRow = NULL;
  1043. // Thread Safety
  1044. EnterCriticalSection(&m_cs);
  1045. // If we have a header, lookup the symbol
  1046. if (pszHeader)
  1047. {
  1048. // HTF_NAMEINDATA better not be set
  1049. Assert(!ISFLAGSET(dwFlags, HTF_NAMEINDATA));
  1050. // Lookup the symbol
  1051. CHECKHR(hr = g_pSymCache->HrOpenSymbol(pszHeader, TRUE, &pSymbol));
  1052. // Create a row
  1053. CHECKHR(hr = _HrAppendProperty(pSymbol, &pProperty));
  1054. // Set the Data on this row
  1055. CHECKHR(hr = SetRowData(pProperty->hRow, dwFlags, pszData, cchData));
  1056. }
  1057. // Otherwise...
  1058. else if (ISFLAGSET(dwFlags, HTF_NAMEINDATA))
  1059. {
  1060. // GetInlineSymbol
  1061. CHECKHR(hr = _HrGetInlineSymbol(pszData, &pSymbol, &cboffColon));
  1062. // Create a row
  1063. CHECKHR(hr = _HrAppendProperty(pSymbol, &pProperty));
  1064. // Remove IHF_NAMELINE
  1065. FLAGCLEAR(dwFlags, HTF_NAMEINDATA);
  1066. // Set the Data on this row
  1067. Assert(cboffColon + 1 < cchData);
  1068. CHECKHR(hr = SetRowData(pProperty->hRow, dwFlags, pszData + cboffColon + 1, cchData - cboffColon - 1));
  1069. }
  1070. // Otherwise, failed
  1071. else
  1072. {
  1073. hr = TrapError(E_INVALIDARG);
  1074. goto exit;
  1075. }
  1076. exit:
  1077. // Thread Safety
  1078. LeaveCriticalSection(&m_cs);
  1079. // Done
  1080. return hr;
  1081. }
  1082. // --------------------------------------------------------------------------------
  1083. // CMimePropertyContainer::DeleteRow
  1084. // --------------------------------------------------------------------------------
  1085. STDMETHODIMP CMimePropertyContainer::DeleteRow(HHEADERROW hRow)
  1086. {
  1087. // Locals
  1088. HRESULT hr=S_OK;
  1089. LPPROPERTY pRow;
  1090. // Thread Safety
  1091. EnterCriticalSection(&m_cs);
  1092. // Validate the Handle
  1093. CHECKEXP(_FIsValidHRow(hRow) == FALSE, MIME_E_INVALID_HANDLE);
  1094. // Get the row
  1095. pRow = PRowFromHRow(hRow);
  1096. // Standard Delete Prop
  1097. CHECKHR(hr = DeleteProp(pRow->pSymbol));
  1098. exit:
  1099. // Thread Safety
  1100. LeaveCriticalSection(&m_cs);
  1101. // Done
  1102. return hr;
  1103. }
  1104. // --------------------------------------------------------------------------------
  1105. // CMimePropertyContainer::GetRowData
  1106. // --------------------------------------------------------------------------------
  1107. STDMETHODIMP CMimePropertyContainer::GetRowData(HHEADERROW hRow, DWORD dwFlags, LPSTR *ppszData, ULONG *pcchData)
  1108. {
  1109. // Locals
  1110. HRESULT hr=S_OK;
  1111. ULONG cchData=0;
  1112. LPPROPERTY pRow;
  1113. MIMEVARIANT rValue;
  1114. DWORD dwPropFlags;
  1115. // Init
  1116. if (ppszData)
  1117. *ppszData = NULL;
  1118. if (pcchData)
  1119. *pcchData = 0;
  1120. // Thread Safety
  1121. EnterCriticalSection(&m_cs);
  1122. // Validate the Handle
  1123. CHECKEXP(_FIsValidHRow(hRow) == FALSE, MIME_E_INVALID_HANDLE);
  1124. // Get the row
  1125. pRow = PRowFromHRow(hRow);
  1126. // Compute dwPropFlags
  1127. dwPropFlags = PDF_HEADERFORMAT | ((dwFlags & HTF_NAMEINDATA) ? PDF_NAMEINDATA : 0);
  1128. // Speicify data type
  1129. rValue.type = MVT_STRINGA;
  1130. // Ask the value for the data
  1131. CHECKHR(hr = _HrGetPropertyValue(pRow, dwPropFlags, &rValue));
  1132. // Want Length
  1133. cchData = rValue.rStringA.cchVal;
  1134. // Want the data
  1135. if (ppszData)
  1136. {
  1137. *ppszData = rValue.rStringA.pszVal;
  1138. rValue.rStringA.pszVal = NULL;
  1139. }
  1140. // Else Free It
  1141. else
  1142. SafeMemFree(rValue.rStringA.pszVal);
  1143. // Verify the NULL
  1144. Assert(ppszData ? '\0' == *((*ppszData) + cchData) : TRUE);
  1145. // Return Length ?
  1146. if (pcchData)
  1147. *pcchData = cchData;
  1148. exit:
  1149. // Thread Safety
  1150. LeaveCriticalSection(&m_cs);
  1151. // Done
  1152. return hr;
  1153. }
  1154. // --------------------------------------------------------------------------------
  1155. // CMimePropertyContainer::SetRowData
  1156. // --------------------------------------------------------------------------------
  1157. STDMETHODIMP CMimePropertyContainer::SetRowData(HHEADERROW hRow, DWORD dwFlags, LPCSTR pszData, ULONG cchData)
  1158. {
  1159. // Locals
  1160. HRESULT hr=S_OK;
  1161. LPPROPERTY pRow;
  1162. MIMEVARIANT rValue;
  1163. ULONG cboffColon;
  1164. LPPROPSYMBOL pSymbol;
  1165. LPSTR psz=(LPSTR)pszData;
  1166. // InvalidArg
  1167. if (NULL == pszData || '\0' != pszData[cchData])
  1168. return TrapError(E_INVALIDARG);
  1169. // Thread Safety
  1170. EnterCriticalSection(&m_cs);
  1171. // Validate the Handle
  1172. CHECKEXP(_FIsValidHRow(hRow) == FALSE, MIME_E_INVALID_HANDLE);
  1173. // Get the row
  1174. pRow = PRowFromHRow(hRow);
  1175. // If HTF_NAMEINDATA
  1176. if (ISFLAGSET(dwFlags, HTF_NAMEINDATA))
  1177. {
  1178. // Extract the name
  1179. CHECKHR(hr = _HrGetInlineSymbol(pszData, &pSymbol, &cboffColon));
  1180. // Symbol Must be the same
  1181. if (pRow->pSymbol != pSymbol)
  1182. {
  1183. hr = TrapError(E_FAIL);
  1184. goto exit;
  1185. }
  1186. // Adjust pszData
  1187. Assert(cboffColon < cchData);
  1188. psz = (LPSTR)(pszData + cboffColon + 1);
  1189. cchData = cchData - cboffColon - 1;
  1190. Assert(psz[cchData] == '\0');
  1191. }
  1192. // Setup the variant
  1193. rValue.type = MVT_STRINGA;
  1194. rValue.rStringA.pszVal = psz;
  1195. rValue.rStringA.cchVal = cchData;
  1196. // Tell value about the new row data
  1197. CHECKHR(hr = _HrSetPropertyValue(pRow, 0, &rValue));
  1198. // Clear Position Information
  1199. pRow->cboffStart = 0;
  1200. pRow->cboffColon = 0;
  1201. pRow->cboffEnd = 0;
  1202. exit:
  1203. // Thread Safety
  1204. LeaveCriticalSection(&m_cs);
  1205. // Done
  1206. return hr;
  1207. }
  1208. // --------------------------------------------------------------------------------
  1209. // CMimePropertyContainer::GetRowInfo
  1210. // --------------------------------------------------------------------------------
  1211. STDMETHODIMP CMimePropertyContainer::GetRowInfo(HHEADERROW hRow, LPHEADERROWINFO pInfo)
  1212. {
  1213. // Locals
  1214. HRESULT hr=S_OK;
  1215. LPPROPERTY pRow;
  1216. // InvalidArg
  1217. if (NULL == pInfo)
  1218. return TrapError(E_INVALIDARG);
  1219. // Thread Safety
  1220. EnterCriticalSection(&m_cs);
  1221. // Validate the Handle
  1222. CHECKEXP(_FIsValidHRow(hRow) == FALSE, MIME_E_INVALID_HANDLE);
  1223. // Get the row
  1224. pRow = PRowFromHRow(hRow);
  1225. // Copy the row info
  1226. pInfo->dwRowNumber = pRow->dwRowNumber;
  1227. pInfo->cboffStart = pRow->cboffStart;
  1228. pInfo->cboffColon = pRow->cboffColon;
  1229. pInfo->cboffEnd = pRow->cboffEnd;
  1230. exit:
  1231. // Thread Safety
  1232. LeaveCriticalSection(&m_cs);
  1233. // Done
  1234. return hr;
  1235. }
  1236. // --------------------------------------------------------------------------------
  1237. // CMimePropertyContainer::SetRowNumber
  1238. // --------------------------------------------------------------------------------
  1239. STDMETHODIMP CMimePropertyContainer::SetRowNumber(HHEADERROW hRow, DWORD dwRowNumber)
  1240. {
  1241. // Locals
  1242. HRESULT hr=S_OK;
  1243. LPPROPERTY pRow;
  1244. // Thread Safety
  1245. EnterCriticalSection(&m_cs);
  1246. // Validate the Handle
  1247. CHECKEXP(_FIsValidHRow(hRow) == FALSE, MIME_E_INVALID_HANDLE);
  1248. // Get the row
  1249. pRow = PRowFromHRow(hRow);
  1250. // Copy the row info
  1251. pRow->dwRowNumber = dwRowNumber;
  1252. exit:
  1253. // Thread Safety
  1254. LeaveCriticalSection(&m_cs);
  1255. // Done
  1256. return hr;
  1257. }
  1258. // --------------------------------------------------------------------------------
  1259. // CMimePropertyContainer::EnumRows
  1260. // --------------------------------------------------------------------------------
  1261. STDMETHODIMP CMimePropertyContainer::EnumRows(LPCSTR pszHeader, DWORD dwFlags, IMimeEnumHeaderRows **ppEnum)
  1262. {
  1263. // Locals
  1264. HRESULT hr=S_OK;
  1265. ULONG i,
  1266. iEnum=0,
  1267. cEnumCount;
  1268. LPENUMHEADERROW pEnumRow=NULL;
  1269. LPPROPERTY pRow;
  1270. CMimeEnumHeaderRows *pEnum=NULL;
  1271. LPROWINDEX prgIndex=NULL;
  1272. ULONG cRows;
  1273. // check params
  1274. if (NULL == ppEnum)
  1275. return TrapError(E_INVALIDARG);
  1276. // Init
  1277. *ppEnum = NULL;
  1278. // Thread Safety
  1279. EnterCriticalSection(&m_cs);
  1280. // This builds an inverted index on the header rows sorted by postion weight
  1281. CHECKHR(hr = _HrGetHeaderTableSaveIndex(&cRows, &prgIndex));
  1282. // Lets Count the Rows
  1283. CHECKHR(hr = CountRows(pszHeader, &cEnumCount));
  1284. // Allocate pEnumRow
  1285. CHECKALLOC(pEnumRow = (LPENUMHEADERROW)g_pMalloc->Alloc(cEnumCount * sizeof(ENUMHEADERROW)));
  1286. // ZeroInit
  1287. ZeroMemory(pEnumRow, cEnumCount * sizeof(ENUMHEADERROW));
  1288. // Loop through the rows
  1289. for (i=0; i<cRows; i++)
  1290. {
  1291. // Get the row
  1292. Assert(_FIsValidHRow(prgIndex[i].hRow));
  1293. pRow = PRowFromHRow(prgIndex[i].hRow);
  1294. // Is this a header the client wants
  1295. if (NULL == pszHeader || lstrcmpi(pszHeader, pRow->pSymbol->pszName) == 0)
  1296. {
  1297. // Valide
  1298. Assert(iEnum < cEnumCount);
  1299. // Set the symbol on this enum row
  1300. pEnumRow[iEnum].dwReserved = (DWORD)pRow->pSymbol;
  1301. // Lets always give the handle
  1302. pEnumRow[iEnum].hRow = pRow->hRow;
  1303. // If Enumerating only handles...
  1304. if (!ISFLAGSET(dwFlags, HTF_ENUMHANDLESONLY))
  1305. {
  1306. // Get the data for this enum row
  1307. CHECKHR(hr = GetRowData(pRow->hRow, dwFlags, &pEnumRow[iEnum].pszData, &pEnumRow[iEnum].cchData));
  1308. }
  1309. // Increment iEnum
  1310. iEnum++;
  1311. }
  1312. }
  1313. // Allocate
  1314. CHECKALLOC(pEnum = new CMimeEnumHeaderRows);
  1315. // Initialize
  1316. CHECKHR(hr = pEnum->HrInit(0, dwFlags, cEnumCount, pEnumRow, FALSE));
  1317. // Don't Free pEnumRow
  1318. pEnumRow = NULL;
  1319. // Return it
  1320. (*ppEnum) = (IMimeEnumHeaderRows *)pEnum;
  1321. (*ppEnum)->AddRef();
  1322. exit:
  1323. // Cleanup
  1324. SafeRelease(pEnum);
  1325. SafeMemFree(prgIndex);
  1326. if (pEnumRow)
  1327. g_cMoleAlloc.FreeEnumHeaderRowArray(cEnumCount, pEnumRow, TRUE);
  1328. // Thread Safety
  1329. LeaveCriticalSection(&m_cs);
  1330. // Done
  1331. return hr;
  1332. }
  1333. // --------------------------------------------------------------------------------
  1334. // CMimePropertyContainer::Clone
  1335. // --------------------------------------------------------------------------------
  1336. STDMETHODIMP CMimePropertyContainer::Clone(IMimeHeaderTable **ppTable)
  1337. {
  1338. // Locals
  1339. HRESULT hr=S_OK;
  1340. LPCONTAINER pContainer=NULL;
  1341. // InvalidArg
  1342. if (NULL == ppTable)
  1343. return TrapError(E_INVALIDARG);
  1344. // Init
  1345. *ppTable = NULL;
  1346. // Thread Safety
  1347. EnterCriticalSection(&m_cs);
  1348. // Ask the container to clone itself
  1349. CHECKHR(hr = Clone(&pContainer));
  1350. // Bind to the IID_IMimeHeaderTable View
  1351. CHECKHR(hr = pContainer->QueryInterface(IID_IMimeHeaderTable, (LPVOID *)ppTable));
  1352. exit:
  1353. // Cleanup
  1354. SafeRelease(pContainer);
  1355. // Thread Safety
  1356. LeaveCriticalSection(&m_cs);
  1357. // Done
  1358. return hr;
  1359. }
  1360. // --------------------------------------------------------------------------------
  1361. // CMimePropertyContainer::_HrSaveAddressGroup
  1362. // --------------------------------------------------------------------------------
  1363. HRESULT CMimePropertyContainer::_HrSaveAddressGroup(LPPROPERTY pProperty, IStream *pStream,
  1364. ULONG *pcAddrsWrote, ADDRESSFORMAT format)
  1365. {
  1366. // Locals
  1367. HRESULT hr=S_OK;
  1368. LPMIMEADDRESS pAddress;
  1369. // Invalid Arg
  1370. Assert(pProperty && pProperty->pGroup && pStream && pcAddrsWrote);
  1371. Assert(!ISFLAGSET(pProperty->dwState, PRSTATE_NEEDPARSE));
  1372. // Loop Infos...
  1373. for (pAddress=pProperty->pGroup->pHead; pAddress!=NULL; pAddress=pAddress->pNext)
  1374. {
  1375. // Tell the Address Info object to write its display information
  1376. CHECKHR(hr = _HrSaveAddress(pProperty, pAddress, pStream, pcAddrsWrote, format));
  1377. // Increment cAddresses Count
  1378. (*pcAddrsWrote)++;
  1379. }
  1380. exit:
  1381. // Done
  1382. return hr;
  1383. }
  1384. // ----------------------------------------------------------------------------
  1385. // CMimePropertyContainer::_HrSaveAddress
  1386. // ----------------------------------------------------------------------------
  1387. HRESULT CMimePropertyContainer::_HrSaveAddress(LPPROPERTY pProperty, LPMIMEADDRESS pAddress,
  1388. IStream *pStream, ULONG *pcAddrsWrote, ADDRESSFORMAT format)
  1389. {
  1390. // Locals
  1391. HRESULT hr=S_OK;
  1392. LPSTR pszName=NULL;
  1393. BOOL fWriteEmail=FALSE;
  1394. LPSTR pszEscape=NULL;
  1395. BOOL fRFC822=FALSE;
  1396. MIMEVARIANT rSource;
  1397. MIMEVARIANT rDest;
  1398. // Invalid Arg
  1399. Assert(pProperty && pAddress && pStream && pcAddrsWrote);
  1400. // Init Dest
  1401. ZeroMemory(&rDest, sizeof(MIMEVARIANT));
  1402. // Deleted or Empty continue
  1403. if (FIsEmptyA(pAddress->rFriendly.psz) && FIsEmptyA(pAddress->rEmail.psz))
  1404. {
  1405. Assert(FALSE);
  1406. goto exit;
  1407. }
  1408. // RFC822 Format
  1409. if (AFT_RFC822_TRANSMIT == format || AFT_RFC822_ENCODED == format || AFT_RFC822_DECODED == format)
  1410. fRFC822 = TRUE;
  1411. // Decide Delimiter
  1412. if (*pcAddrsWrote > 0)
  1413. {
  1414. // AFT_RFC822_TRANSMIT
  1415. if (AFT_RFC822_TRANSMIT == format)
  1416. {
  1417. // ',\r\n\t'
  1418. CHECKHR (hr = pStream->Write(c_szAddressFold, lstrlen(c_szAddressFold), NULL));
  1419. }
  1420. // AFT_DISPLAY_FRIENDLY, AFT_DISPLAY_EMAIL, AFT_DISPLAY_BOTH
  1421. else
  1422. {
  1423. // '; '
  1424. CHECKHR(hr = pStream->Write(c_szSemiColonSpace, lstrlen(c_szSemiColonSpace), NULL));
  1425. }
  1426. }
  1427. // Only format that excludes writing the email name
  1428. if (AFT_DISPLAY_FRIENDLY != format && FIsEmptyA(pAddress->rEmail.psz) == FALSE)
  1429. fWriteEmail = TRUE;
  1430. // Only format that excludes writing the display name
  1431. if (AFT_DISPLAY_EMAIL != format && FIsEmptyA(pAddress->rFriendly.psz) == FALSE)
  1432. {
  1433. // Should we write the name
  1434. if (AFT_RFC822_TRANSMIT == format && fWriteEmail && StrStr(pAddress->rFriendly.psz, pAddress->rEmail.psz))
  1435. pszName = NULL;
  1436. else
  1437. {
  1438. // Setup Types
  1439. rDest.type = MVT_STRINGA;
  1440. rSource.type = MVT_STRINGA;
  1441. // Init pszName
  1442. pszName = pAddress->rFriendly.psz;
  1443. // Escape It
  1444. if (fRFC822 && MimeOleEscapeString(CP_ACP, pszName, &pszEscape) == S_OK)
  1445. {
  1446. // Escaped
  1447. pszName = pszEscape;
  1448. rSource.rStringA.pszVal = pszName;
  1449. rSource.rStringA.cchVal = lstrlen(pszName);
  1450. }
  1451. // Otherwise
  1452. else
  1453. {
  1454. rSource.rStringA.pszVal = pAddress->rFriendly.psz;
  1455. rSource.rStringA.cchVal = pAddress->rFriendly.cch;
  1456. }
  1457. // Encoded
  1458. if (AFT_RFC822_ENCODED == format || AFT_RFC822_TRANSMIT == format)
  1459. {
  1460. // Encode It
  1461. if (SUCCEEDED(HrConvertVariant(pProperty->pSymbol, pAddress->pCharset, pAddress->ietFriendly, CVF_NOALLOC | PDF_ENCODED, 0, &rSource, &rDest)))
  1462. pszName = rDest.rStringA.pszVal;
  1463. }
  1464. // Decoded
  1465. else if (IET_ENCODED == pAddress->ietFriendly)
  1466. {
  1467. // Encode It
  1468. if (SUCCEEDED(HrConvertVariant(pProperty->pSymbol, pAddress->pCharset, pAddress->ietFriendly, CVF_NOALLOC, 0, &rSource, &rDest)))
  1469. pszName = rDest.rStringA.pszVal;
  1470. }
  1471. }
  1472. }
  1473. // Write Display Name ?
  1474. if (NULL != pszName)
  1475. {
  1476. // Write Quote
  1477. if (fRFC822)
  1478. CHECKHR (hr = pStream->Write(c_szDoubleQuote, lstrlen(c_szDoubleQuote), NULL));
  1479. // Write display name
  1480. CHECKHR(hr = pStream->Write(pszName, lstrlen(pszName), NULL));
  1481. // Write Quote
  1482. if (fRFC822)
  1483. CHECKHR (hr = pStream->Write(c_szDoubleQuote, lstrlen(c_szDoubleQuote), NULL));
  1484. }
  1485. // Write Email
  1486. if (TRUE == fWriteEmail)
  1487. {
  1488. // Set Start
  1489. LPCSTR pszStart = pszName ? c_szEmailSpaceStart : c_szEmailStart;
  1490. // Begin Email '>'
  1491. CHECKHR(hr = pStream->Write(pszStart, lstrlen(pszStart), NULL));
  1492. // Write email
  1493. CHECKHR(hr = pStream->Write(pAddress->rEmail.psz, pAddress->rEmail.cch, NULL));
  1494. // End Email '>'
  1495. CHECKHR(hr = pStream->Write(c_szEmailEnd, lstrlen(c_szEmailEnd), NULL));
  1496. }
  1497. exit:
  1498. // Cleanup
  1499. SafeMemFree(pszEscape);
  1500. MimeVariantFree(&rDest);
  1501. // Done
  1502. return hr;
  1503. }
  1504. // --------------------------------------------------------------------------------
  1505. // CMimePropertyContainer::_HrQueryAddressGroup
  1506. // --------------------------------------------------------------------------------
  1507. HRESULT CMimePropertyContainer::_HrQueryAddressGroup(LPPROPERTY pProperty, LPCSTR pszCriteria,
  1508. boolean fSubString, boolean fCaseSensitive)
  1509. {
  1510. // Locals
  1511. HRESULT hr=S_OK;
  1512. LPMIMEADDRESS pAddress;
  1513. // Invalid Arg
  1514. Assert(pProperty && pProperty->pGroup && pszCriteria);
  1515. // Does the Property need to be parsed ?
  1516. CHECKHR(hr = _HrParseInternetAddress(pProperty));
  1517. // Loop Infos...
  1518. for (pAddress=pProperty->pGroup->pHead; pAddress!=NULL; pAddress=pAddress->pNext)
  1519. {
  1520. // Tell the Address Info object to write its display information
  1521. if (_HrQueryAddress(pProperty, pAddress, pszCriteria, fSubString, fCaseSensitive) == S_OK)
  1522. goto exit;
  1523. }
  1524. // Not Found
  1525. hr = S_FALSE;
  1526. exit:
  1527. // Done
  1528. return hr;
  1529. }
  1530. // ----------------------------------------------------------------------------
  1531. // CMimePropertyContainer::_HrQueryAddress
  1532. // ----------------------------------------------------------------------------
  1533. HRESULT CMimePropertyContainer::_HrQueryAddress(LPPROPERTY pProperty, LPMIMEADDRESS pAddress,
  1534. LPCSTR pszCriteria, boolean fSubString, boolean fCaseSensitive)
  1535. {
  1536. // Locals
  1537. HRESULT hr=S_OK;
  1538. LPSTR pszDisplay;
  1539. LPSTR pszFree=NULL;
  1540. MIMEVARIANT rSource;
  1541. MIMEVARIANT rDest;
  1542. // Invalid Arg
  1543. Assert(pProperty && pAddress && pszCriteria);
  1544. // Init
  1545. ZeroMemory(&rDest, sizeof(MIMEVARIANT));
  1546. // Query Email Address First
  1547. if (MimeOleQueryString(pAddress->rEmail.psz, pszCriteria, fSubString, fCaseSensitive) == S_OK)
  1548. goto exit;
  1549. // Decode Display Name
  1550. pszDisplay = pAddress->rFriendly.psz;
  1551. // Decode the Property
  1552. if (IET_ENCODED == pAddress->ietFriendly)
  1553. {
  1554. // Set Source
  1555. rDest.type = MVT_STRINGA;
  1556. rSource.type = MVT_STRINGA;
  1557. rSource.rStringA.pszVal = pAddress->rFriendly.psz;
  1558. rSource.rStringA.cchVal = pAddress->rFriendly.cch;
  1559. // Decode the Property
  1560. if (SUCCEEDED(HrConvertVariant(pProperty->pSymbol, pAddress->pCharset, pAddress->ietFriendly, CVF_NOALLOC, 0, &rSource, &rDest)))
  1561. pszDisplay = rDest.rStringA.pszVal;
  1562. }
  1563. // Query Email Address First
  1564. if (MimeOleQueryString(pszDisplay, pszCriteria, fSubString, fCaseSensitive) == S_OK)
  1565. goto exit;
  1566. // Not Found
  1567. hr = S_FALSE;
  1568. exit:
  1569. // Cleanup
  1570. MimeVariantFree(&rDest);
  1571. // Done
  1572. return hr;
  1573. }
  1574. // ----------------------------------------------------------------------------
  1575. // CMimePropertyContainer::Append
  1576. // ----------------------------------------------------------------------------
  1577. STDMETHODIMP CMimePropertyContainer::Append(DWORD dwAdrType, ENCODINGTYPE ietFriendly, LPCSTR pszFriendly,
  1578. LPCSTR pszEmail, LPHADDRESS phAddress)
  1579. {
  1580. // Locals
  1581. HRESULT hr=S_OK;
  1582. ADDRESSPROPS rProps;
  1583. // Setup rProps
  1584. ZeroMemory(&rProps, sizeof(ADDRESSPROPS));
  1585. // Set AddrTyupe
  1586. rProps.dwProps = IAP_ADRTYPE | IAP_ENCODING;
  1587. rProps.dwAdrType = dwAdrType;
  1588. rProps.ietFriendly = ietFriendly;
  1589. // Set pszFriendly
  1590. if (pszFriendly)
  1591. {
  1592. FLAGSET(rProps.dwProps, IAP_FRIENDLY);
  1593. rProps.pszFriendly = (LPSTR)pszFriendly;
  1594. }
  1595. // Set pszEmail
  1596. if (pszEmail)
  1597. {
  1598. FLAGSET(rProps.dwProps, IAP_EMAIL);
  1599. rProps.pszEmail = (LPSTR)pszEmail;
  1600. }
  1601. // Set the Email Address
  1602. CHECKHR(hr = Insert(&rProps, phAddress));
  1603. exit:
  1604. // Done
  1605. return hr;
  1606. }
  1607. // ----------------------------------------------------------------------------
  1608. // CMimePropertyContainer::Insert
  1609. // ----------------------------------------------------------------------------
  1610. STDMETHODIMP CMimePropertyContainer::Insert(LPADDRESSPROPS pProps, LPHADDRESS phAddress)
  1611. {
  1612. // Locals
  1613. HRESULT hr=S_OK;
  1614. LPPROPSYMBOL pSymbol;
  1615. LPPROPERTY pProperty;
  1616. LPMIMEADDRESS pAddress;
  1617. // Invalid Arg
  1618. if (NULL == pProps)
  1619. return TrapError(E_INVALIDARG);
  1620. // Must have an Email Address and Address Type
  1621. if (!ISFLAGSET(pProps->dwProps, IAP_ADRTYPE) || (ISFLAGSET(pProps->dwProps, IAP_EMAIL) && FIsEmptyA(pProps->pszEmail)))
  1622. return TrapError(E_INVALIDARG);
  1623. // Init
  1624. if (phAddress)
  1625. *phAddress = NULL;
  1626. // Thread Safety
  1627. EnterCriticalSection(&m_cs);
  1628. // Get Header
  1629. CHECKHR(hr = g_pSymCache->HrOpenSymbol(pProps->dwAdrType, &pSymbol));
  1630. // Open the group
  1631. CHECKHR(hr = _HrOpenProperty(pSymbol, &pProperty));
  1632. // Does the Property need to be parsed ?
  1633. CHECKHR(hr = _HrParseInternetAddress(pProperty));
  1634. // Append an Address to the group
  1635. CHECKHR(hr = _HrAppendAddressGroup(pProperty->pGroup, &pAddress));
  1636. // The group is dirty
  1637. Assert(pAddress->pGroup);
  1638. pAddress->pGroup->fDirty = TRUE;
  1639. // Set the Address Type
  1640. pAddress->dwAdrType = pProps->dwAdrType;
  1641. // Copy Address Props to Mime Address
  1642. CHECKHR(hr = SetProps(pAddress->hThis, pProps));
  1643. // Return the Handle
  1644. if (phAddress)
  1645. *phAddress = pAddress->hThis;
  1646. exit:
  1647. // Failure
  1648. if (FAILED(hr) && pAddress)
  1649. Delete(pAddress->hThis);
  1650. // Thread Safety
  1651. LeaveCriticalSection(&m_cs);
  1652. // Done
  1653. return hr;
  1654. }
  1655. // --------------------------------------------------------------------------------
  1656. // CMimePropertyContainer::_HrSetAddressProps
  1657. // --------------------------------------------------------------------------------
  1658. HRESULT CMimePropertyContainer::_HrSetAddressProps(LPADDRESSPROPS pProps, LPMIMEADDRESS pAddress)
  1659. {
  1660. // Locals
  1661. HRESULT hr=S_OK;
  1662. // IAP_ADRTYPE
  1663. if (ISFLAGSET(pProps->dwProps, IAP_ADRTYPE))
  1664. pAddress->dwAdrType = pProps->dwAdrType;
  1665. // IAP_ENCODING
  1666. if (ISFLAGSET(pProps->dwProps, IAP_ENCODING))
  1667. pAddress->ietFriendly = pProps->ietFriendly;
  1668. // IAP_HCHARSET
  1669. if (ISFLAGSET(pProps->dwProps, IAP_CHARSET) && pProps->hCharset)
  1670. {
  1671. // Resolve to pCharset
  1672. LPINETCSETINFO pCharset;
  1673. if (SUCCEEDED(g_pInternat->HrOpenCharset(pProps->hCharset, &pCharset)))
  1674. pAddress->pCharset = pCharset;
  1675. }
  1676. // IAP_CERTSTATE
  1677. if (ISFLAGSET(pProps->dwProps, IAP_CERTSTATE))
  1678. pAddress->certstate = pProps->certstate;
  1679. // IAP_COOKIE
  1680. if (ISFLAGSET(pProps->dwProps, IAP_COOKIE))
  1681. pAddress->dwCookie = pProps->dwCookie;
  1682. // IAP_FRIENDLY
  1683. if (ISFLAGSET(pProps->dwProps, IAP_FRIENDLY) && pProps->pszFriendly)
  1684. {
  1685. // Set It
  1686. CHECKHR(hr = HrSetAddressTokenA(pProps->pszFriendly, lstrlen(pProps->pszFriendly), &pAddress->rFriendly));
  1687. }
  1688. // IAP_EMAIL
  1689. if (ISFLAGSET(pProps->dwProps, IAP_EMAIL) && pProps->pszEmail)
  1690. {
  1691. // Set It
  1692. CHECKHR(hr = HrSetAddressTokenA(pProps->pszEmail, lstrlen(pProps->pszEmail), &pAddress->rEmail));
  1693. }
  1694. // IAP_SIGNING_PRINT
  1695. if (ISFLAGSET(pProps->dwProps, IAP_SIGNING_PRINT) && pProps->tbSigning.pBlobData)
  1696. {
  1697. // Free Current Blob
  1698. SafeMemFree(pAddress->tbSigning.pBlobData);
  1699. pAddress->tbSigning.cbSize = 0;
  1700. // Dup
  1701. CHECKHR(hr = HrCopyBlob(&pProps->tbSigning, &pAddress->tbSigning));
  1702. }
  1703. // IAP_ENCRYPTION_PRINT
  1704. if (ISFLAGSET(pProps->dwProps, IAP_ENCRYPTION_PRINT) && pProps->tbEncryption.pBlobData)
  1705. {
  1706. // Free Current Blob
  1707. SafeMemFree(pAddress->tbEncryption.pBlobData);
  1708. pAddress->tbEncryption.cbSize = 0;
  1709. // Dup
  1710. CHECKHR(hr = HrCopyBlob(&pProps->tbEncryption, &pAddress->tbEncryption));
  1711. }
  1712. // pAddress->pGroup is Dirty
  1713. Assert(pAddress->pGroup);
  1714. if (pAddress->pGroup)
  1715. pAddress->pGroup->fDirty = TRUE;
  1716. exit:
  1717. // Done
  1718. return hr;
  1719. }
  1720. // --------------------------------------------------------------------------------
  1721. // CMimePropertyContainer::_HrGetAddressProps
  1722. // --------------------------------------------------------------------------------
  1723. HRESULT CMimePropertyContainer::_HrGetAddressProps(LPADDRESSPROPS pProps, LPMIMEADDRESS pAddress)
  1724. {
  1725. // Locals
  1726. HRESULT hr=S_OK;
  1727. // IAP_CHARSET
  1728. if (ISFLAGSET(pProps->dwProps, IAP_CHARSET))
  1729. {
  1730. if (pAddress->pCharset && pAddress->pCharset->hCharset)
  1731. {
  1732. pProps->hCharset = pAddress->pCharset->hCharset;
  1733. }
  1734. else
  1735. {
  1736. pProps->hCharset = NULL;
  1737. FLAGCLEAR(pProps->dwProps, IAP_CHARSET);
  1738. }
  1739. }
  1740. // IAP_HANDLE
  1741. if (ISFLAGSET(pProps->dwProps, IAP_HANDLE))
  1742. {
  1743. Assert(pAddress->hThis);
  1744. pProps->hAddress = pAddress->hThis;
  1745. }
  1746. // IAP_ADRTYPE
  1747. if (ISFLAGSET(pProps->dwProps, IAP_ADRTYPE))
  1748. {
  1749. Assert(pAddress->dwAdrType);
  1750. pProps->dwAdrType = pAddress->dwAdrType;
  1751. }
  1752. // IAP_COOKIE
  1753. if (ISFLAGSET(pProps->dwProps, IAP_COOKIE))
  1754. {
  1755. pProps->dwCookie = pAddress->dwCookie;
  1756. }
  1757. // IAP_CERTSTATE
  1758. if (ISFLAGSET(pProps->dwProps, IAP_CERTSTATE))
  1759. {
  1760. pProps->certstate = pAddress->certstate;
  1761. }
  1762. // IAP_ENCODING
  1763. if (ISFLAGSET(pProps->dwProps, IAP_ENCODING))
  1764. {
  1765. pProps->ietFriendly = pAddress->ietFriendly;
  1766. }
  1767. // IAP_FRIENDLY
  1768. if (ISFLAGSET(pProps->dwProps, IAP_FRIENDLY))
  1769. {
  1770. // Decode
  1771. if (!FIsEmptyA(pAddress->rFriendly.psz))
  1772. {
  1773. // Encoded
  1774. if (IET_ENCODED == pAddress->ietFriendly)
  1775. {
  1776. // Locals
  1777. LPPROPSYMBOL pSymbol;
  1778. MIMEVARIANT rSource;
  1779. MIMEVARIANT rDest;
  1780. // Get the symbol of the address tyep
  1781. CHECKHR(hr = g_pSymCache->HrOpenSymbol(pAddress->dwAdrType, &pSymbol));
  1782. // Setup Source
  1783. rSource.type = MVT_STRINGA;
  1784. rSource.rStringA.pszVal = pAddress->rFriendly.psz;
  1785. rSource.rStringA.cchVal = pAddress->rFriendly.cch;
  1786. // Setup Dest
  1787. rDest.type = MVT_STRINGA;
  1788. // Decode It
  1789. if (SUCCEEDED(HrConvertVariant(pSymbol, pAddress->pCharset, IET_ENCODED, 0, 0, &rSource, &rDest)))
  1790. pProps->pszFriendly = rDest.rStringA.pszVal;
  1791. // Otherwise, dup it
  1792. else
  1793. {
  1794. // Dup
  1795. CHECKALLOC(pProps->pszFriendly = PszDupA(pAddress->rFriendly.psz));
  1796. }
  1797. }
  1798. // Otherwise, just copy it
  1799. else
  1800. {
  1801. // Dup
  1802. CHECKALLOC(pProps->pszFriendly = PszDupA(pAddress->rFriendly.psz));
  1803. }
  1804. }
  1805. else
  1806. {
  1807. pProps->pszFriendly = NULL;
  1808. FLAGCLEAR(pProps->dwProps, IAP_FRIENDLY);
  1809. }
  1810. }
  1811. // IAP_EMAIL
  1812. if (ISFLAGSET(pProps->dwProps, IAP_EMAIL))
  1813. {
  1814. if (!FIsEmptyA(pAddress->rEmail.psz))
  1815. {
  1816. CHECKALLOC(pProps->pszEmail = PszDupA(pAddress->rEmail.psz));
  1817. }
  1818. else
  1819. {
  1820. pProps->pszEmail = NULL;
  1821. FLAGCLEAR(pProps->dwProps, IAP_EMAIL);
  1822. }
  1823. }
  1824. // IAP_SIGNING_PRINT
  1825. if (ISFLAGSET(pProps->dwProps, IAP_SIGNING_PRINT))
  1826. {
  1827. if (pAddress->tbSigning.pBlobData)
  1828. {
  1829. CHECKHR(hr = HrCopyBlob(&pAddress->tbSigning, &pProps->tbSigning));
  1830. }
  1831. else
  1832. {
  1833. pProps->tbSigning.pBlobData = NULL;
  1834. pProps->tbSigning.cbSize = 0;
  1835. FLAGCLEAR(pProps->dwProps, IAP_SIGNING_PRINT);
  1836. }
  1837. }
  1838. // IAP_ENCRYPTION_PRINT
  1839. if (ISFLAGSET(pProps->dwProps, IAP_ENCRYPTION_PRINT))
  1840. {
  1841. if (pAddress->tbEncryption.pBlobData)
  1842. {
  1843. CHECKHR(hr = HrCopyBlob(&pAddress->tbEncryption, &pProps->tbEncryption));
  1844. }
  1845. else
  1846. {
  1847. pProps->tbEncryption.pBlobData = NULL;
  1848. pProps->tbEncryption.cbSize = 0;
  1849. FLAGCLEAR(pProps->dwProps, IAP_ENCRYPTION_PRINT);
  1850. }
  1851. }
  1852. exit:
  1853. // Done
  1854. return hr;
  1855. }
  1856. // ----------------------------------------------------------------------------
  1857. // CMimePropertyContainer::SetProps
  1858. // ----------------------------------------------------------------------------
  1859. STDMETHODIMP CMimePropertyContainer::SetProps(HADDRESS hAddress, LPADDRESSPROPS pProps)
  1860. {
  1861. // Locals
  1862. HRESULT hr=S_OK;
  1863. LPPROPSYMBOL pSymbol;
  1864. LPPROPERTY pProperty;
  1865. LPMIMEADDRESS pAddress;
  1866. // Invalid Arg
  1867. if (NULL == pProps)
  1868. return TrapError(E_INVALIDARG);
  1869. // Must have an Email Address
  1870. if (ISFLAGSET(pProps->dwProps, IAP_EMAIL) && FIsEmptyA(pProps->pszEmail))
  1871. return TrapError(E_INVALIDARG);
  1872. // Thread Safety
  1873. EnterCriticalSection(&m_cs);
  1874. // Invalid Handle
  1875. if (_FIsValidHAddress(hAddress) == FALSE)
  1876. {
  1877. hr = TrapError(MIME_E_INVALID_HANDLE);
  1878. goto exit;
  1879. }
  1880. // Deref
  1881. pAddress = HADDRESSGET(hAddress);
  1882. // Changing Address Type
  1883. if (ISFLAGSET(pProps->dwProps, IAP_ADRTYPE) && pProps->dwAdrType != pAddress->dwAdrType)
  1884. {
  1885. // Unlink this address from this group
  1886. _UnlinkAddress(pAddress);
  1887. // Get Header
  1888. CHECKHR(hr = g_pSymCache->HrOpenSymbol(pProps->dwAdrType, &pSymbol));
  1889. // Open the group
  1890. CHECKHR(hr = _HrOpenProperty(pSymbol, &pProperty));
  1891. // Does the Property need to be parsed ?
  1892. CHECKHR(hr = _HrParseInternetAddress(pProperty));
  1893. // LinkAddress
  1894. _LinkAddress(pAddress, pProperty->pGroup);
  1895. // Dirty
  1896. pProperty->pGroup->fDirty = TRUE;
  1897. }
  1898. // Changing other properties
  1899. CHECKHR(hr = _HrSetAddressProps(pProps, pAddress));
  1900. exit:
  1901. // Thread Safety
  1902. LeaveCriticalSection(&m_cs);
  1903. // Done
  1904. return hr;
  1905. }
  1906. // ----------------------------------------------------------------------------
  1907. // CMimePropertyContainer::GetProps
  1908. // ----------------------------------------------------------------------------
  1909. STDMETHODIMP CMimePropertyContainer::GetProps(HADDRESS hAddress, LPADDRESSPROPS pProps)
  1910. {
  1911. // Locals
  1912. HRESULT hr=S_OK;
  1913. LPMIMEADDRESS pAddress;
  1914. // Invalid Arg
  1915. if (NULL == pProps)
  1916. return TrapError(E_INVALIDARG);
  1917. // Thread Safety
  1918. EnterCriticalSection(&m_cs);
  1919. // Invalid Handle
  1920. if (_FIsValidHAddress(hAddress) == FALSE)
  1921. {
  1922. hr = TrapError(MIME_E_INVALID_HANDLE);
  1923. goto exit;
  1924. }
  1925. // Deref
  1926. pAddress = HADDRESSGET(hAddress);
  1927. // Changing Email Address to Null
  1928. CHECKHR(hr = _HrGetAddressProps(pProps, pAddress));
  1929. exit:
  1930. // Thread Safety
  1931. LeaveCriticalSection(&m_cs);
  1932. // Done
  1933. return hr;
  1934. }
  1935. // ----------------------------------------------------------------------------
  1936. // CMimePropertyContainer::GetSender
  1937. // ----------------------------------------------------------------------------
  1938. STDMETHODIMP CMimePropertyContainer::GetSender(LPADDRESSPROPS pProps)
  1939. {
  1940. // Locals
  1941. HRESULT hr=S_OK;
  1942. LPPROPERTY pProperty;
  1943. LPPROPERTY pSender=NULL;
  1944. HADDRESS hAddress=NULL;
  1945. // Invalid Arg
  1946. if (NULL == pProps)
  1947. return TrapError(E_INVALIDARG);
  1948. // Thread Safety
  1949. EnterCriticalSection(&m_cs);
  1950. // Find first from
  1951. for (pProperty=m_rAdrTable.pHead; pProperty!=NULL; pProperty=pProperty->pGroup->pNext)
  1952. {
  1953. // Not the type I want
  1954. if (ISFLAGSET(pProperty->pSymbol->dwAdrType, IAT_FROM))
  1955. {
  1956. // Does the Property need to be parsed ?
  1957. CHECKHR(hr = _HrParseInternetAddress(pProperty));
  1958. // Take the first address
  1959. if (pProperty->pGroup->pHead)
  1960. hAddress = pProperty->pGroup->pHead->hThis;
  1961. // Done
  1962. break;
  1963. }
  1964. // Look for Sender:
  1965. if (ISFLAGSET(pProperty->pSymbol->dwAdrType, IAT_SENDER) && NULL == pSender)
  1966. {
  1967. // Does the Property need to be parsed ?
  1968. CHECKHR(hr = _HrParseInternetAddress(pProperty));
  1969. // Sender Property
  1970. pSender = pProperty;
  1971. }
  1972. }
  1973. // Is there a sender group
  1974. if (NULL == hAddress && NULL != pSender && NULL != pSender->pGroup->pHead)
  1975. hAddress = pSender->pGroup->pHead->hThis;
  1976. // No Address
  1977. if (NULL == hAddress)
  1978. {
  1979. hr = TrapError(MIME_E_NOT_FOUND);
  1980. goto exit;
  1981. }
  1982. // Get Props
  1983. CHECKHR(hr = GetProps(hAddress, pProps));
  1984. exit:
  1985. // Thread Safety
  1986. LeaveCriticalSection(&m_cs);
  1987. // Done
  1988. return hr;
  1989. }
  1990. // ----------------------------------------------------------------------------
  1991. // CMimePropertyContainer::CountTypes
  1992. // ----------------------------------------------------------------------------
  1993. STDMETHODIMP CMimePropertyContainer::CountTypes(DWORD dwAdrTypes, ULONG *pcAdrs)
  1994. {
  1995. // Locals
  1996. HRESULT hr=S_OK;
  1997. LPPROPERTY pProperty;
  1998. // Invalid Arg
  1999. if (NULL == pcAdrs)
  2000. return TrapError(E_INVALIDARG);
  2001. // Thread Safety
  2002. EnterCriticalSection(&m_cs);
  2003. // Init
  2004. *pcAdrs = 0;
  2005. // Loop through groups
  2006. for (pProperty=m_rAdrTable.pHead; pProperty!=NULL; pProperty=pProperty->pGroup->pNext)
  2007. {
  2008. // Not the type I want
  2009. if (ISFLAGSET(dwAdrTypes, pProperty->pSymbol->dwAdrType))
  2010. {
  2011. // Does the Property need to be parsed ?
  2012. CHECKHR(hr = _HrParseInternetAddress(pProperty));
  2013. // Increment Count
  2014. (*pcAdrs) += pProperty->pGroup->cAdrs;
  2015. }
  2016. }
  2017. exit:
  2018. // Thread Safety
  2019. LeaveCriticalSection(&m_cs);
  2020. // Done
  2021. return hr;
  2022. }
  2023. // ----------------------------------------------------------------------------
  2024. // CMimePropertyContainer::GetTypes
  2025. // ----------------------------------------------------------------------------
  2026. STDMETHODIMP CMimePropertyContainer::GetTypes(DWORD dwAdrTypes, DWORD dwProps, LPADDRESSLIST pList)
  2027. {
  2028. // Locals
  2029. HRESULT hr=S_OK;
  2030. ULONG iAddress;
  2031. LPPROPERTY pProperty;
  2032. LPMIMEADDRESS pAddress;
  2033. // Invalid Arg
  2034. if (NULL == pList)
  2035. return TrapError(E_INVALIDARG);
  2036. // Init
  2037. ZeroMemory(pList, sizeof(ADDRESSLIST));
  2038. // Thread Safety
  2039. EnterCriticalSection(&m_cs);
  2040. // Loop through groups
  2041. CHECKHR(hr = CountTypes(dwAdrTypes, &pList->cAdrs));
  2042. // Nothing..
  2043. if (0 == pList->cAdrs)
  2044. goto exit;
  2045. // Allocate an array
  2046. CHECKHR(hr = HrAlloc((LPVOID *)&pList->prgAdr, pList->cAdrs * sizeof(ADDRESSPROPS)));
  2047. // Init
  2048. ZeroMemory(pList->prgAdr, pList->cAdrs * sizeof(ADDRESSPROPS));
  2049. // Fill with types...
  2050. for (iAddress=0, pProperty=m_rAdrTable.pHead; pProperty!=NULL; pProperty=pProperty->pGroup->pNext)
  2051. {
  2052. // Not the type I want
  2053. if (!ISFLAGSET(dwAdrTypes, pProperty->pSymbol->dwAdrType))
  2054. continue;
  2055. // Does the Property need to be parsed ?
  2056. CHECKHR(hr = _HrParseInternetAddress(pProperty));
  2057. // Loop Infos...
  2058. for (pAddress=pProperty->pGroup->pHead; pAddress!=NULL; pAddress=pAddress->pNext)
  2059. {
  2060. // Verify Size...
  2061. Assert(iAddress < pList->cAdrs);
  2062. // Zeromemory
  2063. ZeroMemory(&pList->prgAdr[iAddress], sizeof(ADDRESSPROPS));
  2064. // Set Desired Props
  2065. pList->prgAdr[iAddress].dwProps = dwProps;
  2066. // Get the Address Props
  2067. CHECKHR(hr = _HrGetAddressProps(&pList->prgAdr[iAddress], pAddress));
  2068. // Increment piCurrent
  2069. iAddress++;
  2070. }
  2071. }
  2072. exit:
  2073. // Failure..
  2074. if (FAILED(hr))
  2075. {
  2076. g_cMoleAlloc.FreeAddressList(pList);
  2077. ZeroMemory(pList, sizeof(ADDRESSLIST));
  2078. }
  2079. // Thread Safety
  2080. LeaveCriticalSection(&m_cs);
  2081. // Done
  2082. return hr;
  2083. }
  2084. // ----------------------------------------------------------------------------
  2085. // CMimePropertyContainer::EnumTypes
  2086. // ----------------------------------------------------------------------------
  2087. STDMETHODIMP CMimePropertyContainer::EnumTypes(DWORD dwAdrTypes, DWORD dwProps, IMimeEnumAddressTypes **ppEnum)
  2088. {
  2089. // Locals
  2090. HRESULT hr=S_OK;
  2091. CMimeEnumAddressTypes *pEnum=NULL;
  2092. ADDRESSLIST rList;
  2093. // Invalid Arg
  2094. if (NULL == ppEnum)
  2095. return TrapError(E_INVALIDARG);
  2096. // Init out param in case of error
  2097. *ppEnum = NULL;
  2098. // Init rList
  2099. ZeroMemory(&rList, sizeof(ADDRESSLIST));
  2100. // Thread Safety
  2101. EnterCriticalSection(&m_cs);
  2102. // Get the address lsit
  2103. CHECKHR(hr = GetTypes(dwAdrTypes, dwProps, &rList));
  2104. // Create a new Enumerator
  2105. CHECKALLOC(pEnum = new CMimeEnumAddressTypes);
  2106. // Init
  2107. CHECKHR(hr = pEnum->HrInit((IMimeAddressTable *)this, 0, &rList, FALSE));
  2108. // Clear rList
  2109. rList.cAdrs = 0;
  2110. rList.prgAdr = NULL;
  2111. // Return it
  2112. *ppEnum = pEnum;
  2113. (*ppEnum)->AddRef();
  2114. exit:
  2115. // Cleanup
  2116. SafeRelease(pEnum);
  2117. if (rList.cAdrs)
  2118. g_cMoleAlloc.FreeAddressList(&rList);
  2119. // Thread Safety
  2120. LeaveCriticalSection(&m_cs);
  2121. // Done
  2122. return hr;
  2123. }
  2124. // ----------------------------------------------------------------------------
  2125. // CMimePropertyContainer::Delete
  2126. // ----------------------------------------------------------------------------
  2127. STDMETHODIMP CMimePropertyContainer::Delete(HADDRESS hAddress)
  2128. {
  2129. // Locals
  2130. HRESULT hr=S_OK;
  2131. LPMIMEADDRESS pAddress;
  2132. // Thread Safety
  2133. EnterCriticalSection(&m_cs);
  2134. // Invalid Handle
  2135. if (_FIsValidHAddress(hAddress) == FALSE)
  2136. {
  2137. hr = TrapError(MIME_E_INVALID_HANDLE);
  2138. goto exit;
  2139. }
  2140. // Deref Address
  2141. pAddress = HADDRESSGET(hAddress);
  2142. // Unlink this address
  2143. _UnlinkAddress(pAddress);
  2144. // Unlink this address
  2145. _FreeAddress(pAddress);
  2146. exit:
  2147. // Thread Safety
  2148. LeaveCriticalSection(&m_cs);
  2149. // Done
  2150. return hr;
  2151. }
  2152. // ----------------------------------------------------------------------------
  2153. // CMimePropertyContainer::DeleteTypes
  2154. // ----------------------------------------------------------------------------
  2155. STDMETHODIMP CMimePropertyContainer::DeleteTypes(DWORD dwAdrTypes)
  2156. {
  2157. // Locals
  2158. LPPROPERTY pProperty;
  2159. BOOL fFound;
  2160. // Thread Safety
  2161. EnterCriticalSection(&m_cs);
  2162. // While there are address types
  2163. while(dwAdrTypes)
  2164. {
  2165. // Reset fFound
  2166. fFound = FALSE;
  2167. // Search for first delete-able address type
  2168. for (pProperty=m_rAdrTable.pHead; pProperty!=NULL; pProperty=pProperty->pGroup->pNext)
  2169. {
  2170. // Not the type I want
  2171. if (ISFLAGSET(dwAdrTypes, pProperty->pSymbol->dwAdrType))
  2172. {
  2173. // We found a properyt
  2174. fFound = TRUE;
  2175. // Clear this address type ad being deleted
  2176. FLAGCLEAR(dwAdrTypes, pProperty->pSymbol->dwAdrType);
  2177. // Unlink this property
  2178. _UnlinkProperty(pProperty);
  2179. // Done
  2180. break;
  2181. }
  2182. }
  2183. // No Property Found
  2184. if (FALSE == fFound)
  2185. break;
  2186. }
  2187. // Thread Safety
  2188. LeaveCriticalSection(&m_cs);
  2189. // Done
  2190. return S_OK;
  2191. }
  2192. // ----------------------------------------------------------------------------
  2193. // CMimePropertyContainer::GetFormat
  2194. // ----------------------------------------------------------------------------
  2195. STDMETHODIMP CMimePropertyContainer::GetFormat(DWORD dwAdrType, ADDRESSFORMAT format, LPSTR *ppszFormat)
  2196. {
  2197. // Locals
  2198. HRESULT hr=S_OK;
  2199. CByteStream cByteStream;
  2200. ULONG cAddrsWrote=0;
  2201. LPPROPERTY pProperty;
  2202. // check params
  2203. if (NULL == ppszFormat)
  2204. return TrapError(E_INVALIDARG);
  2205. // Thread Safety
  2206. EnterCriticalSection(&m_cs);
  2207. // Fill with types...
  2208. for (pProperty=m_rAdrTable.pHead; pProperty!=NULL; pProperty=pProperty->pGroup->pNext)
  2209. {
  2210. // Not the type I want
  2211. if (!ISFLAGSET(dwAdrType, pProperty->pSymbol->dwAdrType))
  2212. continue;
  2213. // Does the Property need to be parsed ?
  2214. CHECKHR(hr = _HrParseInternetAddress(pProperty));
  2215. // Tell the group object to write its display address into pStream
  2216. CHECKHR(hr = _HrSaveAddressGroup(pProperty, &cByteStream, &cAddrsWrote, format));
  2217. }
  2218. // Did we write any for this address tyep ?
  2219. if (cAddrsWrote)
  2220. {
  2221. // Get Text
  2222. CHECKHR(hr = cByteStream.HrAcquireStringA(NULL, ppszFormat, ACQ_DISPLACE));
  2223. }
  2224. else
  2225. hr = MIME_E_NO_DATA;
  2226. exit:
  2227. // Thread Safety
  2228. LeaveCriticalSection(&m_cs);
  2229. // Done
  2230. return hr;
  2231. }
  2232. // ----------------------------------------------------------------------------
  2233. // CMimePropertyContainer::AppendRfc822
  2234. // ----------------------------------------------------------------------------
  2235. STDMETHODIMP CMimePropertyContainer::AppendRfc822(DWORD dwAdrType, ENCODINGTYPE ietEncoding, LPCSTR pszRfc822Adr)
  2236. {
  2237. // Locals
  2238. HRESULT hr=S_OK;
  2239. MIMEVARIANT rValue;
  2240. LPPROPSYMBOL pSymbol;
  2241. // Invalid Arg
  2242. if (NULL == pszRfc822Adr)
  2243. return TrapError(E_INVALIDARG);
  2244. // Thread Safety
  2245. EnterCriticalSection(&m_cs);
  2246. // Get Header
  2247. CHECKHR(hr = g_pSymCache->HrOpenSymbol(dwAdrType, &pSymbol));
  2248. // MimeVariant
  2249. rValue.type = MVT_STRINGA;
  2250. rValue.rStringA.pszVal = (LPSTR)pszRfc822Adr;
  2251. rValue.rStringA.cchVal = lstrlen(pszRfc822Adr);
  2252. // Store as a property
  2253. CHECKHR(hr = AppendProp(pSymbol, (IET_ENCODED == ietEncoding) ? PDF_ENCODED : 0, &rValue));
  2254. exit:
  2255. // Thread Safety
  2256. LeaveCriticalSection(&m_cs);
  2257. // Done
  2258. return hr;
  2259. }
  2260. // ----------------------------------------------------------------------------
  2261. // CMimePropertyContainer::ParseRfc822
  2262. // ----------------------------------------------------------------------------
  2263. STDMETHODIMP CMimePropertyContainer::ParseRfc822(DWORD dwAdrType, ENCODINGTYPE ietEncoding,
  2264. LPCSTR pszRfc822Adr, LPADDRESSLIST pList)
  2265. {
  2266. // Locals
  2267. HRESULT hr=S_OK;
  2268. LPPROPSYMBOL pSymbol;
  2269. LPADDRESSPROPS pAddress;
  2270. ULONG cAlloc=0;
  2271. LPSTR pszData=(LPSTR)pszRfc822Adr;
  2272. PROPVARIANT rDecoded;
  2273. RFC1522INFO rRfc1522Info;
  2274. CAddressParser cAdrParse;
  2275. // Invalid Arg
  2276. if (NULL == pszRfc822Adr || NULL == pList)
  2277. return TrapError(E_INVALIDARG);
  2278. // LocalInit
  2279. ZeroMemory(&rDecoded, sizeof(PROPVARIANT));
  2280. // ZeroParse
  2281. ZeroMemory(pList, sizeof(ADDRESSLIST));
  2282. // Get Header
  2283. CHECKHR(hr = g_pSymCache->HrOpenSymbol(dwAdrType, &pSymbol));
  2284. // Setup rfc1522Info
  2285. rRfc1522Info.hRfc1522Cset = NULL;
  2286. // Decode...
  2287. if (IET_DECODED != ietEncoding)
  2288. {
  2289. // Setup rfc1522Info
  2290. rRfc1522Info.fRfc1522Allowed = TRUE;
  2291. rRfc1522Info.fAllow8bit = FALSE;
  2292. rDecoded.vt = VT_LPSTR;
  2293. // Check for 1522 Encoding...
  2294. if (SUCCEEDED(g_pInternat->DecodeHeader(NULL, pszData, &rDecoded, &rRfc1522Info)))
  2295. pszData = rDecoded.pszVal;
  2296. }
  2297. // Initialize Parse Structure
  2298. cAdrParse.Init(pszData, lstrlen(pszData));
  2299. // Parse
  2300. while(SUCCEEDED(cAdrParse.Next()))
  2301. {
  2302. // Grow my address array ?
  2303. if (pList->cAdrs + 1 > cAlloc)
  2304. {
  2305. // Realloc the array
  2306. CHECKHR(hr = HrRealloc((LPVOID *)&pList->prgAdr, sizeof(ADDRESSPROPS) * (cAlloc + 5)));
  2307. // Increment alloc size
  2308. cAlloc += 5;
  2309. }
  2310. // Readability
  2311. pAddress = &pList->prgAdr[pList->cAdrs];
  2312. // Init
  2313. ZeroMemory(pAddress, sizeof(ADDRESSPROPS));
  2314. // Copy the Friendly Name
  2315. CHECKALLOC(pAddress->pszFriendly = PszDupA(cAdrParse.PszFriendly()));
  2316. // Copy the Email Name
  2317. CHECKALLOC(pAddress->pszEmail = PszDupA(cAdrParse.PszEmail()));
  2318. // Charset
  2319. if (rRfc1522Info.hRfc1522Cset)
  2320. {
  2321. pAddress->hCharset = rRfc1522Info.hRfc1522Cset;
  2322. FLAGSET(pAddress->dwProps, IAP_CHARSET);
  2323. }
  2324. // Encoding
  2325. pAddress->ietFriendly = ietEncoding;
  2326. // Set Property Mask
  2327. FLAGSET(pAddress->dwProps, IAP_FRIENDLY | IAP_EMAIL | IAP_ENCODING);
  2328. // Increment Count
  2329. pList->cAdrs++;
  2330. }
  2331. exit:
  2332. // Failure
  2333. if (FAILED(hr))
  2334. g_cMoleAlloc.FreeAddressList(pList);
  2335. // Cleanup
  2336. MimeOleVariantFree(&rDecoded);
  2337. // Done
  2338. return hr;
  2339. }
  2340. // ----------------------------------------------------------------------------
  2341. // CMimePropertyContainer::Clone
  2342. // ----------------------------------------------------------------------------
  2343. STDMETHODIMP CMimePropertyContainer::Clone(IMimeAddressTable **ppTable)
  2344. {
  2345. // Locals
  2346. HRESULT hr=S_OK;
  2347. LPCONTAINER pContainer=NULL;
  2348. // InvalidArg
  2349. if (NULL == ppTable)
  2350. return TrapError(E_INVALIDARG);
  2351. // Init
  2352. *ppTable = NULL;
  2353. // Thread Safety
  2354. EnterCriticalSection(&m_cs);
  2355. // Ask the container to clone itself
  2356. CHECKHR(hr = Clone(&pContainer));
  2357. // Bind to the IID_IMimeHeaderTable View
  2358. CHECKHR(hr = pContainer->QueryInterface(IID_IMimeAddressTable, (LPVOID *)ppTable));
  2359. exit:
  2360. // Cleanup
  2361. SafeRelease(pContainer);
  2362. // Thread Safety
  2363. LeaveCriticalSection(&m_cs);
  2364. // Done
  2365. return hr;
  2366. }
  2367. // --------------------------------------------------------------------------------
  2368. // CMimePropertyContainer::HrGenerateFileName
  2369. // --------------------------------------------------------------------------------
  2370. HRESULT CMimePropertyContainer::_HrGenerateFileName(DWORD dwFlags, LPMIMEVARIANT pValue)
  2371. {
  2372. // Locals
  2373. HRESULT hr=S_OK;
  2374. LPSTR pszDefExt=NULL,
  2375. pszData=NULL,
  2376. pszFree=NULL,
  2377. pszSuggest=NULL;
  2378. LPCSTR pszCntType=NULL;
  2379. LPPROPERTY pProperty;
  2380. MIMEVARIANT rSource;
  2381. // Compute Content Type
  2382. pszCntType = PSZDEFPROPSTRINGA(m_prgIndex[PID_HDR_CNTTYPE], STR_MIME_TEXT_PLAIN);
  2383. // Compute Subject as suggested base file name...
  2384. rSource.type = MVT_STRINGA;
  2385. if (SUCCEEDED(GetProp(SYM_HDR_SUBJECT, 0, &rSource)))
  2386. pszSuggest = pszFree = rSource.rStringA.pszVal;
  2387. // PID_HDR_CNTDESC
  2388. if (NULL == pszSuggest)
  2389. {
  2390. // Use PID_CNTDESC
  2391. pszSuggest = PSZDEFPROPSTRINGA(m_prgIndex[PID_HDR_CNTDESC], NULL);
  2392. }
  2393. // message/rfc822
  2394. if (lstrcmpi(pszCntType, (LPSTR)STR_MIME_MSG_RFC822) == 0)
  2395. {
  2396. // If there is a news header, use c_szDotNws
  2397. if (ISFLAGSET(m_dwState, COSTATE_RFC822NEWS))
  2398. pszDefExt = (LPSTR)c_szDotNws;
  2399. else
  2400. pszDefExt = (LPSTR)c_szDotEml;
  2401. // I will never lookup message/rfc822 extension
  2402. pszCntType = NULL;
  2403. }
  2404. // Still no default
  2405. else if (StrCmpNI(pszCntType, STR_CNT_TEXT, lstrlen(STR_CNT_TEXT)) == 0)
  2406. pszDefExt = (LPSTR)c_szDotTxt;
  2407. // Generate a filename based on the content type...
  2408. CHECKHR(hr = MimeOleGenerateFileName(pszCntType, pszSuggest, pszDefExt, &pszData));
  2409. // Setup rSource
  2410. ZeroMemory(&rSource, sizeof(MIMEVARIANT));
  2411. rSource.type = MVT_STRINGA;
  2412. rSource.rStringA.pszVal = pszData;
  2413. rSource.rStringA.cchVal = lstrlen(pszData);
  2414. // Return per user request
  2415. CHECKHR(hr = HrConvertVariant(SYM_ATT_GENFNAME, NULL, IET_DECODED, dwFlags, 0, &rSource, pValue));
  2416. exit:
  2417. // Cleanup
  2418. SafeMemFree(pszData);
  2419. SafeMemFree(pszFree);
  2420. // Done
  2421. return hr;
  2422. }