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.

243 lines
7.1 KiB

  1. /*++
  2. Copyright (c) 2000-2001 Microsoft Corporation
  3. Module Name:
  4. assign.cpp
  5. Abstract:
  6. WinDbg Extension Api
  7. Environment:
  8. User Mode.
  9. Revision History:
  10. Andre Vachon (andreva)
  11. bugcheck analyzer.
  12. --*/
  13. #include "precomp.h"
  14. #include "mapistuff.h"
  15. ULONG (FAR PASCAL *lpfnMAPILogon)(ULONG_PTR, LPSTR, LPSTR, FLAGS, ULONG, LPLHANDLE);
  16. ULONG (PASCAL *lpfnMAPISendMail)(LHANDLE, ULONG_PTR, MapiMessage*, FLAGS, ULONG);
  17. ULONG (PASCAL *lpfnMAPIResolveName)(LHANDLE, ULONG_PTR, LPTSTR, FLAGS, ULONG, MapiRecipDesc **);
  18. ULONG (FAR PASCAL *lpfnMAPILogoff)(LHANDLE, ULONG_PTR, FLAGS, ULONG);
  19. ULONG (FAR PASCAL *lpfnMAPIFreeBuffer)(LPVOID);
  20. HINSTANCE hInstMapi = NULL;
  21. BOOL SendOffFailure(
  22. TCHAR *pszToList,
  23. TCHAR *pszTitle,
  24. TCHAR *pszMessage)
  25. {
  26. LHANDLE lhSession;
  27. ULONG lResult = 0;
  28. MapiMessage mmmessage;
  29. lpMapiRecipDesc rdList = NULL;
  30. DWORD i = 0;
  31. memset(&mmmessage, 0, sizeof(mmmessage));
  32. hInstMapi = LoadLibrary("Mapi32.dll");
  33. if(hInstMapi == NULL)
  34. {
  35. dprintf("Unable to Load MAPI32.dll!!!\n");
  36. return FALSE;
  37. }
  38. //
  39. // Find the addresses of functions
  40. //
  41. (FARPROC)lpfnMAPILogon = GetProcAddress(hInstMapi, "MAPILogon");
  42. (FARPROC)lpfnMAPILogoff = GetProcAddress(hInstMapi, "MAPILogoff");
  43. (FARPROC)lpfnMAPIFreeBuffer = GetProcAddress(hInstMapi, "MAPIFreeBuffer");
  44. (FARPROC)lpfnMAPIResolveName = GetProcAddress(hInstMapi, "MAPIResolveName");
  45. (FARPROC)lpfnMAPISendMail = GetProcAddress(hInstMapi, "MAPISendMail");
  46. if ((lpfnMAPILogon == NULL) ||
  47. (lpfnMAPILogoff == NULL) ||
  48. (lpfnMAPIFreeBuffer == NULL) ||
  49. (lpfnMAPIResolveName == NULL) ||
  50. (lpfnMAPISendMail == NULL))
  51. {
  52. dprintf("Unable to Load MAPI32 entry points!!!\n");
  53. FreeLibrary(hInstMapi);
  54. return FALSE;
  55. }
  56. // Log on to existing session
  57. lResult = lpfnMAPILogon(0, NULL, NULL, 0, 0, &lhSession);
  58. if (lResult != SUCCESS_SUCCESS)
  59. {
  60. // We need outlook up and running to send mail
  61. // Maybe I write the code to do the connect when I get some time
  62. dprintf("Unable to Logon to an existing MAPI session. Make sure you have Outlook started!!!\n");
  63. }
  64. else
  65. {
  66. mmmessage.ulReserved = 0;
  67. mmmessage.lpszMessageType = NULL;
  68. mmmessage.lpszSubject = pszTitle;
  69. mmmessage.lpszNoteText = pszMessage;
  70. mmmessage.lpRecips = NULL;
  71. mmmessage.flFlags = MAPI_SENT;
  72. mmmessage.lpOriginator = NULL;
  73. mmmessage.nFileCount = 0;
  74. mmmessage.nRecipCount = CountRecips(pszToList);
  75. if (mmmessage.nRecipCount == 0)
  76. {
  77. dprintf("No receipients in string %s\n", pszToList);
  78. }
  79. else
  80. {
  81. TCHAR *token = NULL;
  82. DWORD index = 0;
  83. rdList = (lpMapiRecipDesc) calloc(mmmessage.nRecipCount, sizeof (MapiRecipDesc));
  84. if (rdList)
  85. {
  86. token = _tcstok(pszToList, _T(";"));
  87. while( token != NULL )
  88. {
  89. lResult = lpfnMAPIResolveName(lhSession,
  90. 0,
  91. token,
  92. 0,
  93. 0,
  94. &mmmessage.lpRecips);
  95. if (lResult != SUCCESS_SUCCESS)
  96. {
  97. dprintf("Unable to resolve %s properly! Failing Send\n", token);
  98. break;
  99. }
  100. else
  101. {
  102. if (mmmessage.lpRecips->lpEntryID)
  103. {
  104. rdList[index].lpEntryID = malloc(mmmessage.lpRecips->ulEIDSize);
  105. }
  106. if (mmmessage.lpRecips->lpszAddress)
  107. {
  108. rdList[index].lpszAddress = _tcsdup(mmmessage.lpRecips->lpszAddress);
  109. }
  110. if (mmmessage.lpRecips->lpszName)
  111. {
  112. rdList[index].lpszName = _tcsdup(mmmessage.lpRecips->lpszName);
  113. }
  114. memcpy(rdList[index].lpEntryID, mmmessage.lpRecips->lpEntryID, mmmessage.lpRecips->ulEIDSize);
  115. rdList[index].ulEIDSize = mmmessage.lpRecips->ulEIDSize;
  116. rdList[index].ulRecipClass = MAPI_TO;
  117. rdList[index].ulReserved = mmmessage.lpRecips->ulReserved;
  118. lpfnMAPIFreeBuffer(mmmessage.lpRecips);
  119. }
  120. index++;
  121. token = _tcstok(NULL, _T(";"));
  122. }
  123. if (token == NULL)
  124. {
  125. // Send the message
  126. mmmessage.lpRecips = rdList;
  127. lResult = lpfnMAPISendMail(lhSession, 0, &mmmessage, 0, 0);
  128. }
  129. // free up allocated memory.
  130. for (i = 0; i < mmmessage.nRecipCount; i++)
  131. {
  132. if (rdList[i].lpEntryID)
  133. free(rdList[i].lpEntryID);
  134. if (rdList[i].lpszAddress)
  135. free(rdList[i].lpszAddress);
  136. if (rdList[i].lpszName)
  137. free(rdList[i].lpszName);
  138. }
  139. free(rdList);
  140. }
  141. }
  142. lpfnMAPILogoff(lhSession, 0, 0, 0);
  143. lpfnMAPILogoff(0, lhSession, 0, 0);
  144. }
  145. FreeLibrary(hInstMapi);
  146. if (lResult != SUCCESS_SUCCESS)
  147. {
  148. dprintf("SendMail to %s failed\n", pszToList);
  149. return FALSE;
  150. }
  151. else
  152. {
  153. dprintf("SendMail to %s succeeded\n", pszToList);
  154. return TRUE;
  155. }
  156. }
  157. DWORD CountRecips(PTCHAR pszToList)
  158. {
  159. DWORD i = 0;
  160. PTCHAR ptr = pszToList;
  161. if ((!ptr)||(ptr[0] == TEXT('\0')))
  162. {
  163. return 0;
  164. }
  165. ptr = pszToList + _tcslen(pszToList) - 1;
  166. // rear trim
  167. while ((ptr >= pszToList) &&
  168. ((ptr[0] == TEXT(';')) ||
  169. (ptr[0] == TEXT(' ')) ||
  170. (ptr[0] == TEXT('/r')) ||
  171. (ptr[0] == TEXT('/n')) ||
  172. (ptr[0] == TEXT('/t')) ||
  173. (ptr[0] == TEXT(':'))))
  174. {
  175. ptr[0] = TEXT('\0');
  176. ptr--;
  177. }
  178. ptr = pszToList;
  179. // front trim
  180. while ((ptr[0] == TEXT(';')) ||
  181. (ptr[0] == TEXT(' ')) ||
  182. (ptr[0] == TEXT('/r')) ||
  183. (ptr[0] == TEXT('/n')) ||
  184. (ptr[0] == TEXT('/t')) ||
  185. (ptr[0] == TEXT(':')))
  186. {
  187. _tcscpy(ptr, ptr + 1);
  188. }
  189. // remove spaces
  190. while (ptr = _tcschr(pszToList, TEXT(' ')))
  191. {
  192. _tcscpy(ptr, ptr + 1);
  193. }
  194. ptr = pszToList;
  195. while (ptr = _tcschr(ptr, TEXT(';')))
  196. {
  197. i++;
  198. ptr++;
  199. }
  200. if (!_tcslen(pszToList))
  201. {
  202. return 0;
  203. }
  204. return i + 1;
  205. }