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

322 lines
7.6 KiB

  1. #include "faxrtp.h"
  2. #pragma hdrstop
  3. LPVOID InboundProfileInfo;
  4. BOOL
  5. InitializeEmailRouting(
  6. VOID
  7. )
  8. {
  9. PLIST_ENTRY Next;
  10. PROUTING_TABLE RoutingEntry;
  11. //
  12. // initialize the profiles
  13. //
  14. EnterCriticalSection( &CsRouting );
  15. if (InboundProfileName && InboundProfileName[0]) {
  16. InboundProfileInfo = AddNewMapiProfile( InboundProfileName, TRUE, TRUE );
  17. if (!InboundProfileInfo) {
  18. DebugPrint(( TEXT("Could not initialize inbound mapi profile [%s]"), InboundProfileName ));
  19. }
  20. }
  21. Next = RoutingListHead.Flink;
  22. if (Next) {
  23. while (Next != &RoutingListHead) {
  24. RoutingEntry = CONTAINING_RECORD( Next, ROUTING_TABLE, ListEntry );
  25. Next = RoutingEntry->ListEntry.Flink;
  26. if (RoutingEntry->ProfileName && RoutingEntry->ProfileName[0]) {
  27. RoutingEntry->ProfileInfo = AddNewMapiProfile( RoutingEntry->ProfileName, FALSE, TRUE );
  28. }
  29. }
  30. }
  31. LeaveCriticalSection( &CsRouting );
  32. return TRUE;
  33. }
  34. BOOL
  35. TiffMailDefault(
  36. const FAX_ROUTE *FaxRoute,
  37. PROUTING_TABLE RoutingEntry,
  38. LPCWSTR TiffFileName
  39. )
  40. /*++
  41. Routine Description:
  42. Mails a TIFF file to the inbox in the specified profile.
  43. Arguments:
  44. TiffFileName - Name of TIFF file to mail
  45. ProfileName - Profile name to use
  46. ResultCode - The result of the failed API call
  47. Return Value:
  48. TRUE for success, FALSE on error
  49. --*/
  50. {
  51. LPCTSTR BodyStr = NULL;
  52. BOOL Rslt = FALSE;
  53. DWORD MsgCount;
  54. LPDWORD MsgPtr[6];
  55. TCHAR MsgStr[2048];
  56. TCHAR PageCountStr[64];
  57. LPCTSTR SenderStr = NULL;
  58. LPCTSTR SubjectStr = NULL;
  59. LPCTSTR RecipStr = NULL;
  60. TCHAR TimeStr[128];
  61. ULONG ResultCode;
  62. if (!RoutingEntry->ProfileInfo) {
  63. ResultCode = ERROR_NO_SUCH_LOGON_SESSION;
  64. return FALSE;
  65. }
  66. ResultCode = ERROR_SUCCESS;
  67. FormatElapsedTimeStr(
  68. (FILETIME*)&FaxRoute->ElapsedTime,
  69. TimeStr,
  70. sizeof(TimeStr)
  71. );
  72. _ltot( (LONG) FaxRoute->PageCount, PageCountStr, 10 );
  73. if (!FaxRoute->RoutingInfo || !FaxRoute->RoutingInfo[0]) {
  74. RecipStr = FaxRoute->Csid ? FaxRoute->Csid : TEXT("");
  75. } else {
  76. RecipStr = FaxRoute->RoutingInfo;
  77. }
  78. MsgPtr[0] = (LPDWORD) FaxRoute->Tsid;
  79. MsgPtr[1] = (LPDWORD) FaxRoute->CallerId;
  80. MsgPtr[2] = (LPDWORD) RecipStr;
  81. MsgPtr[3] = (LPDWORD) PageCountStr;
  82. MsgPtr[4] = (LPDWORD) TimeStr;
  83. MsgPtr[5] = (LPDWORD) FaxRoute->DeviceName;
  84. MsgCount = FormatMessage(
  85. FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  86. MyhInstance,
  87. MSG_MAIL_MSG_BODY,
  88. MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT),
  89. MsgStr,
  90. sizeof(MsgStr),
  91. (va_list *) MsgPtr
  92. );
  93. if (MsgCount) {
  94. BodyStr = StringDup( MsgStr );
  95. } else {
  96. BodyStr = StringDup( TEXT("") );
  97. }
  98. if (FaxRoute->Tsid != NULL && FaxRoute->Tsid[0] != 0) {
  99. SenderStr = StringDup( FaxRoute->Tsid );
  100. } else {
  101. MsgCount = FormatMessage(
  102. FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  103. MyhInstance,
  104. MSG_WHO_AM_I,
  105. MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT),
  106. MsgStr,
  107. sizeof(MsgStr),
  108. NULL
  109. );
  110. if (MsgCount) {
  111. SenderStr = StringDup( MsgStr );
  112. } else {
  113. SenderStr = StringDup( TEXT("") );
  114. }
  115. }
  116. MsgCount = FormatMessage(
  117. FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  118. MyhInstance,
  119. MSG_SUBJECT_LINE,
  120. MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT),
  121. MsgStr,
  122. sizeof(MsgStr),
  123. NULL
  124. );
  125. if (MsgCount) {
  126. SubjectStr = StringDup( MsgStr );
  127. } else {
  128. SubjectStr = StringDup( TEXT("") );
  129. }
  130. Rslt = StoreMapiMessage(
  131. RoutingEntry->ProfileInfo,
  132. SenderStr,
  133. SubjectStr,
  134. BodyStr,
  135. TiffFileName,
  136. NULL,
  137. IMPORTANCE_NORMAL,
  138. NULL,
  139. &ResultCode
  140. );
  141. MemFree( (LPBYTE) BodyStr );
  142. MemFree( (LPBYTE) SubjectStr );
  143. MemFree( (LPBYTE) SenderStr );
  144. return Rslt;
  145. }
  146. BOOL
  147. TiffRouteEMail(
  148. const FAX_ROUTE *FaxRoute,
  149. PROUTING_TABLE RoutingEntry,
  150. LPCWSTR TiffFileName
  151. )
  152. /*++
  153. Routine Description:
  154. Mails a TIFF file to the inbox in the specified profile.
  155. Arguments:
  156. TiffFileName - Name of TIFF file to mail
  157. ProfileName - Profile name to use
  158. ResultCode - The result of the failed API call
  159. Return Value:
  160. TRUE for success, FALSE on error
  161. --*/
  162. {
  163. LPCWSTR BodyStr = NULL;
  164. BOOL Failed = FALSE;
  165. DWORD MsgCount;
  166. LPDWORD MsgPtr[6];
  167. WCHAR MsgStr[2048];
  168. WCHAR PageCountStr[64];
  169. LPCWSTR SenderStr = NULL;
  170. LPCWSTR SubjectStr = NULL;
  171. WCHAR TimeStr[128];
  172. LPCWSTR RecipientName = NULL;
  173. LPWSTR ProxyAddress = NULL;
  174. ULONG ResultCode;
  175. if (!InboundProfileInfo) {
  176. ResultCode = ERROR_NO_SUCH_LOGON_SESSION;
  177. return FALSE;
  178. }
  179. if (FaxRoute->RoutingInfo && FaxRoute->RoutingInfo[0]) {
  180. RecipientName = FaxRoute->RoutingInfo;
  181. } else if (FaxRoute->Csid && FaxRoute->Csid[0]) {
  182. RecipientName = FaxRoute->Csid;
  183. }
  184. if (!RecipientName) {
  185. return FALSE;
  186. }
  187. ProxyAddress = (LPTSTR) MemAlloc( StringSize( RecipientName ) + 32 );
  188. if (!ProxyAddress) {
  189. return FALSE;
  190. }
  191. _stprintf( ProxyAddress, TEXT("FAX:FAX[%s]"), RecipientName );
  192. ResultCode = ERROR_SUCCESS;
  193. FormatElapsedTimeStr(
  194. (FILETIME*)&FaxRoute->ElapsedTime,
  195. TimeStr,
  196. sizeof(TimeStr)
  197. );
  198. _ltot( (LONG) FaxRoute->PageCount, PageCountStr, 10 );
  199. MsgPtr[0] = (LPDWORD) FaxRoute->Tsid;
  200. MsgPtr[1] = (LPDWORD) FaxRoute->CallerId;
  201. MsgPtr[2] = (LPDWORD) RecipientName;
  202. MsgPtr[3] = (LPDWORD) PageCountStr;
  203. MsgPtr[4] = (LPDWORD) TimeStr;
  204. MsgPtr[5] = (LPDWORD) FaxRoute->DeviceName;
  205. MsgCount = FormatMessage(
  206. FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  207. NULL,
  208. MSG_MAIL_MSG_BODY,
  209. MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT),
  210. MsgStr,
  211. sizeof(MsgStr),
  212. (va_list *) MsgPtr
  213. );
  214. BodyStr = StringDup( MsgStr );
  215. if (FaxRoute->Tsid != NULL && FaxRoute->Tsid[0] != 0) {
  216. SenderStr = StringDup( FaxRoute->Tsid );
  217. } else {
  218. MsgCount = FormatMessage(
  219. FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  220. NULL,
  221. MSG_WHO_AM_I,
  222. MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT),
  223. MsgStr,
  224. sizeof(MsgStr),
  225. NULL
  226. );
  227. if (MsgCount != 0) {
  228. SenderStr = StringDup(MsgStr);
  229. }
  230. }
  231. MsgCount = FormatMessage(
  232. FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  233. NULL,
  234. MSG_SUBJECT_LINE,
  235. MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT),
  236. MsgStr,
  237. sizeof(MsgStr),
  238. NULL
  239. );
  240. if (MsgCount != 0) {
  241. SubjectStr = StringDup( MsgStr );
  242. }
  243. Failed = MailMapiMessage(
  244. InboundProfileInfo,
  245. ProxyAddress,
  246. SubjectStr,
  247. BodyStr,
  248. TiffFileName,
  249. NULL,
  250. IMPORTANCE_NORMAL,
  251. &ResultCode
  252. );
  253. MemFree( (LPBYTE) BodyStr );
  254. MemFree( (LPBYTE) SubjectStr );
  255. MemFree( (LPBYTE) SenderStr );
  256. MemFree( (LPBYTE) ProxyAddress );
  257. return Failed;
  258. }