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 #include "inetcomm_private.h"
33 InternetTransport InetTransport
;
39 enum parse_state state
;
45 static HRESULT
parse_response(POP3Transport
*This
)
50 if (strlen(This
->response
) < 3)
52 WARN("parse error\n");
53 This
->state
= STATE_DONE
;
56 if (!memcmp(This
->response
, "+OK", 3))
58 This
->ptr
= This
->response
+ 3;
59 This
->state
= STATE_OK
;
62 This
->state
= STATE_DONE
;
69 static HRESULT
parse_uidl_response(POP3Transport
*This
, POP3UIDL
*uidl
)
78 if (This
->type
== POP3CMD_GET_POPID
)
80 if ((p
= strchr(This
->ptr
, ' ')))
82 while (*p
== ' ') p
++;
83 sscanf(p
, "%u", &uidl
->dwPopId
);
84 if ((p
= strchr(p
, ' ')))
86 while (*p
== ' ') p
++;
88 This
->valid_info
= TRUE
;
91 This
->state
= STATE_DONE
;
94 This
->state
= STATE_MULTILINE
;
98 if (This
->response
[0] == '.' && !This
->response
[1])
100 This
->valid_info
= FALSE
;
101 This
->state
= STATE_DONE
;
104 sscanf(This
->response
, "%u", &uidl
->dwPopId
);
105 if ((p
= strchr(This
->response
, ' ')))
107 while (*p
== ' ') p
++;
109 This
->valid_info
= TRUE
;
114 WARN("parse error\n");
115 This
->state
= STATE_DONE
;
120 static HRESULT
parse_stat_response(POP3Transport
*This
, POP3STAT
*stat
)
125 stat
->cbMessages
= 0;
129 if ((p
= strchr(This
->ptr
, ' ')))
131 while (*p
== ' ') p
++;
132 sscanf(p
, "%u %u", &stat
->cMessages
, &stat
->cbMessages
);
133 This
->valid_info
= TRUE
;
134 This
->state
= STATE_DONE
;
139 WARN("parse error\n");
140 This
->state
= STATE_DONE
;
145 static HRESULT
parse_list_response(POP3Transport
*This
, POP3LIST
*list
)
154 if (This
->type
== POP3CMD_GET_POPID
)
156 if ((p
= strchr(This
->ptr
, ' ')))
158 while (*p
== ' ') p
++;
159 sscanf(p
, "%u %u", &list
->dwPopId
, &list
->cbSize
);
160 This
->valid_info
= TRUE
;
162 This
->state
= STATE_DONE
;
165 This
->state
= STATE_MULTILINE
;
168 case STATE_MULTILINE
:
169 if (This
->response
[0] == '.' && !This
->response
[1])
171 This
->valid_info
= FALSE
;
172 This
->state
= STATE_DONE
;
175 sscanf(This
->response
, "%u", &list
->dwPopId
);
176 if ((p
= strchr(This
->response
, ' ')))
178 while (*p
== ' ') p
++;
179 sscanf(p
, "%u", &list
->cbSize
);
180 This
->valid_info
= TRUE
;
185 WARN("parse error\n");
186 This
->state
= STATE_DONE
;
191 static HRESULT
parse_dele_response(POP3Transport
*This
, DWORD
*dwPopId
)
196 *dwPopId
= 0; /* FIXME */
197 This
->state
= STATE_DONE
;
201 WARN("parse error\n");
202 This
->state
= STATE_DONE
;
207 static HRESULT
parse_retr_response(POP3Transport
*This
, POP3RETR
*retr
)
212 retr
->fHeader
= FALSE
;
214 retr
->dwPopId
= This
->msgid
;
216 retr
->pszLines
= This
->response
;
219 This
->state
= STATE_MULTILINE
;
220 This
->valid_info
= FALSE
;
223 case STATE_MULTILINE
:
227 if (This
->response
[0] == '.' && !This
->response
[1])
229 retr
->cbLines
= retr
->cbSoFar
;
230 This
->state
= STATE_DONE
;
233 retr
->fHeader
= TRUE
;
234 if (!This
->response
[0]) retr
->fBody
= TRUE
;
236 len
= strlen(This
->response
);
237 retr
->cbSoFar
+= len
;
238 retr
->pszLines
= This
->response
;
241 This
->valid_info
= TRUE
;
246 WARN("parse error\n");
247 This
->state
= STATE_DONE
;
252 static HRESULT
parse_top_response(POP3Transport
*This
, POP3TOP
*top
)
257 top
->fHeader
= FALSE
;
259 top
->dwPopId
= This
->msgid
;
260 top
->cPreviewLines
= This
->preview_lines
;
262 top
->pszLines
= This
->response
;
265 This
->state
= STATE_MULTILINE
;
266 This
->valid_info
= FALSE
;
269 case STATE_MULTILINE
:
273 if (This
->response
[0] == '.' && !This
->response
[1])
275 top
->cbLines
= top
->cbSoFar
;
276 This
->state
= STATE_DONE
;
280 if (!This
->response
[0]) top
->fBody
= TRUE
;
282 len
= strlen(This
->response
);
284 top
->pszLines
= This
->response
;
287 This
->valid_info
= TRUE
;
292 WARN("parse error\n");
293 This
->state
= STATE_DONE
;
298 static void init_parser(POP3Transport
*This
, POP3COMMAND command
)
300 This
->state
= STATE_NONE
;
301 This
->command
= command
;
304 static HRESULT
POP3Transport_ParseResponse(POP3Transport
*This
, char *pszResponse
, POP3RESPONSE
*pResponse
)
308 TRACE("response: %s\n", debugstr_a(pszResponse
));
310 This
->response
= pszResponse
;
311 This
->valid_info
= FALSE
;
312 TRACE("state %u\n", This
->state
);
314 if (SUCCEEDED((hr
= parse_response(This
))))
316 switch (This
->command
)
318 case POP3_UIDL
: hr
= parse_uidl_response(This
, &pResponse
->u
.rUidlInfo
); break;
319 case POP3_STAT
: hr
= parse_stat_response(This
, &pResponse
->u
.rStatInfo
); break;
320 case POP3_LIST
: hr
= parse_list_response(This
, &pResponse
->u
.rListInfo
); break;
321 case POP3_DELE
: hr
= parse_dele_response(This
, &pResponse
->u
.dwPopId
); break;
322 case POP3_RETR
: hr
= parse_retr_response(This
, &pResponse
->u
.rRetrInfo
); break;
323 case POP3_TOP
: hr
= parse_top_response(This
, &pResponse
->u
.rTopInfo
); break;
325 This
->state
= STATE_DONE
;
329 pResponse
->command
= This
->command
;
330 pResponse
->fDone
= (This
->state
== STATE_DONE
);
331 pResponse
->fValidInfo
= This
->valid_info
;
332 pResponse
->rIxpResult
.hrResult
= hr
;
333 pResponse
->rIxpResult
.pszResponse
= pszResponse
;
334 pResponse
->rIxpResult
.uiServerError
= 0;
335 pResponse
->rIxpResult
.hrServerError
= pResponse
->rIxpResult
.hrResult
;
336 pResponse
->rIxpResult
.dwSocketError
= WSAGetLastError();
337 pResponse
->rIxpResult
.pszProblem
= NULL
;
338 pResponse
->pTransport
= (IPOP3Transport
*)&This
->InetTransport
.u
.vtblPOP3
;
340 if (This
->InetTransport
.pCallback
&& This
->InetTransport
.fCommandLogging
)
342 ITransportCallback_OnCommand(This
->InetTransport
.pCallback
, CMD_RESP
,
343 pResponse
->rIxpResult
.pszResponse
, pResponse
->rIxpResult
.hrServerError
,
344 (IInternetTransport
*)&This
->InetTransport
.u
.vtbl
);
349 static void POP3Transport_CallbackProcessDELEResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
351 POP3Transport
*This
= (POP3Transport
*)iface
;
352 POP3RESPONSE response
;
357 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
360 /* FIXME: handle error */
364 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
367 static void POP3Transport_CallbackRecvDELEResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
369 POP3Transport
*This
= (POP3Transport
*)iface
;
372 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessDELEResp
);
375 static void POP3Transport_CallbackProcessNOOPResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
377 POP3Transport
*This
= (POP3Transport
*)iface
;
378 POP3RESPONSE response
;
383 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
386 /* FIXME: handle error */
390 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
393 static void POP3Transport_CallbackRecvNOOPResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
395 POP3Transport
*This
= (POP3Transport
*)iface
;
398 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessNOOPResp
);
401 static void POP3Transport_CallbackProcessRSETResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
403 POP3Transport
*This
= (POP3Transport
*)iface
;
404 POP3RESPONSE response
;
409 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
412 /* FIXME: handle error */
416 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
419 static void POP3Transport_CallbackRecvRSETResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
421 POP3Transport
*This
= (POP3Transport
*)iface
;
424 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessRSETResp
);
427 static void POP3Transport_CallbackProcessRETRResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
429 POP3Transport
*This
= (POP3Transport
*)iface
;
430 POP3RESPONSE response
;
435 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
438 /* FIXME: handle error */
442 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
446 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessRETRResp
);
450 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
453 static void POP3Transport_CallbackRecvRETRResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
455 POP3Transport
*This
= (POP3Transport
*)iface
;
458 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessRETRResp
);
461 static void POP3Transport_CallbackProcessTOPResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
463 POP3Transport
*This
= (POP3Transport
*)iface
;
464 POP3RESPONSE response
;
469 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
472 /* FIXME: handle error */
476 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
480 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessTOPResp
);
484 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
487 static void POP3Transport_CallbackRecvTOPResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
489 POP3Transport
*This
= (POP3Transport
*)iface
;
492 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessTOPResp
);
495 static void POP3Transport_CallbackProcessLISTResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
497 POP3Transport
*This
= (POP3Transport
*)iface
;
498 POP3RESPONSE response
;
503 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
506 /* FIXME: handle error */
510 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
514 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessLISTResp
);
518 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
521 static void POP3Transport_CallbackRecvLISTResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
523 POP3Transport
*This
= (POP3Transport
*)iface
;
526 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessLISTResp
);
529 static void POP3Transport_CallbackProcessUIDLResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
531 POP3Transport
*This
= (POP3Transport
*)iface
;
532 POP3RESPONSE response
;
537 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
540 /* FIXME: handle error */
544 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
548 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessUIDLResp
);
552 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
555 static void POP3Transport_CallbackRecvUIDLResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
557 POP3Transport
*This
= (POP3Transport
*)iface
;
560 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessUIDLResp
);
563 static void POP3Transport_CallbackProcessSTATResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
565 POP3Transport
*This
= (POP3Transport
*)iface
;
566 POP3RESPONSE response
;
571 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
574 /* FIXME: handle error */
578 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
581 static void POP3Transport_CallbackRecvSTATResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
583 POP3Transport
*This
= (POP3Transport
*)iface
;
586 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessSTATResp
);
589 static void POP3Transport_CallbackProcessPASSResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
591 POP3Transport
*This
= (POP3Transport
*)iface
;
592 POP3RESPONSE response
;
597 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
600 /* FIXME: handle error */
604 InternetTransport_ChangeStatus(&This
->InetTransport
, IXP_AUTHORIZED
);
605 InternetTransport_ChangeStatus(&This
->InetTransport
, IXP_CONNECTED
);
607 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
610 static void POP3Transport_CallbackRecvPASSResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
612 POP3Transport
*This
= (POP3Transport
*)iface
;
615 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessPASSResp
);
618 static void POP3Transport_CallbackProcessUSERResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
620 static const char pass
[] = "PASS ";
621 POP3Transport
*This
= (POP3Transport
*)iface
;
622 POP3RESPONSE response
;
629 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
632 /* FIXME: handle error */
636 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
638 len
= sizeof(pass
) + strlen(This
->InetTransport
.ServerInfo
.szPassword
) + 2; /* "\r\n" */
639 command
= HeapAlloc(GetProcessHeap(), 0, len
);
641 strcpy(command
, pass
);
642 strcat(command
, This
->InetTransport
.ServerInfo
.szPassword
);
643 strcat(command
, "\r\n");
645 init_parser(This
, POP3_PASS
);
647 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvPASSResp
);
648 HeapFree(GetProcessHeap(), 0, command
);
651 static void POP3Transport_CallbackRecvUSERResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
653 POP3Transport
*This
= (POP3Transport
*)iface
;
656 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessUSERResp
);
659 static void POP3Transport_CallbackSendUSERCmd(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
661 static const char user
[] = "USER ";
662 POP3Transport
*This
= (POP3Transport
*)iface
;
668 len
= sizeof(user
) + strlen(This
->InetTransport
.ServerInfo
.szUserName
) + 2; /* "\r\n" */
669 command
= HeapAlloc(GetProcessHeap(), 0, len
);
671 strcpy(command
, user
);
672 strcat(command
, This
->InetTransport
.ServerInfo
.szUserName
);
673 strcat(command
, "\r\n");
674 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvUSERResp
);
676 HeapFree(GetProcessHeap(), 0, command
);
679 static void POP3Transport_CallbackProcessQUITResponse(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
681 POP3Transport
*This
= (POP3Transport
*)iface
;
682 POP3RESPONSE response
;
685 TRACE("%s\n", debugstr_an(pBuffer
, cbBuffer
));
687 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
690 /* FIXME: handle error */
694 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
695 InternetTransport_DropConnection(&This
->InetTransport
);
698 static void POP3Transport_CallbackRecvQUITResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
700 POP3Transport
*This
= (POP3Transport
*)iface
;
703 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessQUITResponse
);
706 static HRESULT WINAPI
POP3Transport_QueryInterface(IPOP3Transport
*iface
, REFIID riid
, void **ppv
)
708 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
710 if (IsEqualIID(riid
, &IID_IUnknown
) ||
711 IsEqualIID(riid
, &IID_IInternetTransport
) ||
712 IsEqualIID(riid
, &IID_IPOP3Transport
))
715 IPOP3Transport_AddRef(iface
);
719 FIXME("no interface for %s\n", debugstr_guid(riid
));
720 return E_NOINTERFACE
;
723 static ULONG WINAPI
POP3Transport_AddRef(IPOP3Transport
*iface
)
725 POP3Transport
*This
= (POP3Transport
*)iface
;
726 return InterlockedIncrement((LONG
*)&This
->refs
);
729 static ULONG WINAPI
POP3Transport_Release(IPOP3Transport
*iface
)
731 POP3Transport
*This
= (POP3Transport
*)iface
;
732 ULONG refs
= InterlockedDecrement((LONG
*)&This
->refs
);
735 TRACE("destroying %p\n", This
);
736 if (This
->InetTransport
.Status
!= IXP_DISCONNECTED
)
737 InternetTransport_DropConnection(&This
->InetTransport
);
738 if (This
->InetTransport
.pCallback
) ITransportCallback_Release(This
->InetTransport
.pCallback
);
739 HeapFree(GetProcessHeap(), 0, This
);
744 static HRESULT WINAPI
POP3Transport_GetServerInfo(IPOP3Transport
*iface
,
745 LPINETSERVER pInetServer
)
747 POP3Transport
*This
= (POP3Transport
*)iface
;
749 TRACE("(%p)\n", pInetServer
);
750 return InternetTransport_GetServerInfo(&This
->InetTransport
, pInetServer
);
753 static IXPTYPE WINAPI
POP3Transport_GetIXPType(IPOP3Transport
*iface
)
759 static HRESULT WINAPI
POP3Transport_IsState(IPOP3Transport
*iface
, IXPISSTATE isstate
)
761 FIXME("(%u)\n", isstate
);
765 static HRESULT WINAPI
POP3Transport_InetServerFromAccount(
766 IPOP3Transport
*iface
, IImnAccount
*pAccount
, LPINETSERVER pInetServer
)
768 POP3Transport
*This
= (POP3Transport
*)iface
;
770 TRACE("(%p, %p)\n", pAccount
, pInetServer
);
771 return InternetTransport_InetServerFromAccount(&This
->InetTransport
, pAccount
, pInetServer
);
774 static HRESULT WINAPI
POP3Transport_Connect(IPOP3Transport
*iface
,
775 LPINETSERVER pInetServer
, boolean fAuthenticate
, boolean fCommandLogging
)
777 POP3Transport
*This
= (POP3Transport
*)iface
;
780 TRACE("(%p, %s, %s)\n", pInetServer
, fAuthenticate
? "TRUE" : "FALSE", fCommandLogging
? "TRUE" : "FALSE");
782 hr
= InternetTransport_Connect(&This
->InetTransport
, pInetServer
, fAuthenticate
, fCommandLogging
);
786 init_parser(This
, POP3_USER
);
787 return InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackSendUSERCmd
);
790 static HRESULT WINAPI
POP3Transport_HandsOffCallback(IPOP3Transport
*iface
)
792 POP3Transport
*This
= (POP3Transport
*)iface
;
795 return InternetTransport_HandsOffCallback(&This
->InetTransport
);
798 static HRESULT WINAPI
POP3Transport_Disconnect(IPOP3Transport
*iface
)
801 return IPOP3Transport_CommandQUIT(iface
);
804 static HRESULT WINAPI
POP3Transport_DropConnection(IPOP3Transport
*iface
)
806 POP3Transport
*This
= (POP3Transport
*)iface
;
809 return InternetTransport_DropConnection(&This
->InetTransport
);
812 static HRESULT WINAPI
POP3Transport_GetStatus(IPOP3Transport
*iface
,
813 IXPSTATUS
*pCurrentStatus
)
815 POP3Transport
*This
= (POP3Transport
*)iface
;
818 return InternetTransport_GetStatus(&This
->InetTransport
, pCurrentStatus
);
821 static HRESULT WINAPI
POP3Transport_InitNew(IPOP3Transport
*iface
,
822 LPSTR pszLogFilePath
, IPOP3Callback
*pCallback
)
824 POP3Transport
*This
= (POP3Transport
*)iface
;
826 TRACE("(%s, %p)\n", debugstr_a(pszLogFilePath
), pCallback
);
832 FIXME("not using log file of %s, use Wine debug logging instead\n",
833 debugstr_a(pszLogFilePath
));
835 IPOP3Callback_AddRef(pCallback
);
836 This
->InetTransport
.pCallback
= (ITransportCallback
*)pCallback
;
837 This
->InetTransport
.fInitialised
= TRUE
;
842 static HRESULT WINAPI
POP3Transport_MarkItem(IPOP3Transport
*iface
, POP3MARKTYPE marktype
,
843 DWORD dwPopId
, boolean fMarked
)
845 FIXME("(%u, %u, %d)\n", marktype
, dwPopId
, fMarked
);
849 static HRESULT WINAPI
POP3Transport_CommandAUTH(IPOP3Transport
*iface
, LPSTR pszAuthType
)
851 FIXME("(%s)\n", pszAuthType
);
855 static HRESULT WINAPI
POP3Transport_CommandUSER(IPOP3Transport
*iface
, LPSTR username
)
857 static const char user
[] = "USER ";
858 POP3Transport
*This
= (POP3Transport
*)iface
;
862 TRACE("(%s)\n", username
);
864 len
= sizeof(user
) + strlen(username
) + 2; /* "\r\n" */
865 if (!(command
= HeapAlloc(GetProcessHeap(), 0, len
))) return S_FALSE
;
867 strcpy(command
, user
);
868 strcat(command
, username
);
869 strcat(command
, "\r\n");
871 init_parser(This
, POP3_USER
);
872 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvUSERResp
);
874 HeapFree(GetProcessHeap(), 0, command
);
878 static HRESULT WINAPI
POP3Transport_CommandPASS(IPOP3Transport
*iface
, LPSTR password
)
880 static const char pass
[] = "PASS ";
881 POP3Transport
*This
= (POP3Transport
*)iface
;
885 TRACE("(%p)\n", password
);
887 len
= sizeof(pass
) + strlen(password
) + 2; /* "\r\n" */
888 if (!(command
= HeapAlloc(GetProcessHeap(), 0, len
))) return S_FALSE
;
890 strcpy(command
, pass
);
891 strcat(command
, password
);
892 strcat(command
, "\r\n");
894 init_parser(This
, POP3_PASS
);
895 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvPASSResp
);
897 HeapFree(GetProcessHeap(), 0, command
);
901 static HRESULT WINAPI
POP3Transport_CommandLIST(
902 IPOP3Transport
*iface
, POP3CMDTYPE cmdtype
, DWORD dwPopId
)
904 static const char list
[] = "LIST %u\r\n";
905 static char list_all
[] = "LIST\r\n";
906 POP3Transport
*This
= (POP3Transport
*)iface
;
910 TRACE("(%u, %u)\n", cmdtype
, dwPopId
);
914 len
= sizeof(list
) + 10 + 2; /* "4294967296" + "\r\n" */
915 if (!(command
= HeapAlloc(GetProcessHeap(), 0, len
))) return S_FALSE
;
916 sprintf(command
, list
, dwPopId
);
918 else command
= list_all
;
920 init_parser(This
, POP3_LIST
);
921 This
->type
= cmdtype
;
922 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvLISTResp
);
924 if (dwPopId
) HeapFree(GetProcessHeap(), 0, command
);
928 static HRESULT WINAPI
POP3Transport_CommandTOP(
929 IPOP3Transport
*iface
, POP3CMDTYPE cmdtype
, DWORD dwPopId
, DWORD cPreviewLines
)
931 static const char top
[] = "TOP %u %u\r\n";
932 POP3Transport
*This
= (POP3Transport
*)iface
;
936 TRACE("(%u, %u, %u)\n", cmdtype
, dwPopId
, cPreviewLines
);
938 len
= sizeof(top
) + 20 + 2; /* 2 * "4294967296" + "\r\n" */
939 if (!(command
= HeapAlloc(GetProcessHeap(), 0, len
))) return S_FALSE
;
940 sprintf(command
, top
, dwPopId
, cPreviewLines
);
942 This
->preview_lines
= cPreviewLines
;
943 init_parser(This
, POP3_TOP
);
944 This
->type
= cmdtype
;
945 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvTOPResp
);
947 HeapFree(GetProcessHeap(), 0, command
);
951 static HRESULT WINAPI
POP3Transport_CommandQUIT(IPOP3Transport
*iface
)
953 static const char command
[] = "QUIT\r\n";
954 POP3Transport
*This
= (POP3Transport
*)iface
;
958 InternetTransport_ChangeStatus(&This
->InetTransport
, IXP_DISCONNECTING
);
960 init_parser(This
, POP3_QUIT
);
961 return InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvQUITResp
);
964 static HRESULT WINAPI
POP3Transport_CommandSTAT(IPOP3Transport
*iface
)
966 static const char stat
[] = "STAT\r\n";
967 POP3Transport
*This
= (POP3Transport
*)iface
;
971 init_parser(This
, POP3_STAT
);
972 InternetTransport_DoCommand(&This
->InetTransport
, stat
, POP3Transport_CallbackRecvSTATResp
);
976 static HRESULT WINAPI
POP3Transport_CommandNOOP(IPOP3Transport
*iface
)
978 static const char noop
[] = "NOOP\r\n";
979 POP3Transport
*This
= (POP3Transport
*)iface
;
983 init_parser(This
, POP3_NOOP
);
984 InternetTransport_DoCommand(&This
->InetTransport
, noop
, POP3Transport_CallbackRecvNOOPResp
);
988 static HRESULT WINAPI
POP3Transport_CommandRSET(IPOP3Transport
*iface
)
990 static const char rset
[] = "RSET\r\n";
991 POP3Transport
*This
= (POP3Transport
*)iface
;
995 init_parser(This
, POP3_RSET
);
996 InternetTransport_DoCommand(&This
->InetTransport
, rset
, POP3Transport_CallbackRecvRSETResp
);
1000 static HRESULT WINAPI
POP3Transport_CommandUIDL(
1001 IPOP3Transport
*iface
, POP3CMDTYPE cmdtype
, DWORD dwPopId
)
1003 static const char uidl
[] = "UIDL %u\r\n";
1004 static char uidl_all
[] = "UIDL\r\n";
1005 POP3Transport
*This
= (POP3Transport
*)iface
;
1009 TRACE("(%u, %u)\n", cmdtype
, dwPopId
);
1013 len
= sizeof(uidl
) + 10 + 2; /* "4294967296" + "\r\n" */
1014 if (!(command
= HeapAlloc(GetProcessHeap(), 0, len
))) return S_FALSE
;
1015 sprintf(command
, uidl
, dwPopId
);
1017 else command
= uidl_all
;
1019 init_parser(This
, POP3_UIDL
);
1020 This
->type
= cmdtype
;
1021 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvUIDLResp
);
1023 if (dwPopId
) HeapFree(GetProcessHeap(), 0, command
);
1027 static HRESULT WINAPI
POP3Transport_CommandDELE(
1028 IPOP3Transport
*iface
, POP3CMDTYPE cmdtype
, DWORD dwPopId
)
1030 static const char dele
[] = "DELE %u\r\n";
1031 POP3Transport
*This
= (POP3Transport
*)iface
;
1035 TRACE("(%u, %u)\n", cmdtype
, dwPopId
);
1037 len
= sizeof(dele
) + 10 + 2; /* "4294967296" + "\r\n" */
1038 if (!(command
= HeapAlloc(GetProcessHeap(), 0, len
))) return S_FALSE
;
1039 sprintf(command
, dele
, dwPopId
);
1041 init_parser(This
, POP3_DELE
);
1042 This
->type
= cmdtype
;
1043 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvDELEResp
);
1045 HeapFree(GetProcessHeap(), 0, command
);
1049 static HRESULT WINAPI
POP3Transport_CommandRETR(
1050 IPOP3Transport
*iface
, POP3CMDTYPE cmdtype
, DWORD dwPopId
)
1052 static const char retr
[] = "RETR %u\r\n";
1053 POP3Transport
*This
= (POP3Transport
*)iface
;
1057 TRACE("(%u, %u)\n", cmdtype
, dwPopId
);
1059 len
= sizeof(retr
) + 10 + 2; /* "4294967296" + "\r\n" */
1060 if (!(command
= HeapAlloc(GetProcessHeap(), 0, len
))) return S_FALSE
;
1061 sprintf(command
, retr
, dwPopId
);
1063 init_parser(This
, POP3_RETR
);
1064 This
->type
= cmdtype
;
1065 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvRETRResp
);
1067 HeapFree(GetProcessHeap(), 0, command
);
1071 static const IPOP3TransportVtbl POP3TransportVtbl
=
1073 POP3Transport_QueryInterface
,
1074 POP3Transport_AddRef
,
1075 POP3Transport_Release
,
1076 POP3Transport_GetServerInfo
,
1077 POP3Transport_GetIXPType
,
1078 POP3Transport_IsState
,
1079 POP3Transport_InetServerFromAccount
,
1080 POP3Transport_Connect
,
1081 POP3Transport_HandsOffCallback
,
1082 POP3Transport_Disconnect
,
1083 POP3Transport_DropConnection
,
1084 POP3Transport_GetStatus
,
1085 POP3Transport_InitNew
,
1086 POP3Transport_MarkItem
,
1087 POP3Transport_CommandAUTH
,
1088 POP3Transport_CommandUSER
,
1089 POP3Transport_CommandPASS
,
1090 POP3Transport_CommandLIST
,
1091 POP3Transport_CommandTOP
,
1092 POP3Transport_CommandQUIT
,
1093 POP3Transport_CommandSTAT
,
1094 POP3Transport_CommandNOOP
,
1095 POP3Transport_CommandRSET
,
1096 POP3Transport_CommandUIDL
,
1097 POP3Transport_CommandDELE
,
1098 POP3Transport_CommandRETR
1101 HRESULT WINAPI
CreatePOP3Transport(IPOP3Transport
**ppTransport
)
1104 POP3Transport
*This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
1106 return E_OUTOFMEMORY
;
1108 This
->InetTransport
.u
.vtblPOP3
= &POP3TransportVtbl
;
1110 hr
= InternetTransport_Init(&This
->InetTransport
);
1113 HeapFree(GetProcessHeap(), 0, This
);
1117 *ppTransport
= (IPOP3Transport
*)&This
->InetTransport
.u
.vtblPOP3
;
1118 IPOP3Transport_AddRef(*ppTransport
);
1123 static HRESULT WINAPI
POP3TransportCF_QueryInterface(LPCLASSFACTORY iface
,
1124 REFIID riid
, LPVOID
*ppv
)
1127 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IClassFactory
))
1130 IClassFactory_AddRef(iface
);
1133 return E_NOINTERFACE
;
1136 static ULONG WINAPI
POP3TransportCF_AddRef(LPCLASSFACTORY iface
)
1138 return 2; /* non-heap based object */
1141 static ULONG WINAPI
POP3TransportCF_Release(LPCLASSFACTORY iface
)
1143 return 1; /* non-heap based object */
1146 static HRESULT WINAPI
POP3TransportCF_CreateInstance(LPCLASSFACTORY iface
,
1147 LPUNKNOWN pUnk
, REFIID riid
, LPVOID
*ppv
)
1150 IPOP3Transport
*pPop3Transport
;
1152 TRACE("(%p, %s, %p)\n", pUnk
, debugstr_guid(riid
), ppv
);
1157 return CLASS_E_NOAGGREGATION
;
1159 hr
= CreatePOP3Transport(&pPop3Transport
);
1163 hr
= IPOP3Transport_QueryInterface(pPop3Transport
, riid
, ppv
);
1164 IPOP3Transport_Release(pPop3Transport
);
1169 static HRESULT WINAPI
POP3TransportCF_LockServer(LPCLASSFACTORY iface
, BOOL fLock
)
1171 FIXME("(%d)\n",fLock
);
1175 static const IClassFactoryVtbl POP3TransportCFVtbl
=
1177 POP3TransportCF_QueryInterface
,
1178 POP3TransportCF_AddRef
,
1179 POP3TransportCF_Release
,
1180 POP3TransportCF_CreateInstance
,
1181 POP3TransportCF_LockServer
1183 static const IClassFactoryVtbl
*POP3TransportCF
= &POP3TransportCFVtbl
;
1185 HRESULT
POP3TransportCF_Create(REFIID riid
, LPVOID
*ppv
)
1187 return IClassFactory_QueryInterface((IClassFactory
*)&POP3TransportCF
, riid
, ppv
);