1 /* 2 * IMAP Transport 3 * 4 * Copyright 2008 Hans Leidekker for CodeWeavers 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 19 */ 20 21 #include "inetcomm_private.h" 22 23 typedef struct 24 { 25 InternetTransport InetTransport; 26 ULONG refs; 27 } IMAPTransport; 28 29 static HRESULT WINAPI IMAPTransport_QueryInterface(IIMAPTransport *iface, REFIID riid, void **ppv) 30 { 31 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv); 32 33 if (IsEqualIID(riid, &IID_IUnknown) || 34 IsEqualIID(riid, &IID_IInternetTransport) || 35 IsEqualIID(riid, &IID_IIMAPTransport)) 36 { 37 *ppv = iface; 38 IIMAPTransport_AddRef(iface); 39 return S_OK; 40 } 41 *ppv = NULL; 42 FIXME("no interface for %s\n", debugstr_guid(riid)); 43 return E_NOINTERFACE; 44 } 45 46 static ULONG WINAPI IMAPTransport_AddRef(IIMAPTransport *iface) 47 { 48 IMAPTransport *This = (IMAPTransport *)iface; 49 return InterlockedIncrement((LONG *)&This->refs); 50 } 51 52 static ULONG WINAPI IMAPTransport_Release(IIMAPTransport *iface) 53 { 54 IMAPTransport *This = (IMAPTransport *)iface; 55 ULONG refs = InterlockedDecrement((LONG *)&This->refs); 56 if (!refs) 57 { 58 TRACE("destroying %p\n", This); 59 if (This->InetTransport.Status != IXP_DISCONNECTED) 60 InternetTransport_DropConnection(&This->InetTransport); 61 if (This->InetTransport.pCallback) ITransportCallback_Release(This->InetTransport.pCallback); 62 HeapFree(GetProcessHeap(), 0, This); 63 } 64 return refs; 65 } 66 67 static HRESULT WINAPI IMAPTransport_GetServerInfo(IIMAPTransport *iface, 68 LPINETSERVER pInetServer) 69 { 70 IMAPTransport *This = (IMAPTransport *)iface; 71 72 TRACE("(%p)\n", pInetServer); 73 return InternetTransport_GetServerInfo(&This->InetTransport, pInetServer); 74 } 75 76 static IXPTYPE WINAPI IMAPTransport_GetIXPType(IIMAPTransport *iface) 77 { 78 TRACE("()\n"); 79 return IXP_IMAP; 80 } 81 82 static HRESULT WINAPI IMAPTransport_IsState(IIMAPTransport *iface, 83 IXPISSTATE isstate) 84 { 85 FIXME("(%d): stub\n", isstate); 86 return E_NOTIMPL; 87 } 88 89 static HRESULT WINAPI IMAPTransport_InetServerFromAccount( 90 IIMAPTransport *iface, IImnAccount *pAccount, LPINETSERVER pInetServer) 91 { 92 IMAPTransport *This = (IMAPTransport *)iface; 93 94 TRACE("(%p, %p)\n", pAccount, pInetServer); 95 return InternetTransport_InetServerFromAccount(&This->InetTransport, pAccount, pInetServer); 96 } 97 98 static HRESULT WINAPI IMAPTransport_Connect(IIMAPTransport *iface, 99 LPINETSERVER pInetServer, boolean fAuthenticate, boolean fCommandLogging) 100 { 101 IMAPTransport *This = (IMAPTransport *)iface; 102 HRESULT hr; 103 104 TRACE("(%p, %s, %s)\n", pInetServer, fAuthenticate ? "TRUE" : "FALSE", fCommandLogging ? "TRUE" : "FALSE"); 105 106 hr = InternetTransport_Connect(&This->InetTransport, pInetServer, fAuthenticate, fCommandLogging); 107 return hr; 108 } 109 110 static HRESULT WINAPI IMAPTransport_HandsOffCallback(IIMAPTransport *iface) 111 { 112 IMAPTransport *This = (IMAPTransport *)iface; 113 114 TRACE("()\n"); 115 return InternetTransport_HandsOffCallback(&This->InetTransport); 116 } 117 118 static HRESULT WINAPI IMAPTransport_Disconnect(IIMAPTransport *iface) 119 { 120 FIXME("(): stub\n"); 121 return E_NOTIMPL; 122 } 123 124 static HRESULT WINAPI IMAPTransport_DropConnection(IIMAPTransport *iface) 125 { 126 IMAPTransport *This = (IMAPTransport *)iface; 127 128 TRACE("()\n"); 129 return InternetTransport_DropConnection(&This->InetTransport); 130 } 131 132 static HRESULT WINAPI IMAPTransport_GetStatus(IIMAPTransport *iface, 133 IXPSTATUS *pCurrentStatus) 134 { 135 IMAPTransport *This = (IMAPTransport *)iface; 136 137 TRACE("()\n"); 138 return InternetTransport_GetStatus(&This->InetTransport, pCurrentStatus); 139 } 140 141 static HRESULT WINAPI IMAPTransport_InitNew(IIMAPTransport *iface, 142 LPSTR pszLogFilePath, IIMAPCallback *pCallback) 143 { 144 IMAPTransport *This = (IMAPTransport *)iface; 145 146 TRACE("(%s, %p)\n", debugstr_a(pszLogFilePath), pCallback); 147 148 if (!pCallback) 149 return E_INVALIDARG; 150 151 if (pszLogFilePath) 152 FIXME("not using log file of %s, use Wine debug logging instead\n", 153 debugstr_a(pszLogFilePath)); 154 155 IIMAPCallback_AddRef(pCallback); 156 This->InetTransport.pCallback = (ITransportCallback *)pCallback; 157 This->InetTransport.fInitialised = TRUE; 158 159 return S_OK; 160 } 161 162 static HRESULT WINAPI IMAPTransport_NewIRangeList(IIMAPTransport *iface, 163 IRangeList **pprlNewRangeList) 164 { 165 FIXME("(%p): stub\n", pprlNewRangeList); 166 return E_NOTIMPL; 167 } 168 169 static HRESULT WINAPI IMAPTransport_Capability(IIMAPTransport *iface, 170 DWORD *pdwCapabilityFlags) 171 { 172 FIXME("(%p): stub\n", pdwCapabilityFlags); 173 return E_NOTIMPL; 174 } 175 176 static HRESULT WINAPI IMAPTransport_Select(IIMAPTransport *iface, 177 WPARAM wParam, LPARAM lParam, IIMAPCallback *pCBHandler, LPSTR lpszMailboxName) 178 { 179 FIXME("(%ld, %ld, %p, %s): stub\n", wParam, lParam, pCBHandler, debugstr_a(lpszMailboxName)); 180 return E_NOTIMPL; 181 } 182 183 static HRESULT WINAPI IMAPTransport_Examine(IIMAPTransport *iface, 184 WPARAM wParam, LPARAM lParam, IIMAPCallback *pCBHandler, LPSTR lpszMailboxName) 185 { 186 FIXME("(%ld, %ld, %p, %s): stub\n", wParam, lParam, pCBHandler, debugstr_a(lpszMailboxName)); 187 return E_NOTIMPL; 188 } 189 190 static HRESULT WINAPI IMAPTransport_Create(IIMAPTransport *iface, 191 WPARAM wParam, LPARAM lParam, IIMAPCallback *pCBHandler, LPSTR lpszMailboxName) 192 { 193 FIXME("(%ld, %ld, %p, %s): stub\n", wParam, lParam, pCBHandler, debugstr_a(lpszMailboxName)); 194 return E_NOTIMPL; 195 } 196 197 static HRESULT WINAPI IMAPTransport_Delete(IIMAPTransport *iface, 198 WPARAM wParam, LPARAM lParam, IIMAPCallback *pCBHandler, LPSTR lpszMailboxName) 199 { 200 FIXME("(%ld, %ld, %p, %s): stub\n", wParam, lParam, pCBHandler, debugstr_a(lpszMailboxName)); 201 return E_NOTIMPL; 202 } 203 204 static HRESULT WINAPI IMAPTransport_Rename(IIMAPTransport *iface, WPARAM wParam, LPARAM lParam, 205 IIMAPCallback *pCBHandler, LPSTR lpszMailboxName, LPSTR lpszNewMailboxName) 206 { 207 FIXME("(%ld, %ld, %p, %s, %s): stub\n", wParam, lParam, pCBHandler, 208 debugstr_a(lpszMailboxName), debugstr_a(lpszNewMailboxName)); 209 return E_NOTIMPL; 210 } 211 212 static HRESULT WINAPI IMAPTransport_Subscribe(IIMAPTransport *iface, 213 WPARAM wParam, LPARAM lParam, IIMAPCallback *pCBHandler, LPSTR lpszMailboxName) 214 { 215 FIXME("(%ld, %ld, %p, %s): stub\n", wParam, lParam, pCBHandler, debugstr_a(lpszMailboxName)); 216 return E_NOTIMPL; 217 } 218 219 static HRESULT WINAPI IMAPTransport_Unsubscribe(IIMAPTransport *iface, 220 WPARAM wParam, LPARAM lParam, IIMAPCallback *pCBHandler, LPSTR lpszMailboxName) 221 { 222 FIXME("(%ld, %ld, %p, %s): stub\n", wParam, lParam, pCBHandler, debugstr_a(lpszMailboxName)); 223 return E_NOTIMPL; 224 } 225 226 static HRESULT WINAPI IMAPTransport_List(IIMAPTransport *iface, WPARAM wParam, LPARAM lParam, 227 IIMAPCallback *pCBHandler, LPSTR lpszMailboxNameReference, LPSTR lpszMailboxNamePattern) 228 { 229 FIXME("(%ld, %ld, %p, %s, %s): stub\n", wParam, lParam, pCBHandler, 230 debugstr_a(lpszMailboxNameReference), debugstr_a(lpszMailboxNamePattern)); 231 return E_NOTIMPL; 232 } 233 234 static HRESULT WINAPI IMAPTransport_Lsub(IIMAPTransport *iface, WPARAM wParam, LPARAM lParam, 235 IIMAPCallback *pCBHandler, LPSTR lpszMailboxNameReference, LPSTR lpszMailboxNamePattern) 236 { 237 FIXME("(%ld, %ld, %p, %s, %s): stub\n", wParam, lParam, pCBHandler, 238 debugstr_a(lpszMailboxNameReference), debugstr_a(lpszMailboxNamePattern)); 239 return E_NOTIMPL; 240 } 241 242 static HRESULT WINAPI IMAPTransport_Append(IIMAPTransport *iface, 243 WPARAM wParam, LPARAM lParam, IIMAPCallback *pCBHandler, LPSTR lpszMailboxName, 244 LPSTR lpszMessageFlags, FILETIME ftMessageDateTime, LPSTREAM lpstmMessageToSave) 245 { 246 FIXME("(%ld, %ld, %p, %s, %s, %p): stub\n", wParam, lParam, pCBHandler, 247 debugstr_a(lpszMailboxName), debugstr_a(lpszMessageFlags), lpstmMessageToSave); 248 return E_NOTIMPL; 249 } 250 251 static HRESULT WINAPI IMAPTransport_Close(IIMAPTransport *iface, 252 WPARAM wParam, LPARAM lParam, IIMAPCallback *pCBHandler) 253 { 254 FIXME("(%ld, %ld, %p): stub\n", wParam, lParam, pCBHandler); 255 return E_NOTIMPL; 256 } 257 258 static HRESULT WINAPI IMAPTransport_Expunge(IIMAPTransport *iface, 259 WPARAM wParam, LPARAM lParam, IIMAPCallback *pCBHandler) 260 { 261 FIXME("(%ld, %ld, %p): stub\n", wParam, lParam, pCBHandler); 262 return E_NOTIMPL; 263 } 264 265 static HRESULT WINAPI IMAPTransport_Search(IIMAPTransport *iface, 266 WPARAM wParam, LPARAM lParam, IIMAPCallback *pCBHandler, LPSTR lpszSearchCriteria, 267 boolean bReturnUIDs, IRangeList *pMsgRange, boolean bUIDRangeList) 268 { 269 FIXME("(%ld, %ld, %p, %s, %d, %p, %d): stub\n", wParam, lParam, pCBHandler, 270 debugstr_a(lpszSearchCriteria), bReturnUIDs, pMsgRange, bUIDRangeList); 271 return E_NOTIMPL; 272 } 273 274 static HRESULT WINAPI IMAPTransport_Fetch(IIMAPTransport *iface, WPARAM wParam, LPARAM lParam, 275 IIMAPCallback *pCBHandler, IRangeList *pMsgRange, boolean bUIDMsgRange, LPSTR lpszFetchArgs) 276 { 277 FIXME("(%ld, %ld, %p, %p, %d, %s): stub\n", wParam, lParam, pCBHandler, pMsgRange, 278 bUIDMsgRange, debugstr_a(lpszFetchArgs)); 279 return E_NOTIMPL; 280 } 281 282 static HRESULT WINAPI IMAPTransport_Store(IIMAPTransport *iface, WPARAM wParam, LPARAM lParam, 283 IIMAPCallback *pCBHandler, IRangeList *pMsgRange, boolean bUIDRangeList, LPSTR lpszStoreArgs) 284 { 285 FIXME("(%ld, %ld, %p, %p, %d, %s): stub\n", wParam, lParam, pCBHandler, pMsgRange, 286 bUIDRangeList, debugstr_a(lpszStoreArgs)); 287 return E_NOTIMPL; 288 } 289 290 static HRESULT WINAPI IMAPTransport_Copy(IIMAPTransport *iface, WPARAM wParam, LPARAM lParam, 291 IIMAPCallback *pCBHandler, IRangeList *pMsgRange, boolean bUIDRangeList, LPSTR lpszMailboxName) 292 { 293 FIXME("(%ld, %ld, %p, %p, %d, %s): stub\n", wParam, lParam, pCBHandler, pMsgRange, 294 bUIDRangeList, debugstr_a(lpszMailboxName)); 295 return E_NOTIMPL; 296 } 297 298 static HRESULT WINAPI IMAPTransport_Noop(IIMAPTransport *iface, 299 WPARAM wParam, LPARAM lParam, IIMAPCallback *pCBHandler) 300 { 301 FIXME("(%ld, %ld, %p): stub\n", wParam, lParam, pCBHandler); 302 return E_NOTIMPL; 303 } 304 305 static HRESULT WINAPI IMAPTransport_ResizeMsgSeqNumTable(IIMAPTransport *iface, DWORD dwSizeOfMbox) 306 { 307 FIXME("(%u): stub\n", dwSizeOfMbox); 308 return E_NOTIMPL; 309 } 310 311 static HRESULT WINAPI IMAPTransport_UpdateSeqNumToUID(IIMAPTransport *iface, 312 DWORD dwMsgSeqNum, DWORD dwUID) 313 { 314 FIXME("(%u, %u): stub\n", dwMsgSeqNum, dwUID); 315 return E_NOTIMPL; 316 } 317 318 static HRESULT WINAPI IMAPTransport_RemoveSequenceNum(IIMAPTransport *iface, DWORD dwDeletedMsgSeqNum) 319 { 320 FIXME("(%u): stub\n", dwDeletedMsgSeqNum); 321 return E_NOTIMPL; 322 } 323 324 static HRESULT WINAPI IMAPTransport_MsgSeqNumToUID(IIMAPTransport *iface, DWORD dwMsgSeqNum, 325 DWORD *pdwUID) 326 { 327 FIXME("(%u, %p): stub\n", dwMsgSeqNum, pdwUID); 328 return E_NOTIMPL; 329 } 330 331 static HRESULT WINAPI IMAPTransport_GetMsgSeqNumToUIDArray(IIMAPTransport *iface, 332 DWORD **ppdwMsgSeqNumToUIDArray, DWORD *pdwNumberOfElements) 333 { 334 FIXME("(%p, %p): stub\n", ppdwMsgSeqNumToUIDArray, pdwNumberOfElements); 335 return E_NOTIMPL; 336 } 337 338 static HRESULT WINAPI IMAPTransport_GetHighestMsgSeqNum(IIMAPTransport *iface, DWORD *pdwHighestMSN) 339 { 340 FIXME("(%p): stub\n", pdwHighestMSN); 341 return E_NOTIMPL; 342 } 343 344 static HRESULT WINAPI IMAPTransport_ResetMsgSeqNumToUID(IIMAPTransport *iface) 345 { 346 FIXME("(): stub\n"); 347 return E_NOTIMPL; 348 } 349 350 static HRESULT WINAPI IMAPTransport_SetDefaultCBHandler(IIMAPTransport *iface, IIMAPCallback *pCBHandler) 351 { 352 FIXME("(%p): stub\n", pCBHandler); 353 return E_NOTIMPL; 354 } 355 356 static HRESULT WINAPI IMAPTransport_Status(IIMAPTransport *iface, WPARAM wParam, LPARAM lParam, 357 IIMAPCallback *pCBHandler, LPSTR pszMailboxName, LPSTR pszStatusCmdArgs) 358 { 359 FIXME("(%ld, %ld, %p, %s, %s): stub\n", wParam, lParam, pCBHandler, 360 debugstr_a(pszMailboxName), debugstr_a(pszStatusCmdArgs)); 361 return E_NOTIMPL; 362 } 363 364 static const IIMAPTransportVtbl IMAPTransportVtbl = 365 { 366 IMAPTransport_QueryInterface, 367 IMAPTransport_AddRef, 368 IMAPTransport_Release, 369 IMAPTransport_GetServerInfo, 370 IMAPTransport_GetIXPType, 371 IMAPTransport_IsState, 372 IMAPTransport_InetServerFromAccount, 373 IMAPTransport_Connect, 374 IMAPTransport_HandsOffCallback, 375 IMAPTransport_Disconnect, 376 IMAPTransport_DropConnection, 377 IMAPTransport_GetStatus, 378 IMAPTransport_InitNew, 379 IMAPTransport_NewIRangeList, 380 IMAPTransport_Capability, 381 IMAPTransport_Select, 382 IMAPTransport_Examine, 383 IMAPTransport_Create, 384 IMAPTransport_Delete, 385 IMAPTransport_Rename, 386 IMAPTransport_Subscribe, 387 IMAPTransport_Unsubscribe, 388 IMAPTransport_List, 389 IMAPTransport_Lsub, 390 IMAPTransport_Append, 391 IMAPTransport_Close, 392 IMAPTransport_Expunge, 393 IMAPTransport_Search, 394 IMAPTransport_Fetch, 395 IMAPTransport_Store, 396 IMAPTransport_Copy, 397 IMAPTransport_Noop, 398 IMAPTransport_ResizeMsgSeqNumTable, 399 IMAPTransport_UpdateSeqNumToUID, 400 IMAPTransport_RemoveSequenceNum, 401 IMAPTransport_MsgSeqNumToUID, 402 IMAPTransport_GetMsgSeqNumToUIDArray, 403 IMAPTransport_GetHighestMsgSeqNum, 404 IMAPTransport_ResetMsgSeqNumToUID, 405 IMAPTransport_SetDefaultCBHandler, 406 IMAPTransport_Status 407 }; 408 409 HRESULT WINAPI CreateIMAPTransport(IIMAPTransport **ppTransport) 410 { 411 HRESULT hr; 412 IMAPTransport *This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This)); 413 if (!This) 414 return E_OUTOFMEMORY; 415 416 This->InetTransport.u.vtblIMAP = &IMAPTransportVtbl; 417 This->refs = 0; 418 hr = InternetTransport_Init(&This->InetTransport); 419 if (FAILED(hr)) 420 { 421 HeapFree(GetProcessHeap(), 0, This); 422 return hr; 423 } 424 425 *ppTransport = (IIMAPTransport *)&This->InetTransport.u.vtblIMAP; 426 IIMAPTransport_AddRef(*ppTransport); 427 428 return S_OK; 429 } 430 431 static HRESULT WINAPI IMAPTransportCF_QueryInterface(IClassFactory *iface, 432 REFIID riid, LPVOID *ppv) 433 { 434 *ppv = NULL; 435 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory)) 436 { 437 *ppv = iface; 438 IClassFactory_AddRef(iface); 439 return S_OK; 440 } 441 return E_NOINTERFACE; 442 } 443 444 static ULONG WINAPI IMAPTransportCF_AddRef(IClassFactory *iface) 445 { 446 return 2; /* non-heap based object */ 447 } 448 449 static ULONG WINAPI IMAPTransportCF_Release(IClassFactory *iface) 450 { 451 return 1; /* non-heap based object */ 452 } 453 454 static HRESULT WINAPI IMAPTransportCF_CreateInstance(IClassFactory *iface, 455 LPUNKNOWN pUnk, REFIID riid, LPVOID *ppv) 456 { 457 HRESULT hr; 458 IIMAPTransport *pImapTransport; 459 460 TRACE("(%p, %s, %p)\n", pUnk, debugstr_guid(riid), ppv); 461 462 *ppv = NULL; 463 464 if (pUnk) 465 return CLASS_E_NOAGGREGATION; 466 467 hr = CreateIMAPTransport(&pImapTransport); 468 if (FAILED(hr)) 469 return hr; 470 471 hr = IIMAPTransport_QueryInterface(pImapTransport, riid, ppv); 472 IIMAPTransport_Release(pImapTransport); 473 474 return hr; 475 } 476 477 static HRESULT WINAPI IMAPTransportCF_LockServer(IClassFactory *iface, BOOL fLock) 478 { 479 FIXME("(%d), stub!\n",fLock); 480 return S_OK; 481 } 482 483 static const IClassFactoryVtbl IMAPTransportCFVtbl = 484 { 485 IMAPTransportCF_QueryInterface, 486 IMAPTransportCF_AddRef, 487 IMAPTransportCF_Release, 488 IMAPTransportCF_CreateInstance, 489 IMAPTransportCF_LockServer 490 }; 491 static const IClassFactoryVtbl *IMAPTransportCF = &IMAPTransportCFVtbl; 492 493 HRESULT IMAPTransportCF_Create(REFIID riid, LPVOID *ppv) 494 { 495 return IClassFactory_QueryInterface((IClassFactory *)&IMAPTransportCF, riid, ppv); 496 } 497