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.

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