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.

244 lines
7.2 KiB

  1. #include "precomp.h"
  2. static BOOL importLDAPBitmapHelper(LPCTSTR pcszIns, LPCTSTR pcszWorkDir, BOOL fImport);
  3. static BOOL importOEInfoHelper(LPCTSTR pcszIns, LPCTSTR pcszWorkDir, BOOL fImport);
  4. static BOOL encodeSignatureHelper(LPCTSTR pcszFrom, LPTSTR pszTo, BOOL fEncode);
  5. static void decodeSig(LPCTSTR pcszFrom, LPTSTR pszTo);
  6. static void encodeSig(LPCTSTR pcszFrom, LPTSTR pszTo);
  7. BOOL WINAPI ImportLDAPBitmapA(LPCSTR pcszIns, LPCSTR pcszWorkDir, BOOL fImport)
  8. {
  9. USES_CONVERSION;
  10. return importLDAPBitmapHelper(A2CT(pcszIns), A2CT(pcszWorkDir), fImport);
  11. }
  12. BOOL WINAPI ImportLDAPBitmapW(LPCWSTR pcwszIns, LPCWSTR pcwszWorkDir, BOOL fImport)
  13. {
  14. USES_CONVERSION;
  15. return importLDAPBitmapHelper(W2CT(pcwszIns), W2CT(pcwszWorkDir), fImport);
  16. }
  17. BOOL WINAPI ImportOEInfoA(LPCSTR pcszIns, LPCSTR pcszWorkDir, BOOL fImport)
  18. {
  19. USES_CONVERSION;
  20. return importOEInfoHelper(A2CT(pcszIns), A2CT(pcszWorkDir), fImport);
  21. }
  22. BOOL WINAPI ImportOEInfoW(LPCWSTR pcwszIns, LPCWSTR pcwszWorkDir, BOOL fImport)
  23. {
  24. USES_CONVERSION;
  25. return importOEInfoHelper(W2CT(pcwszIns), W2CT(pcwszWorkDir), fImport);
  26. }
  27. BOOL WINAPI EncodeSignatureA(LPCSTR pcszFrom, LPSTR pszTo, BOOL fEncode)
  28. {
  29. LPTSTR pszBuf = (LPTSTR)LocalAlloc(LPTR, 1024 * sizeof(TCHAR));
  30. BOOL fRet = FALSE;
  31. USES_CONVERSION;
  32. if (pszBuf != NULL)
  33. {
  34. fRet = encodeSignatureHelper(A2CT(pcszFrom), pszBuf, fEncode);
  35. T2Abux(pszBuf, pszTo);
  36. }
  37. return fRet;
  38. }
  39. BOOL WINAPI EncodeSignatureW(LPCWSTR pcwszFrom, LPWSTR pwszTo, BOOL fEncode)
  40. {
  41. LPTSTR pszBuf = (LPTSTR)LocalAlloc(LPTR, 1024 * sizeof(TCHAR));
  42. BOOL fRet = FALSE;
  43. USES_CONVERSION;
  44. if (pszBuf != NULL)
  45. {
  46. fRet = encodeSignatureHelper(W2CT(pcwszFrom), pszBuf, fEncode);
  47. T2Wbux(pszBuf, pwszTo);
  48. }
  49. LocalFree(pszBuf); //bug 14001, forgot to free temp buffer
  50. return fRet;
  51. }
  52. static BOOL importLDAPBitmapHelper(LPCTSTR pcszIns, LPCTSTR pcszWorkDir, BOOL fImport)
  53. {
  54. TCHAR szLDAPBitmap[MAX_PATH];
  55. BOOL fSuccess = TRUE;
  56. if (pcszIns == NULL || pcszWorkDir == NULL)
  57. return FALSE;
  58. if (fImport)
  59. PathRemovePath(pcszWorkDir);
  60. GetPrivateProfileString(IS_LDAP, IK_BITMAP, TEXT(""), szLDAPBitmap, countof(szLDAPBitmap), pcszIns);
  61. if (szLDAPBitmap[0] != TEXT('\0')) {
  62. if (fImport) {
  63. ASSERT(PathFileExists(szLDAPBitmap));
  64. fSuccess = CopyFileToDir(szLDAPBitmap, pcszWorkDir);
  65. }
  66. else {
  67. DeleteFileInDir(szLDAPBitmap, pcszWorkDir);
  68. WritePrivateProfileString(IS_LDAP, IK_BITMAP, NULL, pcszIns);
  69. }
  70. }
  71. return fSuccess;
  72. }
  73. static BOOL importOEInfoHelper(LPCTSTR pcszIns, LPCTSTR pcszWorkDir, BOOL fImport)
  74. {
  75. TCHAR szInfopane[INTERNET_MAX_URL_LENGTH],
  76. szInfopaneBmp[MAX_PATH],
  77. szHTMLPath[MAX_PATH];
  78. BOOL fSuccess;
  79. if (pcszIns == NULL || pcszWorkDir == NULL)
  80. return FALSE;
  81. if (fImport)
  82. PathRemovePath(pcszWorkDir);
  83. fSuccess = TRUE;
  84. GetPrivateProfileString(IS_INTERNETMAIL, IK_INFOPANE, TEXT(""), szInfopane, countof(szInfopane), pcszIns);
  85. if (szInfopane[0] != TEXT('\0') && !PathIsURL(szInfopane)) {
  86. if (fImport) {
  87. ASSERT(PathFileExists(szInfopane));
  88. if (CopyFileToDir(szInfopane, pcszWorkDir))
  89. CopyHtmlImgs(szInfopane, pcszWorkDir, NULL, NULL);
  90. else
  91. fSuccess = FALSE;
  92. }
  93. else {
  94. TCHAR szTemp[MAX_PATH];
  95. PathCombine(szTemp, pcszWorkDir, PathFindFileName(szInfopane));
  96. if (PathFileExists(szTemp)) {
  97. DeleteHtmlImgs(szTemp, pcszWorkDir, NULL, NULL);
  98. DeleteFileInDir(szTemp, pcszWorkDir);
  99. }
  100. }
  101. }
  102. GetPrivateProfileString(IS_INTERNETMAIL, IK_INFOPANEBMP, TEXT(""), szInfopaneBmp, countof(szInfopaneBmp), pcszIns);
  103. if (szInfopaneBmp[0] != TEXT('\0')) {
  104. if (fImport) {
  105. ASSERT(PathFileExists(szInfopaneBmp));
  106. fSuccess = CopyFileToDir(szInfopaneBmp, pcszWorkDir) && fSuccess;
  107. }
  108. else
  109. DeleteFileInDir(szInfopaneBmp, pcszWorkDir);
  110. }
  111. GetPrivateProfileString(IS_INTERNETMAIL, IK_WELCOMEMESSAGE, TEXT(""), szHTMLPath, countof(szHTMLPath), pcszIns);
  112. if (szHTMLPath[0] != TEXT('\0')) {
  113. if (fImport) {
  114. ASSERT(PathFileExists(szHTMLPath));
  115. if (CopyFileToDir(szHTMLPath, pcszWorkDir))
  116. CopyHtmlImgs(szHTMLPath, pcszWorkDir, NULL, NULL);
  117. else
  118. fSuccess = FALSE;
  119. }
  120. else {
  121. TCHAR szTemp[MAX_PATH];
  122. PathCombine(szTemp, pcszWorkDir, PathFindFileName(szHTMLPath));
  123. if (PathFileExists(szTemp)) {
  124. DeleteHtmlImgs(szTemp, pcszWorkDir, NULL, NULL);
  125. DeleteFileInDir(szTemp, pcszWorkDir);
  126. }
  127. }
  128. }
  129. if (!fImport) {
  130. WritePrivateProfileString(IS_INTERNETMAIL, IK_INFOPANE, NULL, pcszIns);
  131. WritePrivateProfileString(IS_INTERNETMAIL, IK_INFOPANEBMP, NULL, pcszIns);
  132. WritePrivateProfileString(IS_INTERNETMAIL, IK_WELCOMEMESSAGE, NULL, pcszIns);
  133. }
  134. return fSuccess;
  135. }
  136. static BOOL encodeSignatureHelper(LPCTSTR pcszFrom, LPTSTR pszTo, BOOL fEncode)
  137. {
  138. if (fEncode)
  139. encodeSig(pcszFrom, pszTo);
  140. else
  141. decodeSig(pcszFrom, pszTo);
  142. return TRUE;
  143. }
  144. static void decodeSig(LPCTSTR pszFrom, LPTSTR pszTo)
  145. {
  146. if (pszFrom == NULL || pszTo == NULL)
  147. return;
  148. while (*pszFrom != TEXT('\0'))
  149. #ifndef UNICODE
  150. if (IsDBCSLeadByte(*pszFrom)) {
  151. *pszTo++ = *pszFrom++;
  152. *pszTo++ = *pszFrom++;
  153. }
  154. else
  155. #endif
  156. if (*pszFrom != TEXT('\\'))
  157. *(pszTo++) = *(pszFrom++);
  158. else {
  159. pszFrom++;
  160. if (*pszFrom == TEXT('n')) {
  161. *pszTo++ = (TCHAR)0x0D;
  162. *pszTo++ = (TCHAR)0x0A;
  163. pszFrom++;
  164. }
  165. else
  166. if (*pszFrom == TEXT('\\')) {
  167. *pszTo++ = TEXT('\\');
  168. pszFrom++;
  169. }
  170. else
  171. *pszTo++ = *pszFrom++;
  172. }
  173. *pszTo = TEXT('\0');
  174. }
  175. static void encodeSig(LPCTSTR pszFrom, LPTSTR pszTo)
  176. {
  177. if (pszFrom == NULL || pszTo == NULL)
  178. return;
  179. while (*pszFrom != TEXT('\0'))
  180. #ifndef UNICODE
  181. if (IsDBCSLeadByte(*pszFrom)) {
  182. *pszTo++ = *pszFrom++;
  183. *pszTo++ = *pszFrom++;
  184. }
  185. else
  186. #endif
  187. if ((*pszFrom == TEXT('\r')) || (*pszFrom == TEXT('\n'))) {
  188. *pszTo++ = TEXT('\\');
  189. *pszTo++ = TEXT('n');
  190. pszFrom++;
  191. if ((*pszFrom == TEXT('\r')) || (*pszFrom == TEXT('\n')))
  192. pszFrom++;
  193. }
  194. else {
  195. if (*pszFrom == TEXT('\\'))
  196. *pszTo++ = TEXT('\\');
  197. *pszTo++ = *pszFrom++;
  198. }
  199. *pszTo = TEXT('\0');
  200. }