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
22 #define NONAMELESSUNION
33 #include "wine/debug.h"
35 #include "inetcomm_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(inetcomm
);
49 InternetTransport InetTransport
;
55 enum parse_state state
;
61 static HRESULT
parse_response(POP3Transport
*This
)
66 if (strlen(This
->response
) < 3)
68 WARN("parse error\n");
69 This
->state
= STATE_DONE
;
72 if (!memcmp(This
->response
, "+OK", 3))
74 This
->ptr
= This
->response
+ 3;
75 This
->state
= STATE_OK
;
78 This
->state
= STATE_DONE
;
85 static HRESULT
parse_uidl_response(POP3Transport
*This
, POP3UIDL
*uidl
)
94 if (This
->type
== POP3CMD_GET_POPID
)
96 if ((p
= strchr(This
->ptr
, ' ')))
98 while (*p
== ' ') p
++;
99 sscanf(p
, "%lu", &uidl
->dwPopId
);
100 if ((p
= strchr(p
, ' ')))
102 while (*p
== ' ') p
++;
104 This
->valid_info
= TRUE
;
107 This
->state
= STATE_DONE
;
110 This
->state
= STATE_MULTILINE
;
113 case STATE_MULTILINE
:
114 if (This
->response
[0] == '.' && !This
->response
[1])
116 This
->valid_info
= FALSE
;
117 This
->state
= STATE_DONE
;
120 sscanf(This
->response
, "%lu", &uidl
->dwPopId
);
121 if ((p
= strchr(This
->response
, ' ')))
123 while (*p
== ' ') p
++;
125 This
->valid_info
= TRUE
;
130 WARN("parse error\n");
131 This
->state
= STATE_DONE
;
136 static HRESULT
parse_stat_response(POP3Transport
*This
, POP3STAT
*stat
)
141 stat
->cbMessages
= 0;
145 if ((p
= strchr(This
->ptr
, ' ')))
147 while (*p
== ' ') p
++;
148 sscanf(p
, "%lu %lu", &stat
->cMessages
, &stat
->cbMessages
);
149 This
->valid_info
= TRUE
;
150 This
->state
= STATE_DONE
;
155 WARN("parse error\n");
156 This
->state
= STATE_DONE
;
161 static HRESULT
parse_list_response(POP3Transport
*This
, POP3LIST
*list
)
170 if (This
->type
== POP3CMD_GET_POPID
)
172 if ((p
= strchr(This
->ptr
, ' ')))
174 while (*p
== ' ') p
++;
175 sscanf(p
, "%lu %lu", &list
->dwPopId
, &list
->cbSize
);
176 This
->valid_info
= TRUE
;
178 This
->state
= STATE_DONE
;
181 This
->state
= STATE_MULTILINE
;
184 case STATE_MULTILINE
:
185 if (This
->response
[0] == '.' && !This
->response
[1])
187 This
->valid_info
= FALSE
;
188 This
->state
= STATE_DONE
;
191 sscanf(This
->response
, "%lu", &list
->dwPopId
);
192 if ((p
= strchr(This
->response
, ' ')))
194 while (*p
== ' ') p
++;
195 sscanf(p
, "%lu", &list
->cbSize
);
196 This
->valid_info
= TRUE
;
201 WARN("parse error\n");
202 This
->state
= STATE_DONE
;
207 static HRESULT
parse_dele_response(POP3Transport
*This
, DWORD
*dwPopId
)
212 *dwPopId
= 0; /* FIXME */
213 This
->state
= STATE_DONE
;
217 WARN("parse error\n");
218 This
->state
= STATE_DONE
;
223 static HRESULT
parse_retr_response(POP3Transport
*This
, POP3RETR
*retr
)
228 retr
->fHeader
= FALSE
;
230 retr
->dwPopId
= This
->msgid
;
232 retr
->pszLines
= This
->response
;
235 This
->state
= STATE_MULTILINE
;
236 This
->valid_info
= FALSE
;
239 case STATE_MULTILINE
:
243 if (This
->response
[0] == '.' && !This
->response
[1])
245 retr
->cbLines
= retr
->cbSoFar
;
246 This
->state
= STATE_DONE
;
249 retr
->fHeader
= TRUE
;
250 if (!This
->response
[0]) retr
->fBody
= TRUE
;
252 len
= strlen(This
->response
);
253 retr
->cbSoFar
+= len
;
254 retr
->pszLines
= This
->response
;
257 This
->valid_info
= TRUE
;
262 WARN("parse error\n");
263 This
->state
= STATE_DONE
;
268 static HRESULT
parse_top_response(POP3Transport
*This
, POP3TOP
*top
)
273 top
->fHeader
= FALSE
;
275 top
->dwPopId
= This
->msgid
;
276 top
->cPreviewLines
= This
->preview_lines
;
278 top
->pszLines
= This
->response
;
281 This
->state
= STATE_MULTILINE
;
282 This
->valid_info
= FALSE
;
285 case STATE_MULTILINE
:
289 if (This
->response
[0] == '.' && !This
->response
[1])
291 top
->cbLines
= top
->cbSoFar
;
292 This
->state
= STATE_DONE
;
296 if (!This
->response
[0]) top
->fBody
= TRUE
;
298 len
= strlen(This
->response
);
300 top
->pszLines
= This
->response
;
303 This
->valid_info
= TRUE
;
308 WARN("parse error\n");
309 This
->state
= STATE_DONE
;
314 static void init_parser(POP3Transport
*This
, POP3COMMAND command
)
316 This
->state
= STATE_NONE
;
317 This
->command
= command
;
320 static HRESULT
POP3Transport_ParseResponse(POP3Transport
*This
, char *pszResponse
, POP3RESPONSE
*pResponse
)
324 TRACE("response: %s\n", debugstr_a(pszResponse
));
326 This
->response
= pszResponse
;
327 This
->valid_info
= FALSE
;
328 TRACE("state %u\n", This
->state
);
330 if (SUCCEEDED((hr
= parse_response(This
))))
332 switch (This
->command
)
334 case POP3_UIDL
: hr
= parse_uidl_response(This
, &pResponse
->rUidlInfo
); break;
335 case POP3_STAT
: hr
= parse_stat_response(This
, &pResponse
->rStatInfo
); break;
336 case POP3_LIST
: hr
= parse_list_response(This
, &pResponse
->rListInfo
); break;
337 case POP3_DELE
: hr
= parse_dele_response(This
, &pResponse
->dwPopId
); break;
338 case POP3_RETR
: hr
= parse_retr_response(This
, &pResponse
->rRetrInfo
); break;
339 case POP3_TOP
: hr
= parse_top_response(This
, &pResponse
->rTopInfo
); break;
341 This
->state
= STATE_DONE
;
345 pResponse
->command
= This
->command
;
346 pResponse
->fDone
= (This
->state
== STATE_DONE
);
347 pResponse
->fValidInfo
= This
->valid_info
;
348 pResponse
->rIxpResult
.hrResult
= hr
;
349 pResponse
->rIxpResult
.pszResponse
= pszResponse
;
350 pResponse
->rIxpResult
.uiServerError
= 0;
351 pResponse
->rIxpResult
.hrServerError
= pResponse
->rIxpResult
.hrResult
;
352 pResponse
->rIxpResult
.dwSocketError
= WSAGetLastError();
353 pResponse
->rIxpResult
.pszProblem
= NULL
;
354 pResponse
->pTransport
= (IPOP3Transport
*)&This
->InetTransport
.u
.vtblPOP3
;
356 if (This
->InetTransport
.pCallback
&& This
->InetTransport
.fCommandLogging
)
358 ITransportCallback_OnCommand(This
->InetTransport
.pCallback
, CMD_RESP
,
359 pResponse
->rIxpResult
.pszResponse
, pResponse
->rIxpResult
.hrServerError
,
360 (IInternetTransport
*)&This
->InetTransport
.u
.vtbl
);
365 static void POP3Transport_CallbackProcessDELEResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
367 POP3Transport
*This
= (POP3Transport
*)iface
;
368 POP3RESPONSE response
;
373 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
376 /* FIXME: handle error */
380 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
383 static void POP3Transport_CallbackRecvDELEResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
385 POP3Transport
*This
= (POP3Transport
*)iface
;
388 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessDELEResp
);
391 static void POP3Transport_CallbackProcessNOOPResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
393 POP3Transport
*This
= (POP3Transport
*)iface
;
394 POP3RESPONSE response
;
399 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
402 /* FIXME: handle error */
406 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
409 static void POP3Transport_CallbackRecvNOOPResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
411 POP3Transport
*This
= (POP3Transport
*)iface
;
414 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessNOOPResp
);
417 static void POP3Transport_CallbackProcessRSETResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
419 POP3Transport
*This
= (POP3Transport
*)iface
;
420 POP3RESPONSE response
;
425 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
428 /* FIXME: handle error */
432 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
435 static void POP3Transport_CallbackRecvRSETResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
437 POP3Transport
*This
= (POP3Transport
*)iface
;
440 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessRSETResp
);
443 static void POP3Transport_CallbackProcessRETRResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
445 POP3Transport
*This
= (POP3Transport
*)iface
;
446 POP3RESPONSE response
;
451 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
454 /* FIXME: handle error */
458 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
462 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessRETRResp
);
466 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
469 static void POP3Transport_CallbackRecvRETRResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
471 POP3Transport
*This
= (POP3Transport
*)iface
;
474 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessRETRResp
);
477 static void POP3Transport_CallbackProcessTOPResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
479 POP3Transport
*This
= (POP3Transport
*)iface
;
480 POP3RESPONSE response
;
485 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
488 /* FIXME: handle error */
492 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
496 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessTOPResp
);
500 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
503 static void POP3Transport_CallbackRecvTOPResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
505 POP3Transport
*This
= (POP3Transport
*)iface
;
508 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessTOPResp
);
511 static void POP3Transport_CallbackProcessLISTResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
513 POP3Transport
*This
= (POP3Transport
*)iface
;
514 POP3RESPONSE response
;
519 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
522 /* FIXME: handle error */
526 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
530 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessLISTResp
);
534 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
537 static void POP3Transport_CallbackRecvLISTResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
539 POP3Transport
*This
= (POP3Transport
*)iface
;
542 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessLISTResp
);
545 static void POP3Transport_CallbackProcessUIDLResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
547 POP3Transport
*This
= (POP3Transport
*)iface
;
548 POP3RESPONSE response
;
553 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
556 /* FIXME: handle error */
560 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
564 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessUIDLResp
);
568 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
571 static void POP3Transport_CallbackRecvUIDLResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
573 POP3Transport
*This
= (POP3Transport
*)iface
;
576 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessUIDLResp
);
579 static void POP3Transport_CallbackProcessSTATResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
581 POP3Transport
*This
= (POP3Transport
*)iface
;
582 POP3RESPONSE response
;
587 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
590 /* FIXME: handle error */
594 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
597 static void POP3Transport_CallbackRecvSTATResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
599 POP3Transport
*This
= (POP3Transport
*)iface
;
602 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessSTATResp
);
605 static void POP3Transport_CallbackProcessPASSResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
607 POP3Transport
*This
= (POP3Transport
*)iface
;
608 POP3RESPONSE response
;
613 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
616 /* FIXME: handle error */
620 InternetTransport_ChangeStatus(&This
->InetTransport
, IXP_AUTHORIZED
);
621 InternetTransport_ChangeStatus(&This
->InetTransport
, IXP_CONNECTED
);
623 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
626 static void POP3Transport_CallbackRecvPASSResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
628 POP3Transport
*This
= (POP3Transport
*)iface
;
631 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessPASSResp
);
634 static void POP3Transport_CallbackProcessUSERResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
636 static const char pass
[] = "PASS ";
637 POP3Transport
*This
= (POP3Transport
*)iface
;
638 POP3RESPONSE response
;
645 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
648 /* FIXME: handle error */
652 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
654 len
= sizeof(pass
) + strlen(This
->InetTransport
.ServerInfo
.szPassword
) + 2; /* "\r\n" */
655 command
= HeapAlloc(GetProcessHeap(), 0, len
);
657 strcpy(command
, pass
);
658 strcat(command
, This
->InetTransport
.ServerInfo
.szPassword
);
659 strcat(command
, "\r\n");
661 init_parser(This
, POP3_PASS
);
663 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvPASSResp
);
664 HeapFree(GetProcessHeap(), 0, command
);
667 static void POP3Transport_CallbackRecvUSERResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
669 POP3Transport
*This
= (POP3Transport
*)iface
;
672 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessUSERResp
);
675 static void POP3Transport_CallbackSendUSERCmd(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
677 static const char user
[] = "USER ";
678 POP3Transport
*This
= (POP3Transport
*)iface
;
684 len
= sizeof(user
) + strlen(This
->InetTransport
.ServerInfo
.szUserName
) + 2; /* "\r\n" */
685 command
= HeapAlloc(GetProcessHeap(), 0, len
);
687 strcpy(command
, user
);
688 strcat(command
, This
->InetTransport
.ServerInfo
.szUserName
);
689 strcat(command
, "\r\n");
690 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvUSERResp
);
692 HeapFree(GetProcessHeap(), 0, command
);
695 static void POP3Transport_CallbackProcessQUITResponse(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
697 POP3Transport
*This
= (POP3Transport
*)iface
;
698 POP3RESPONSE response
;
701 TRACE("%s\n", debugstr_an(pBuffer
, cbBuffer
));
703 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
706 /* FIXME: handle error */
710 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
711 InternetTransport_DropConnection(&This
->InetTransport
);
714 static void POP3Transport_CallbackRecvQUITResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
716 POP3Transport
*This
= (POP3Transport
*)iface
;
719 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessQUITResponse
);
722 static HRESULT WINAPI
POP3Transport_QueryInterface(IPOP3Transport
*iface
, REFIID riid
, void **ppv
)
724 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
726 if (IsEqualIID(riid
, &IID_IUnknown
) ||
727 IsEqualIID(riid
, &IID_IInternetTransport
) ||
728 IsEqualIID(riid
, &IID_IPOP3Transport
))
731 IPOP3Transport_AddRef(iface
);
735 FIXME("no interface for %s\n", debugstr_guid(riid
));
736 return E_NOINTERFACE
;
739 static ULONG WINAPI
POP3Transport_AddRef(IPOP3Transport
*iface
)
741 POP3Transport
*This
= (POP3Transport
*)iface
;
742 return InterlockedIncrement((LONG
*)&This
->refs
);
745 static ULONG WINAPI
POP3Transport_Release(IPOP3Transport
*iface
)
747 POP3Transport
*This
= (POP3Transport
*)iface
;
748 ULONG refs
= InterlockedDecrement((LONG
*)&This
->refs
);
751 TRACE("destroying %p\n", This
);
752 if (This
->InetTransport
.Status
!= IXP_DISCONNECTED
)
753 InternetTransport_DropConnection(&This
->InetTransport
);
754 if (This
->InetTransport
.pCallback
) ITransportCallback_Release(This
->InetTransport
.pCallback
);
755 HeapFree(GetProcessHeap(), 0, This
);
760 static HRESULT WINAPI
POP3Transport_GetServerInfo(IPOP3Transport
*iface
,
761 LPINETSERVER pInetServer
)
763 POP3Transport
*This
= (POP3Transport
*)iface
;
765 TRACE("(%p)\n", pInetServer
);
766 return InternetTransport_GetServerInfo(&This
->InetTransport
, pInetServer
);
769 static IXPTYPE WINAPI
POP3Transport_GetIXPType(IPOP3Transport
*iface
)
775 static HRESULT WINAPI
POP3Transport_IsState(IPOP3Transport
*iface
, IXPISSTATE isstate
)
777 FIXME("(%u)\n", isstate
);
781 static HRESULT WINAPI
POP3Transport_InetServerFromAccount(
782 IPOP3Transport
*iface
, IImnAccount
*pAccount
, LPINETSERVER pInetServer
)
784 POP3Transport
*This
= (POP3Transport
*)iface
;
786 TRACE("(%p, %p)\n", pAccount
, pInetServer
);
787 return InternetTransport_InetServerFromAccount(&This
->InetTransport
, pAccount
, pInetServer
);
790 static HRESULT WINAPI
POP3Transport_Connect(IPOP3Transport
*iface
,
791 LPINETSERVER pInetServer
, boolean fAuthenticate
, boolean fCommandLogging
)
793 POP3Transport
*This
= (POP3Transport
*)iface
;
796 TRACE("(%p, %s, %s)\n", pInetServer
, fAuthenticate
? "TRUE" : "FALSE", fCommandLogging
? "TRUE" : "FALSE");
798 hr
= InternetTransport_Connect(&This
->InetTransport
, pInetServer
, fAuthenticate
, fCommandLogging
);
802 init_parser(This
, POP3_USER
);
803 return InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackSendUSERCmd
);
806 static HRESULT WINAPI
POP3Transport_HandsOffCallback(IPOP3Transport
*iface
)
808 POP3Transport
*This
= (POP3Transport
*)iface
;
811 return InternetTransport_HandsOffCallback(&This
->InetTransport
);
814 static HRESULT WINAPI
POP3Transport_Disconnect(IPOP3Transport
*iface
)
817 return IPOP3Transport_CommandQUIT(iface
);
820 static HRESULT WINAPI
POP3Transport_DropConnection(IPOP3Transport
*iface
)
822 POP3Transport
*This
= (POP3Transport
*)iface
;
825 return InternetTransport_DropConnection(&This
->InetTransport
);
828 static HRESULT WINAPI
POP3Transport_GetStatus(IPOP3Transport
*iface
,
829 IXPSTATUS
*pCurrentStatus
)
831 POP3Transport
*This
= (POP3Transport
*)iface
;
834 return InternetTransport_GetStatus(&This
->InetTransport
, pCurrentStatus
);
837 static HRESULT WINAPI
POP3Transport_InitNew(IPOP3Transport
*iface
,
838 LPSTR pszLogFilePath
, IPOP3Callback
*pCallback
)
840 POP3Transport
*This
= (POP3Transport
*)iface
;
842 TRACE("(%s, %p)\n", debugstr_a(pszLogFilePath
), pCallback
);
848 FIXME("not using log file of %s, use Wine debug logging instead\n",
849 debugstr_a(pszLogFilePath
));
851 IPOP3Callback_AddRef(pCallback
);
852 This
->InetTransport
.pCallback
= (ITransportCallback
*)pCallback
;
853 This
->InetTransport
.fInitialised
= TRUE
;
858 static HRESULT WINAPI
POP3Transport_MarkItem(IPOP3Transport
*iface
, POP3MARKTYPE marktype
,
859 DWORD dwPopId
, boolean fMarked
)
861 FIXME("(%u, %lu, %d)\n", marktype
, dwPopId
, fMarked
);
865 static HRESULT WINAPI
POP3Transport_CommandAUTH(IPOP3Transport
*iface
, LPSTR pszAuthType
)
867 FIXME("(%s)\n", pszAuthType
);
871 static HRESULT WINAPI
POP3Transport_CommandUSER(IPOP3Transport
*iface
, LPSTR username
)
873 static const char user
[] = "USER ";
874 POP3Transport
*This
= (POP3Transport
*)iface
;
878 TRACE("(%s)\n", username
);
880 len
= sizeof(user
) + strlen(username
) + 2; /* "\r\n" */
881 if (!(command
= HeapAlloc(GetProcessHeap(), 0, len
))) return S_FALSE
;
883 strcpy(command
, user
);
884 strcat(command
, username
);
885 strcat(command
, "\r\n");
887 init_parser(This
, POP3_USER
);
888 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvUSERResp
);
890 HeapFree(GetProcessHeap(), 0, command
);
894 static HRESULT WINAPI
POP3Transport_CommandPASS(IPOP3Transport
*iface
, LPSTR password
)
896 static const char pass
[] = "PASS ";
897 POP3Transport
*This
= (POP3Transport
*)iface
;
901 TRACE("(%p)\n", password
);
903 len
= sizeof(pass
) + strlen(password
) + 2; /* "\r\n" */
904 if (!(command
= HeapAlloc(GetProcessHeap(), 0, len
))) return S_FALSE
;
906 strcpy(command
, pass
);
907 strcat(command
, password
);
908 strcat(command
, "\r\n");
910 init_parser(This
, POP3_PASS
);
911 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvPASSResp
);
913 HeapFree(GetProcessHeap(), 0, command
);
917 static HRESULT WINAPI
POP3Transport_CommandLIST(
918 IPOP3Transport
*iface
, POP3CMDTYPE cmdtype
, DWORD dwPopId
)
920 static const char list
[] = "LIST %lu\r\n";
921 static char list_all
[] = "LIST\r\n";
922 POP3Transport
*This
= (POP3Transport
*)iface
;
926 TRACE("(%u, %lu)\n", cmdtype
, dwPopId
);
930 len
= sizeof(list
) + 10 + 2; /* "4294967296" + "\r\n" */
931 if (!(command
= HeapAlloc(GetProcessHeap(), 0, len
))) return S_FALSE
;
932 sprintf(command
, list
, dwPopId
);
934 else command
= list_all
;
936 init_parser(This
, POP3_LIST
);
937 This
->type
= cmdtype
;
938 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvLISTResp
);
940 if (dwPopId
) HeapFree(GetProcessHeap(), 0, command
);
944 static HRESULT WINAPI
POP3Transport_CommandTOP(
945 IPOP3Transport
*iface
, POP3CMDTYPE cmdtype
, DWORD dwPopId
, DWORD cPreviewLines
)
947 static const char top
[] = "TOP %lu %lu\r\n";
948 POP3Transport
*This
= (POP3Transport
*)iface
;
952 TRACE("(%u, %lu, %lu)\n", cmdtype
, dwPopId
, cPreviewLines
);
954 len
= sizeof(top
) + 20 + 2; /* 2 * "4294967296" + "\r\n" */
955 if (!(command
= HeapAlloc(GetProcessHeap(), 0, len
))) return S_FALSE
;
956 sprintf(command
, top
, dwPopId
, cPreviewLines
);
958 This
->preview_lines
= cPreviewLines
;
959 init_parser(This
, POP3_TOP
);
960 This
->type
= cmdtype
;
961 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvTOPResp
);
963 HeapFree(GetProcessHeap(), 0, command
);
967 static HRESULT WINAPI
POP3Transport_CommandQUIT(IPOP3Transport
*iface
)
969 static const char command
[] = "QUIT\r\n";
970 POP3Transport
*This
= (POP3Transport
*)iface
;
974 InternetTransport_ChangeStatus(&This
->InetTransport
, IXP_DISCONNECTING
);
976 init_parser(This
, POP3_QUIT
);
977 return InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvQUITResp
);
980 static HRESULT WINAPI
POP3Transport_CommandSTAT(IPOP3Transport
*iface
)
982 static const char stat
[] = "STAT\r\n";
983 POP3Transport
*This
= (POP3Transport
*)iface
;
987 init_parser(This
, POP3_STAT
);
988 InternetTransport_DoCommand(&This
->InetTransport
, stat
, POP3Transport_CallbackRecvSTATResp
);
992 static HRESULT WINAPI
POP3Transport_CommandNOOP(IPOP3Transport
*iface
)
994 static const char noop
[] = "NOOP\r\n";
995 POP3Transport
*This
= (POP3Transport
*)iface
;
999 init_parser(This
, POP3_NOOP
);
1000 InternetTransport_DoCommand(&This
->InetTransport
, noop
, POP3Transport_CallbackRecvNOOPResp
);
1004 static HRESULT WINAPI
POP3Transport_CommandRSET(IPOP3Transport
*iface
)
1006 static const char rset
[] = "RSET\r\n";
1007 POP3Transport
*This
= (POP3Transport
*)iface
;
1011 init_parser(This
, POP3_RSET
);
1012 InternetTransport_DoCommand(&This
->InetTransport
, rset
, POP3Transport_CallbackRecvRSETResp
);
1016 static HRESULT WINAPI
POP3Transport_CommandUIDL(
1017 IPOP3Transport
*iface
, POP3CMDTYPE cmdtype
, DWORD dwPopId
)
1019 static const char uidl
[] = "UIDL %lu\r\n";
1020 static char uidl_all
[] = "UIDL\r\n";
1021 POP3Transport
*This
= (POP3Transport
*)iface
;
1025 TRACE("(%u, %lu)\n", cmdtype
, dwPopId
);
1029 len
= sizeof(uidl
) + 10 + 2; /* "4294967296" + "\r\n" */
1030 if (!(command
= HeapAlloc(GetProcessHeap(), 0, len
))) return S_FALSE
;
1031 sprintf(command
, uidl
, dwPopId
);
1033 else command
= uidl_all
;
1035 init_parser(This
, POP3_UIDL
);
1036 This
->type
= cmdtype
;
1037 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvUIDLResp
);
1039 if (dwPopId
) HeapFree(GetProcessHeap(), 0, command
);
1043 static HRESULT WINAPI
POP3Transport_CommandDELE(
1044 IPOP3Transport
*iface
, POP3CMDTYPE cmdtype
, DWORD dwPopId
)
1046 static const char dele
[] = "DELE %lu\r\n";
1047 POP3Transport
*This
= (POP3Transport
*)iface
;
1051 TRACE("(%u, %lu)\n", cmdtype
, dwPopId
);
1053 len
= sizeof(dele
) + 10 + 2; /* "4294967296" + "\r\n" */
1054 if (!(command
= HeapAlloc(GetProcessHeap(), 0, len
))) return S_FALSE
;
1055 sprintf(command
, dele
, dwPopId
);
1057 init_parser(This
, POP3_DELE
);
1058 This
->type
= cmdtype
;
1059 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvDELEResp
);
1061 HeapFree(GetProcessHeap(), 0, command
);
1065 static HRESULT WINAPI
POP3Transport_CommandRETR(
1066 IPOP3Transport
*iface
, POP3CMDTYPE cmdtype
, DWORD dwPopId
)
1068 static const char retr
[] = "RETR %lu\r\n";
1069 POP3Transport
*This
= (POP3Transport
*)iface
;
1073 TRACE("(%u, %lu)\n", cmdtype
, dwPopId
);
1075 len
= sizeof(retr
) + 10 + 2; /* "4294967296" + "\r\n" */
1076 if (!(command
= HeapAlloc(GetProcessHeap(), 0, len
))) return S_FALSE
;
1077 sprintf(command
, retr
, dwPopId
);
1079 init_parser(This
, POP3_RETR
);
1080 This
->type
= 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 IClassFactory_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
);