4 * Copyright 2008 Hans Leidekker for CodeWeavers
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.
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.
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
21 #define WIN32_NO_STATUS
23 #define COM_NO_WINDOWS_H
26 #define NONAMELESSUNION
34 //#include "winuser.h"
37 #include <wine/debug.h>
39 #include "inetcomm_private.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(inetcomm
);
53 InternetTransport InetTransport
;
59 enum parse_state state
;
65 static HRESULT
parse_response(POP3Transport
*This
)
70 if (strlen(This
->response
) < 3)
72 WARN("parse error\n");
73 This
->state
= STATE_DONE
;
76 if (!memcmp(This
->response
, "+OK", 3))
78 This
->ptr
= This
->response
+ 3;
79 This
->state
= STATE_OK
;
82 This
->state
= STATE_DONE
;
89 static HRESULT
parse_uidl_response(POP3Transport
*This
, POP3UIDL
*uidl
)
98 if (This
->type
== POP3CMD_GET_POPID
)
100 if ((p
= strchr(This
->ptr
, ' ')))
102 while (*p
== ' ') p
++;
103 sscanf(p
, "%u", &uidl
->dwPopId
);
104 if ((p
= strchr(p
, ' ')))
106 while (*p
== ' ') p
++;
108 This
->valid_info
= TRUE
;
111 This
->state
= STATE_DONE
;
114 This
->state
= STATE_MULTILINE
;
117 case STATE_MULTILINE
:
118 if (This
->response
[0] == '.' && !This
->response
[1])
120 This
->valid_info
= FALSE
;
121 This
->state
= STATE_DONE
;
124 sscanf(This
->response
, "%u", &uidl
->dwPopId
);
125 if ((p
= strchr(This
->response
, ' ')))
127 while (*p
== ' ') p
++;
129 This
->valid_info
= TRUE
;
134 WARN("parse error\n");
135 This
->state
= STATE_DONE
;
140 static HRESULT
parse_stat_response(POP3Transport
*This
, POP3STAT
*stat
)
145 stat
->cbMessages
= 0;
149 if ((p
= strchr(This
->ptr
, ' ')))
151 while (*p
== ' ') p
++;
152 sscanf(p
, "%u %u", &stat
->cMessages
, &stat
->cbMessages
);
153 This
->valid_info
= TRUE
;
154 This
->state
= STATE_DONE
;
159 WARN("parse error\n");
160 This
->state
= STATE_DONE
;
165 static HRESULT
parse_list_response(POP3Transport
*This
, POP3LIST
*list
)
174 if (This
->type
== POP3CMD_GET_POPID
)
176 if ((p
= strchr(This
->ptr
, ' ')))
178 while (*p
== ' ') p
++;
179 sscanf(p
, "%u %u", &list
->dwPopId
, &list
->cbSize
);
180 This
->valid_info
= TRUE
;
182 This
->state
= STATE_DONE
;
185 This
->state
= STATE_MULTILINE
;
188 case STATE_MULTILINE
:
189 if (This
->response
[0] == '.' && !This
->response
[1])
191 This
->valid_info
= FALSE
;
192 This
->state
= STATE_DONE
;
195 sscanf(This
->response
, "%u", &list
->dwPopId
);
196 if ((p
= strchr(This
->response
, ' ')))
198 while (*p
== ' ') p
++;
199 sscanf(p
, "%u", &list
->cbSize
);
200 This
->valid_info
= TRUE
;
205 WARN("parse error\n");
206 This
->state
= STATE_DONE
;
211 static HRESULT
parse_dele_response(POP3Transport
*This
, DWORD
*dwPopId
)
216 *dwPopId
= 0; /* FIXME */
217 This
->state
= STATE_DONE
;
221 WARN("parse error\n");
222 This
->state
= STATE_DONE
;
227 static HRESULT
parse_retr_response(POP3Transport
*This
, POP3RETR
*retr
)
232 retr
->fHeader
= FALSE
;
234 retr
->dwPopId
= This
->msgid
;
236 retr
->pszLines
= This
->response
;
239 This
->state
= STATE_MULTILINE
;
240 This
->valid_info
= FALSE
;
243 case STATE_MULTILINE
:
247 if (This
->response
[0] == '.' && !This
->response
[1])
249 retr
->cbLines
= retr
->cbSoFar
;
250 This
->state
= STATE_DONE
;
253 retr
->fHeader
= TRUE
;
254 if (!This
->response
[0]) retr
->fBody
= TRUE
;
256 len
= strlen(This
->response
);
257 retr
->cbSoFar
+= len
;
258 retr
->pszLines
= This
->response
;
261 This
->valid_info
= TRUE
;
266 WARN("parse error\n");
267 This
->state
= STATE_DONE
;
272 static HRESULT
parse_top_response(POP3Transport
*This
, POP3TOP
*top
)
277 top
->fHeader
= FALSE
;
279 top
->dwPopId
= This
->msgid
;
280 top
->cPreviewLines
= This
->preview_lines
;
282 top
->pszLines
= This
->response
;
285 This
->state
= STATE_MULTILINE
;
286 This
->valid_info
= FALSE
;
289 case STATE_MULTILINE
:
293 if (This
->response
[0] == '.' && !This
->response
[1])
295 top
->cbLines
= top
->cbSoFar
;
296 This
->state
= STATE_DONE
;
300 if (!This
->response
[0]) top
->fBody
= TRUE
;
302 len
= strlen(This
->response
);
304 top
->pszLines
= This
->response
;
307 This
->valid_info
= TRUE
;
312 WARN("parse error\n");
313 This
->state
= STATE_DONE
;
318 static void init_parser(POP3Transport
*This
, POP3COMMAND command
, POP3CMDTYPE type
)
320 This
->state
= STATE_NONE
;
321 This
->command
= command
;
325 static HRESULT
POP3Transport_ParseResponse(POP3Transport
*This
, char *pszResponse
, POP3RESPONSE
*pResponse
)
329 TRACE("response: %s\n", debugstr_a(pszResponse
));
331 This
->response
= pszResponse
;
332 This
->valid_info
= FALSE
;
333 TRACE("state %u\n", This
->state
);
335 if (SUCCEEDED((hr
= parse_response(This
))))
337 switch (This
->command
)
339 case POP3_UIDL
: hr
= parse_uidl_response(This
, &pResponse
->u
.rUidlInfo
); break;
340 case POP3_STAT
: hr
= parse_stat_response(This
, &pResponse
->u
.rStatInfo
); break;
341 case POP3_LIST
: hr
= parse_list_response(This
, &pResponse
->u
.rListInfo
); break;
342 case POP3_DELE
: hr
= parse_dele_response(This
, &pResponse
->u
.dwPopId
); break;
343 case POP3_RETR
: hr
= parse_retr_response(This
, &pResponse
->u
.rRetrInfo
); break;
344 case POP3_TOP
: hr
= parse_top_response(This
, &pResponse
->u
.rTopInfo
); break;
346 This
->state
= STATE_DONE
;
350 pResponse
->command
= This
->command
;
351 pResponse
->fDone
= (This
->state
== STATE_DONE
);
352 pResponse
->fValidInfo
= This
->valid_info
;
353 pResponse
->rIxpResult
.hrResult
= hr
;
354 pResponse
->rIxpResult
.pszResponse
= pszResponse
;
355 pResponse
->rIxpResult
.uiServerError
= 0;
356 pResponse
->rIxpResult
.hrServerError
= pResponse
->rIxpResult
.hrResult
;
357 pResponse
->rIxpResult
.dwSocketError
= WSAGetLastError();
358 pResponse
->rIxpResult
.pszProblem
= NULL
;
359 pResponse
->pTransport
= (IPOP3Transport
*)&This
->InetTransport
.u
.vtblPOP3
;
361 if (This
->InetTransport
.pCallback
&& This
->InetTransport
.fCommandLogging
)
363 ITransportCallback_OnCommand(This
->InetTransport
.pCallback
, CMD_RESP
,
364 pResponse
->rIxpResult
.pszResponse
, pResponse
->rIxpResult
.hrServerError
,
365 (IInternetTransport
*)&This
->InetTransport
.u
.vtbl
);
370 static void POP3Transport_CallbackProcessDELEResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
372 POP3Transport
*This
= (POP3Transport
*)iface
;
373 POP3RESPONSE response
;
378 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
381 /* FIXME: handle error */
385 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
388 static void POP3Transport_CallbackRecvDELEResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
390 POP3Transport
*This
= (POP3Transport
*)iface
;
393 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessDELEResp
);
396 static void POP3Transport_CallbackProcessNOOPResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
398 POP3Transport
*This
= (POP3Transport
*)iface
;
399 POP3RESPONSE response
;
404 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
407 /* FIXME: handle error */
411 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
414 static void POP3Transport_CallbackRecvNOOPResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
416 POP3Transport
*This
= (POP3Transport
*)iface
;
419 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessNOOPResp
);
422 static void POP3Transport_CallbackProcessRSETResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
424 POP3Transport
*This
= (POP3Transport
*)iface
;
425 POP3RESPONSE response
;
430 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
433 /* FIXME: handle error */
437 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
440 static void POP3Transport_CallbackRecvRSETResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
442 POP3Transport
*This
= (POP3Transport
*)iface
;
445 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessRSETResp
);
448 static void POP3Transport_CallbackProcessRETRResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
450 POP3Transport
*This
= (POP3Transport
*)iface
;
451 POP3RESPONSE response
;
456 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
459 /* FIXME: handle error */
463 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
467 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessRETRResp
);
471 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
474 static void POP3Transport_CallbackRecvRETRResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
476 POP3Transport
*This
= (POP3Transport
*)iface
;
479 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessRETRResp
);
482 static void POP3Transport_CallbackProcessTOPResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
484 POP3Transport
*This
= (POP3Transport
*)iface
;
485 POP3RESPONSE response
;
490 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
493 /* FIXME: handle error */
497 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
501 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessTOPResp
);
505 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
508 static void POP3Transport_CallbackRecvTOPResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
510 POP3Transport
*This
= (POP3Transport
*)iface
;
513 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessTOPResp
);
516 static void POP3Transport_CallbackProcessLISTResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
518 POP3Transport
*This
= (POP3Transport
*)iface
;
519 POP3RESPONSE response
;
524 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
527 /* FIXME: handle error */
531 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
535 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessLISTResp
);
539 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
542 static void POP3Transport_CallbackRecvLISTResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
544 POP3Transport
*This
= (POP3Transport
*)iface
;
547 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessLISTResp
);
550 static void POP3Transport_CallbackProcessUIDLResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
552 POP3Transport
*This
= (POP3Transport
*)iface
;
553 POP3RESPONSE response
;
558 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
561 /* FIXME: handle error */
565 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
569 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessUIDLResp
);
573 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
576 static void POP3Transport_CallbackRecvUIDLResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
578 POP3Transport
*This
= (POP3Transport
*)iface
;
581 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessUIDLResp
);
584 static void POP3Transport_CallbackProcessSTATResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
586 POP3Transport
*This
= (POP3Transport
*)iface
;
587 POP3RESPONSE response
;
592 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
595 /* FIXME: handle error */
599 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
602 static void POP3Transport_CallbackRecvSTATResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
604 POP3Transport
*This
= (POP3Transport
*)iface
;
607 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessSTATResp
);
610 static void POP3Transport_CallbackProcessPASSResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
612 POP3Transport
*This
= (POP3Transport
*)iface
;
613 POP3RESPONSE response
;
618 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
621 /* FIXME: handle error */
625 InternetTransport_ChangeStatus(&This
->InetTransport
, IXP_AUTHORIZED
);
626 InternetTransport_ChangeStatus(&This
->InetTransport
, IXP_CONNECTED
);
628 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
631 static void POP3Transport_CallbackRecvPASSResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
633 POP3Transport
*This
= (POP3Transport
*)iface
;
636 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessPASSResp
);
639 static void POP3Transport_CallbackProcessUSERResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
641 static char pass
[] = "PASS ";
642 POP3Transport
*This
= (POP3Transport
*)iface
;
643 POP3RESPONSE response
;
650 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
653 /* FIXME: handle error */
657 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
659 len
= sizeof(pass
) + strlen(This
->InetTransport
.ServerInfo
.szPassword
) + 2; /* "\r\n" */
660 command
= HeapAlloc(GetProcessHeap(), 0, len
);
662 strcpy(command
, pass
);
663 strcat(command
, This
->InetTransport
.ServerInfo
.szPassword
);
664 strcat(command
, "\r\n");
666 init_parser(This
, POP3_PASS
, POP3_NONE
);
668 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvPASSResp
);
669 HeapFree(GetProcessHeap(), 0, command
);
672 static void POP3Transport_CallbackRecvUSERResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
674 POP3Transport
*This
= (POP3Transport
*)iface
;
677 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessUSERResp
);
680 static void POP3Transport_CallbackSendUSERCmd(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
682 static char user
[] = "USER ";
683 POP3Transport
*This
= (POP3Transport
*)iface
;
689 len
= sizeof(user
) + strlen(This
->InetTransport
.ServerInfo
.szUserName
) + 2; /* "\r\n" */
690 command
= HeapAlloc(GetProcessHeap(), 0, len
);
692 strcpy(command
, user
);
693 strcat(command
, This
->InetTransport
.ServerInfo
.szUserName
);
694 strcat(command
, "\r\n");
695 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvUSERResp
);
697 HeapFree(GetProcessHeap(), 0, command
);
700 static void POP3Transport_CallbackProcessQUITResponse(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
702 POP3Transport
*This
= (POP3Transport
*)iface
;
703 POP3RESPONSE response
;
706 TRACE("%s\n", debugstr_an(pBuffer
, cbBuffer
));
708 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
711 /* FIXME: handle error */
715 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
716 InternetTransport_DropConnection(&This
->InetTransport
);
719 static void POP3Transport_CallbackRecvQUITResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
721 POP3Transport
*This
= (POP3Transport
*)iface
;
724 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessQUITResponse
);
727 static HRESULT WINAPI
POP3Transport_QueryInterface(IPOP3Transport
*iface
, REFIID riid
, void **ppv
)
729 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
731 if (IsEqualIID(riid
, &IID_IUnknown
) ||
732 IsEqualIID(riid
, &IID_IInternetTransport
) ||
733 IsEqualIID(riid
, &IID_IPOP3Transport
))
736 IUnknown_AddRef(iface
);
740 FIXME("no interface for %s\n", debugstr_guid(riid
));
741 return E_NOINTERFACE
;
744 static ULONG WINAPI
POP3Transport_AddRef(IPOP3Transport
*iface
)
746 POP3Transport
*This
= (POP3Transport
*)iface
;
747 return InterlockedIncrement((LONG
*)&This
->refs
);
750 static ULONG WINAPI
POP3Transport_Release(IPOP3Transport
*iface
)
752 POP3Transport
*This
= (POP3Transport
*)iface
;
753 ULONG refs
= InterlockedDecrement((LONG
*)&This
->refs
);
756 TRACE("destroying %p\n", This
);
757 if (This
->InetTransport
.Status
!= IXP_DISCONNECTED
)
758 InternetTransport_DropConnection(&This
->InetTransport
);
759 if (This
->InetTransport
.pCallback
) ITransportCallback_Release(This
->InetTransport
.pCallback
);
760 HeapFree(GetProcessHeap(), 0, This
);
765 static HRESULT WINAPI
POP3Transport_GetServerInfo(IPOP3Transport
*iface
,
766 LPINETSERVER pInetServer
)
768 POP3Transport
*This
= (POP3Transport
*)iface
;
770 TRACE("(%p)\n", pInetServer
);
771 return InternetTransport_GetServerInfo(&This
->InetTransport
, pInetServer
);
774 static IXPTYPE WINAPI
POP3Transport_GetIXPType(IPOP3Transport
*iface
)
780 static HRESULT WINAPI
POP3Transport_IsState(IPOP3Transport
*iface
, IXPISSTATE isstate
)
782 FIXME("(%u)\n", isstate
);
786 static HRESULT WINAPI
POP3Transport_InetServerFromAccount(
787 IPOP3Transport
*iface
, IImnAccount
*pAccount
, LPINETSERVER pInetServer
)
789 POP3Transport
*This
= (POP3Transport
*)iface
;
791 TRACE("(%p, %p)\n", pAccount
, pInetServer
);
792 return InternetTransport_InetServerFromAccount(&This
->InetTransport
, pAccount
, pInetServer
);
795 static HRESULT WINAPI
POP3Transport_Connect(IPOP3Transport
*iface
,
796 LPINETSERVER pInetServer
, boolean fAuthenticate
, boolean fCommandLogging
)
798 POP3Transport
*This
= (POP3Transport
*)iface
;
801 TRACE("(%p, %s, %s)\n", pInetServer
, fAuthenticate
? "TRUE" : "FALSE", fCommandLogging
? "TRUE" : "FALSE");
803 hr
= InternetTransport_Connect(&This
->InetTransport
, pInetServer
, fAuthenticate
, fCommandLogging
);
807 init_parser(This
, POP3_USER
, POP3_NONE
);
808 return InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackSendUSERCmd
);
811 static HRESULT WINAPI
POP3Transport_HandsOffCallback(IPOP3Transport
*iface
)
813 POP3Transport
*This
= (POP3Transport
*)iface
;
816 return InternetTransport_HandsOffCallback(&This
->InetTransport
);
819 static HRESULT WINAPI
POP3Transport_Disconnect(IPOP3Transport
*iface
)
822 return IPOP3Transport_CommandQUIT(iface
);
825 static HRESULT WINAPI
POP3Transport_DropConnection(IPOP3Transport
*iface
)
827 POP3Transport
*This
= (POP3Transport
*)iface
;
830 return InternetTransport_DropConnection(&This
->InetTransport
);
833 static HRESULT WINAPI
POP3Transport_GetStatus(IPOP3Transport
*iface
,
834 IXPSTATUS
*pCurrentStatus
)
836 POP3Transport
*This
= (POP3Transport
*)iface
;
839 return InternetTransport_GetStatus(&This
->InetTransport
, pCurrentStatus
);
842 static HRESULT WINAPI
POP3Transport_InitNew(IPOP3Transport
*iface
,
843 LPSTR pszLogFilePath
, IPOP3Callback
*pCallback
)
845 POP3Transport
*This
= (POP3Transport
*)iface
;
847 TRACE("(%s, %p)\n", debugstr_a(pszLogFilePath
), pCallback
);
853 FIXME("not using log file of %s, use Wine debug logging instead\n",
854 debugstr_a(pszLogFilePath
));
856 IPOP3Callback_AddRef(pCallback
);
857 This
->InetTransport
.pCallback
= (ITransportCallback
*)pCallback
;
858 This
->InetTransport
.fInitialised
= TRUE
;
863 static HRESULT WINAPI
POP3Transport_MarkItem(IPOP3Transport
*iface
, POP3MARKTYPE marktype
,
864 DWORD dwPopId
, boolean fMarked
)
866 FIXME("(%u, %u, %d)\n", marktype
, dwPopId
, fMarked
);
870 static HRESULT WINAPI
POP3Transport_CommandAUTH(IPOP3Transport
*iface
, LPSTR pszAuthType
)
872 FIXME("(%s)\n", pszAuthType
);
876 static HRESULT WINAPI
POP3Transport_CommandUSER(IPOP3Transport
*iface
, LPSTR username
)
878 static char user
[] = "USER ";
879 POP3Transport
*This
= (POP3Transport
*)iface
;
883 TRACE("(%s)\n", username
);
885 len
= sizeof(user
) + strlen(username
) + 2; /* "\r\n" */
886 if (!(command
= HeapAlloc(GetProcessHeap(), 0, len
))) return S_FALSE
;
888 strcpy(command
, user
);
889 strcat(command
, username
);
890 strcat(command
, "\r\n");
892 init_parser(This
, POP3_USER
, POP3_NONE
);
893 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvUSERResp
);
895 HeapFree(GetProcessHeap(), 0, command
);
899 static HRESULT WINAPI
POP3Transport_CommandPASS(IPOP3Transport
*iface
, LPSTR password
)
901 static char pass
[] = "PASS ";
902 POP3Transport
*This
= (POP3Transport
*)iface
;
906 TRACE("(%p)\n", password
);
908 len
= sizeof(pass
) + strlen(password
) + 2; /* "\r\n" */
909 if (!(command
= HeapAlloc(GetProcessHeap(), 0, len
))) return S_FALSE
;
911 strcpy(command
, pass
);
912 strcat(command
, password
);
913 strcat(command
, "\r\n");
915 init_parser(This
, POP3_PASS
, POP3_NONE
);
916 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvPASSResp
);
918 HeapFree(GetProcessHeap(), 0, command
);
922 static HRESULT WINAPI
POP3Transport_CommandLIST(
923 IPOP3Transport
*iface
, POP3CMDTYPE cmdtype
, DWORD dwPopId
)
925 static char list
[] = "LIST %u\r\n";
926 static char list_all
[] = "LIST\r\n";
927 POP3Transport
*This
= (POP3Transport
*)iface
;
931 TRACE("(%u, %u)\n", cmdtype
, dwPopId
);
935 len
= sizeof(list
) + 10 + 2; /* "4294967296" + "\r\n" */
936 if (!(command
= HeapAlloc(GetProcessHeap(), 0, len
))) return S_FALSE
;
937 sprintf(command
, list
, dwPopId
);
939 else command
= list_all
;
941 init_parser(This
, POP3_LIST
, cmdtype
);
942 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvLISTResp
);
944 if (dwPopId
) HeapFree(GetProcessHeap(), 0, command
);
948 static HRESULT WINAPI
POP3Transport_CommandTOP(
949 IPOP3Transport
*iface
, POP3CMDTYPE cmdtype
, DWORD dwPopId
, DWORD cPreviewLines
)
951 static char top
[] = "TOP %u %u\r\n";
952 POP3Transport
*This
= (POP3Transport
*)iface
;
956 TRACE("(%u, %u, %u)\n", cmdtype
, dwPopId
, cPreviewLines
);
958 len
= sizeof(top
) + 20 + 2; /* 2 * "4294967296" + "\r\n" */
959 if (!(command
= HeapAlloc(GetProcessHeap(), 0, len
))) return S_FALSE
;
960 sprintf(command
, top
, dwPopId
, cPreviewLines
);
962 This
->preview_lines
= cPreviewLines
;
963 init_parser(This
, POP3_TOP
, cmdtype
);
964 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvTOPResp
);
966 HeapFree(GetProcessHeap(), 0, command
);
970 static HRESULT WINAPI
POP3Transport_CommandQUIT(IPOP3Transport
*iface
)
972 static char command
[] = "QUIT\r\n";
973 POP3Transport
*This
= (POP3Transport
*)iface
;
977 InternetTransport_ChangeStatus(&This
->InetTransport
, IXP_DISCONNECTING
);
979 init_parser(This
, POP3_QUIT
, POP3_NONE
);
980 return InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvQUITResp
);
983 static HRESULT WINAPI
POP3Transport_CommandSTAT(IPOP3Transport
*iface
)
985 static char stat
[] = "STAT\r\n";
986 POP3Transport
*This
= (POP3Transport
*)iface
;
990 init_parser(This
, POP3_STAT
, POP3_NONE
);
991 InternetTransport_DoCommand(&This
->InetTransport
, stat
, POP3Transport_CallbackRecvSTATResp
);
995 static HRESULT WINAPI
POP3Transport_CommandNOOP(IPOP3Transport
*iface
)
997 static char noop
[] = "NOOP\r\n";
998 POP3Transport
*This
= (POP3Transport
*)iface
;
1002 init_parser(This
, POP3_NOOP
, POP3_NONE
);
1003 InternetTransport_DoCommand(&This
->InetTransport
, noop
, POP3Transport_CallbackRecvNOOPResp
);
1007 static HRESULT WINAPI
POP3Transport_CommandRSET(IPOP3Transport
*iface
)
1009 static char rset
[] = "RSET\r\n";
1010 POP3Transport
*This
= (POP3Transport
*)iface
;
1014 init_parser(This
, POP3_RSET
, POP3_NONE
);
1015 InternetTransport_DoCommand(&This
->InetTransport
, rset
, POP3Transport_CallbackRecvRSETResp
);
1019 static HRESULT WINAPI
POP3Transport_CommandUIDL(
1020 IPOP3Transport
*iface
, POP3CMDTYPE cmdtype
, DWORD dwPopId
)
1022 static char uidl
[] = "UIDL %u\r\n";
1023 static char uidl_all
[] = "UIDL\r\n";
1024 POP3Transport
*This
= (POP3Transport
*)iface
;
1028 TRACE("(%u, %u)\n", cmdtype
, dwPopId
);
1032 len
= sizeof(uidl
) + 10 + 2; /* "4294967296" + "\r\n" */
1033 if (!(command
= HeapAlloc(GetProcessHeap(), 0, len
))) return S_FALSE
;
1034 sprintf(command
, uidl
, dwPopId
);
1036 else command
= uidl_all
;
1038 init_parser(This
, POP3_UIDL
, cmdtype
);
1039 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvUIDLResp
);
1041 if (dwPopId
) HeapFree(GetProcessHeap(), 0, command
);
1045 static HRESULT WINAPI
POP3Transport_CommandDELE(
1046 IPOP3Transport
*iface
, POP3CMDTYPE cmdtype
, DWORD dwPopId
)
1048 static char dele
[] = "DELE %u\r\n";
1049 POP3Transport
*This
= (POP3Transport
*)iface
;
1053 TRACE("(%u, %u)\n", cmdtype
, dwPopId
);
1055 len
= sizeof(dele
) + 10 + 2; /* "4294967296" + "\r\n" */
1056 if (!(command
= HeapAlloc(GetProcessHeap(), 0, len
))) return S_FALSE
;
1057 sprintf(command
, dele
, dwPopId
);
1059 init_parser(This
, POP3_DELE
, cmdtype
);
1060 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvDELEResp
);
1062 HeapFree(GetProcessHeap(), 0, command
);
1066 static HRESULT WINAPI
POP3Transport_CommandRETR(
1067 IPOP3Transport
*iface
, POP3CMDTYPE cmdtype
, DWORD dwPopId
)
1069 static char retr
[] = "RETR %u\r\n";
1070 POP3Transport
*This
= (POP3Transport
*)iface
;
1074 TRACE("(%u, %u)\n", cmdtype
, dwPopId
);
1076 len
= sizeof(retr
) + 10 + 2; /* "4294967296" + "\r\n" */
1077 if (!(command
= HeapAlloc(GetProcessHeap(), 0, len
))) return S_FALSE
;
1078 sprintf(command
, retr
, dwPopId
);
1080 init_parser(This
, POP3_RETR
, cmdtype
);
1081 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvRETRResp
);
1083 HeapFree(GetProcessHeap(), 0, command
);
1087 static const IPOP3TransportVtbl POP3TransportVtbl
=
1089 POP3Transport_QueryInterface
,
1090 POP3Transport_AddRef
,
1091 POP3Transport_Release
,
1092 POP3Transport_GetServerInfo
,
1093 POP3Transport_GetIXPType
,
1094 POP3Transport_IsState
,
1095 POP3Transport_InetServerFromAccount
,
1096 POP3Transport_Connect
,
1097 POP3Transport_HandsOffCallback
,
1098 POP3Transport_Disconnect
,
1099 POP3Transport_DropConnection
,
1100 POP3Transport_GetStatus
,
1101 POP3Transport_InitNew
,
1102 POP3Transport_MarkItem
,
1103 POP3Transport_CommandAUTH
,
1104 POP3Transport_CommandUSER
,
1105 POP3Transport_CommandPASS
,
1106 POP3Transport_CommandLIST
,
1107 POP3Transport_CommandTOP
,
1108 POP3Transport_CommandQUIT
,
1109 POP3Transport_CommandSTAT
,
1110 POP3Transport_CommandNOOP
,
1111 POP3Transport_CommandRSET
,
1112 POP3Transport_CommandUIDL
,
1113 POP3Transport_CommandDELE
,
1114 POP3Transport_CommandRETR
1117 HRESULT WINAPI
CreatePOP3Transport(IPOP3Transport
**ppTransport
)
1120 POP3Transport
*This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
1122 return E_OUTOFMEMORY
;
1124 This
->InetTransport
.u
.vtblPOP3
= &POP3TransportVtbl
;
1126 hr
= InternetTransport_Init(&This
->InetTransport
);
1129 HeapFree(GetProcessHeap(), 0, This
);
1133 *ppTransport
= (IPOP3Transport
*)&This
->InetTransport
.u
.vtblPOP3
;
1134 IPOP3Transport_AddRef(*ppTransport
);
1139 static HRESULT WINAPI
POP3TransportCF_QueryInterface(LPCLASSFACTORY iface
,
1140 REFIID riid
, LPVOID
*ppv
)
1143 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IClassFactory
))
1146 IUnknown_AddRef(iface
);
1149 return E_NOINTERFACE
;
1152 static ULONG WINAPI
POP3TransportCF_AddRef(LPCLASSFACTORY iface
)
1154 return 2; /* non-heap based object */
1157 static ULONG WINAPI
POP3TransportCF_Release(LPCLASSFACTORY iface
)
1159 return 1; /* non-heap based object */
1162 static HRESULT WINAPI
POP3TransportCF_CreateInstance(LPCLASSFACTORY iface
,
1163 LPUNKNOWN pUnk
, REFIID riid
, LPVOID
*ppv
)
1166 IPOP3Transport
*pPop3Transport
;
1168 TRACE("(%p, %s, %p)\n", pUnk
, debugstr_guid(riid
), ppv
);
1173 return CLASS_E_NOAGGREGATION
;
1175 hr
= CreatePOP3Transport(&pPop3Transport
);
1179 hr
= IPOP3Transport_QueryInterface(pPop3Transport
, riid
, ppv
);
1180 IPOP3Transport_Release(pPop3Transport
);
1185 static HRESULT WINAPI
POP3TransportCF_LockServer(LPCLASSFACTORY iface
, BOOL fLock
)
1187 FIXME("(%d)\n",fLock
);
1191 static const IClassFactoryVtbl POP3TransportCFVtbl
=
1193 POP3TransportCF_QueryInterface
,
1194 POP3TransportCF_AddRef
,
1195 POP3TransportCF_Release
,
1196 POP3TransportCF_CreateInstance
,
1197 POP3TransportCF_LockServer
1199 static const IClassFactoryVtbl
*POP3TransportCF
= &POP3TransportCFVtbl
;
1201 HRESULT
POP3TransportCF_Create(REFIID riid
, LPVOID
*ppv
)
1203 return IClassFactory_QueryInterface((IClassFactory
*)&POP3TransportCF
, riid
, ppv
);