@@ -20,7 +20,9 @@ import Foreign ( FunPtr, newForeignPtr, pokeByteOff, maybeWith
20
20
, Ptr , castPtr , castPtrToFunPtr , nullPtr
21
21
, touchForeignPtr , alloca , peek , allocaBytes
22
22
, minusPtr , plusPtr , copyBytes , ForeignPtr )
23
- import Foreign.C ( withCString , withCStringLen )
23
+ import Foreign.C ( withCAString , withCAStringLen )
24
+ -- Apparently, simple MAPI does not support unicode and probably never will,
25
+ -- so this module will just mangle any Unicode in your strings
24
26
import Graphics.Win32.GDI.Types ( HWND )
25
27
import System.Win32.DLL ( loadLibrary , c_GetProcAddress , freeLibrary
26
28
, c_FreeLibraryFinaliser )
@@ -141,7 +143,7 @@ loadMapiFuncs dllname dll = liftM5 MapiFuncs
141
143
(loadProc " MAPISendMail" dll mkMapiSendMail)
142
144
where
143
145
loadProc :: String -> HMODULE -> (FunPtr a -> a ) -> IO a
144
- loadProc name dll conv = withCString name $ \ name' -> do
146
+ loadProc name dll conv = withCAString name $ \ name' -> do
145
147
proc <- failIfNull (" loadMapiDll: " ++ dllname ++ " : " ++ name)
146
148
$ c_GetProcAddress dll name'
147
149
return $ conv $ castPtrToFunPtr proc
@@ -190,8 +192,8 @@ mapiLogon
190
192
-> MapiFlag -- ^ None, one or many flags: FORCE_DOWNLOAD, NEW_SESSION, LOGON_UI, PASSWORD_UI
191
193
-> IO LHANDLE
192
194
mapiLogon f hwnd ses pw flags =
193
- maybeWith withCString ses $ \ ses ->
194
- maybeWith withCString pw $ \ pw ->
195
+ maybeWith withCAString ses $ \ ses ->
196
+ maybeWith withCAString pw $ \ pw ->
195
197
alloca $ \ out -> do
196
198
mapiFail_ " MAPILogon: " $ mapifLogon
197
199
f (maybeHWND hwnd)
@@ -242,8 +244,8 @@ withRecipient f ses rcls rec act = resolve "" rec
242
244
act buf
243
245
resolve err rc = case rc of
244
246
Recip name addr ->
245
- withCString name $ \ name ->
246
- withCString addr $ \ addr ->
247
+ withCAString name $ \ name ->
248
+ withCAString addr $ \ addr ->
247
249
allocaBytes (# size MapiRecipDesc ) $ \ buf -> do
248
250
(# poke MapiRecipDesc , ulReserved) buf (0 :: ULONG )
249
251
(# poke MapiRecipDesc , lpszName) buf name
@@ -253,7 +255,7 @@ withRecipient f ses rcls rec act = resolve "" rec
253
255
a buf
254
256
RecipResolve hwnd flag name fallback -> do
255
257
res <- alloca $ \ res ->
256
- withCString name $ \ name' -> do
258
+ withCAString name $ \ name' -> do
257
259
errn <- mapifResolveName
258
260
f ses (maybeHWND hwnd) name' flag 0 res
259
261
if errn== (# const SUCCESS_SUCCESS )
@@ -310,7 +312,7 @@ withFileTag ft act =
310
312
where
311
313
w v a = case v of
312
314
Nothing -> a (nullPtr, 0 )
313
- Just x -> withCStringLen x a
315
+ Just x -> withCAStringLen x a
314
316
315
317
data Attachment = Attachment
316
318
{ attFlag :: MapiFlag
@@ -330,9 +332,9 @@ withAttachments att act = allocaBytes (len*as) $ \buf -> write (act len buf) buf
330
332
len = length att
331
333
write act _ [] = act
332
334
write act buf (att: y) =
333
- withCString (attPath att) $ \ path ->
335
+ withCAString (attPath att) $ \ path ->
334
336
maybeWith withFileTag (attTag att) $ \ tag ->
335
- withCString (maybe (attPath att) id (attName att)) $ \ name -> do
337
+ withCAString (maybe (attPath att) id (attName att)) $ \ name -> do
336
338
(# poke MapiFileDesc , ulReserved) buf (0 :: ULONG )
337
339
(# poke MapiFileDesc , flFlags) buf (attFlag att)
338
340
(# poke MapiFileDesc , nPosition) buf (maybe 0xffffffff id $ attPosition att)
@@ -363,11 +365,11 @@ withMessage
363
365
-> (Ptr Message -> IO a )
364
366
-> IO a
365
367
withMessage f ses m act =
366
- withCString (msgSubject m) $ \ subject ->
367
- withCString (msgBody m) $ \ body ->
368
- maybeWith withCString (msgType m) $ \ message_type ->
369
- maybeWith withCString (msgDate m) $ \ date ->
370
- maybeWith withCString (msgConversationId m) $ \ conv_id ->
368
+ withCAString (msgSubject m) $ \ subject ->
369
+ withCAString (msgBody m) $ \ body ->
370
+ maybeWith withCAString (msgType m) $ \ message_type ->
371
+ maybeWith withCAString (msgDate m) $ \ date ->
372
+ maybeWith withCAString (msgConversationId m) $ \ conv_id ->
371
373
withRecipients f ses (msgRecips m) $ \ rlen rbuf ->
372
374
withAttachments (msgAttachments m) $ \ alen abuf ->
373
375
maybeWith (withRecipient f ses RcOriginal ) (msgFrom m) $ \ from ->
0 commit comments