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
32 #include "wine/debug.h"
34 #include "inetcomm_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(inetcomm
);
48 InternetTransport InetTransport
;
54 enum parse_state state
;
60 static HRESULT
parse_response(POP3Transport
*This
)
65 if (strlen(This
->response
) < 3)
67 WARN("parse error\n");
68 This
->state
= STATE_DONE
;
71 if (!memcmp(This
->response
, "+OK", 3))
73 This
->ptr
= This
->response
+ 3;
74 This
->state
= STATE_OK
;
77 This
->state
= STATE_DONE
;
84 static HRESULT
parse_uidl_response(POP3Transport
*This
, POP3UIDL
*uidl
)
93 if (This
->type
== POP3CMD_GET_POPID
)
95 if ((p
= strchr(This
->ptr
, ' ')))
97 while (*p
== ' ') p
++;
98 sscanf(p
, "%lu", &uidl
->dwPopId
);
99 if ((p
= strchr(p
, ' ')))
101 while (*p
== ' ') p
++;
103 This
->valid_info
= TRUE
;
106 This
->state
= STATE_DONE
;
109 This
->state
= STATE_MULTILINE
;
112 case STATE_MULTILINE
:
113 if (This
->response
[0] == '.' && !This
->response
[1])
115 This
->valid_info
= FALSE
;
116 This
->state
= STATE_DONE
;
119 sscanf(This
->response
, "%lu", &uidl
->dwPopId
);
120 if ((p
= strchr(This
->response
, ' ')))
122 while (*p
== ' ') p
++;
124 This
->valid_info
= TRUE
;
129 WARN("parse error\n");
130 This
->state
= STATE_DONE
;
135 static HRESULT
parse_stat_response(POP3Transport
*This
, POP3STAT
*stat
)
140 stat
->cbMessages
= 0;
144 if ((p
= strchr(This
->ptr
, ' ')))
146 while (*p
== ' ') p
++;
147 sscanf(p
, "%lu %lu", &stat
->cMessages
, &stat
->cbMessages
);
148 This
->valid_info
= TRUE
;
149 This
->state
= STATE_DONE
;
154 WARN("parse error\n");
155 This
->state
= STATE_DONE
;
160 static HRESULT
parse_list_response(POP3Transport
*This
, POP3LIST
*list
)
169 if (This
->type
== POP3CMD_GET_POPID
)
171 if ((p
= strchr(This
->ptr
, ' ')))
173 while (*p
== ' ') p
++;
174 sscanf(p
, "%lu %lu", &list
->dwPopId
, &list
->cbSize
);
175 This
->valid_info
= TRUE
;
177 This
->state
= STATE_DONE
;
180 This
->state
= STATE_MULTILINE
;
183 case STATE_MULTILINE
:
184 if (This
->response
[0] == '.' && !This
->response
[1])
186 This
->valid_info
= FALSE
;
187 This
->state
= STATE_DONE
;
190 sscanf(This
->response
, "%lu", &list
->dwPopId
);
191 if ((p
= strchr(This
->response
, ' ')))
193 while (*p
== ' ') p
++;
194 sscanf(p
, "%lu", &list
->cbSize
);
195 This
->valid_info
= TRUE
;
200 WARN("parse error\n");
201 This
->state
= STATE_DONE
;
206 static HRESULT
parse_dele_response(POP3Transport
*This
, DWORD
*dwPopId
)
211 *dwPopId
= 0; /* FIXME */
212 This
->state
= STATE_DONE
;
216 WARN("parse error\n");
217 This
->state
= STATE_DONE
;
222 static HRESULT
parse_retr_response(POP3Transport
*This
, POP3RETR
*retr
)
227 retr
->fHeader
= FALSE
;
229 retr
->dwPopId
= This
->msgid
;
231 retr
->pszLines
= This
->response
;
234 This
->state
= STATE_MULTILINE
;
235 This
->valid_info
= FALSE
;
238 case STATE_MULTILINE
:
242 if (This
->response
[0] == '.' && !This
->response
[1])
244 retr
->cbLines
= retr
->cbSoFar
;
245 This
->state
= STATE_DONE
;
248 retr
->fHeader
= TRUE
;
249 if (!This
->response
[0]) retr
->fBody
= TRUE
;
251 len
= strlen(This
->response
);
252 retr
->cbSoFar
+= len
;
253 retr
->pszLines
= This
->response
;
256 This
->valid_info
= TRUE
;
261 WARN("parse error\n");
262 This
->state
= STATE_DONE
;
267 static HRESULT
parse_top_response(POP3Transport
*This
, POP3TOP
*top
)
272 top
->fHeader
= FALSE
;
274 top
->dwPopId
= This
->msgid
;
275 top
->cPreviewLines
= This
->preview_lines
;
277 top
->pszLines
= This
->response
;
280 This
->state
= STATE_MULTILINE
;
281 This
->valid_info
= FALSE
;
284 case STATE_MULTILINE
:
288 if (This
->response
[0] == '.' && !This
->response
[1])
290 top
->cbLines
= top
->cbSoFar
;
291 This
->state
= STATE_DONE
;
295 if (!This
->response
[0]) top
->fBody
= TRUE
;
297 len
= strlen(This
->response
);
299 top
->pszLines
= This
->response
;
302 This
->valid_info
= TRUE
;
307 WARN("parse error\n");
308 This
->state
= STATE_DONE
;
313 static void init_parser(POP3Transport
*This
, POP3COMMAND command
)
315 This
->state
= STATE_NONE
;
316 This
->command
= command
;
319 static HRESULT
POP3Transport_ParseResponse(POP3Transport
*This
, char *pszResponse
, POP3RESPONSE
*pResponse
)
323 TRACE("response: %s\n", debugstr_a(pszResponse
));
325 This
->response
= pszResponse
;
326 This
->valid_info
= FALSE
;
327 TRACE("state %u\n", This
->state
);
329 if (SUCCEEDED((hr
= parse_response(This
))))
331 switch (This
->command
)
333 case POP3_UIDL
: hr
= parse_uidl_response(This
, &pResponse
->rUidlInfo
); break;
334 case POP3_STAT
: hr
= parse_stat_response(This
, &pResponse
->rStatInfo
); break;
335 case POP3_LIST
: hr
= parse_list_response(This
, &pResponse
->rListInfo
); break;
336 case POP3_DELE
: hr
= parse_dele_response(This
, &pResponse
->dwPopId
); break;
337 case POP3_RETR
: hr
= parse_retr_response(This
, &pResponse
->rRetrInfo
); break;
338 case POP3_TOP
: hr
= parse_top_response(This
, &pResponse
->rTopInfo
); break;
340 This
->state
= STATE_DONE
;
344 pResponse
->command
= This
->command
;
345 pResponse
->fDone
= (This
->state
== STATE_DONE
);
346 pResponse
->fValidInfo
= This
->valid_info
;
347 pResponse
->rIxpResult
.hrResult
= hr
;
348 pResponse
->rIxpResult
.pszResponse
= pszResponse
;
349 pResponse
->rIxpResult
.uiServerError
= 0;
350 pResponse
->rIxpResult
.hrServerError
= pResponse
->rIxpResult
.hrResult
;
351 pResponse
->rIxpResult
.dwSocketError
= WSAGetLastError();
352 pResponse
->rIxpResult
.pszProblem
= NULL
;
353 pResponse
->pTransport
= (IPOP3Transport
*)&This
->InetTransport
.u
.vtblPOP3
;
355 if (This
->InetTransport
.pCallback
&& This
->InetTransport
.fCommandLogging
)
357 ITransportCallback_OnCommand(This
->InetTransport
.pCallback
, CMD_RESP
,
358 pResponse
->rIxpResult
.pszResponse
, pResponse
->rIxpResult
.hrServerError
,
359 (IInternetTransport
*)&This
->InetTransport
.u
.vtbl
);
364 static void POP3Transport_CallbackProcessDELEResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
366 POP3Transport
*This
= (POP3Transport
*)iface
;
367 POP3RESPONSE response
;
372 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
375 /* FIXME: handle error */
379 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
382 static void POP3Transport_CallbackRecvDELEResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
384 POP3Transport
*This
= (POP3Transport
*)iface
;
387 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessDELEResp
);
390 static void POP3Transport_CallbackProcessNOOPResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
392 POP3Transport
*This
= (POP3Transport
*)iface
;
393 POP3RESPONSE response
;
398 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
401 /* FIXME: handle error */
405 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
408 static void POP3Transport_CallbackRecvNOOPResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
410 POP3Transport
*This
= (POP3Transport
*)iface
;
413 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessNOOPResp
);
416 static void POP3Transport_CallbackProcessRSETResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
418 POP3Transport
*This
= (POP3Transport
*)iface
;
419 POP3RESPONSE response
;
424 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
427 /* FIXME: handle error */
431 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
434 static void POP3Transport_CallbackRecvRSETResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
436 POP3Transport
*This
= (POP3Transport
*)iface
;
439 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessRSETResp
);
442 static void POP3Transport_CallbackProcessRETRResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
444 POP3Transport
*This
= (POP3Transport
*)iface
;
445 POP3RESPONSE response
;
450 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
453 /* FIXME: handle error */
457 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
461 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessRETRResp
);
465 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
468 static void POP3Transport_CallbackRecvRETRResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
470 POP3Transport
*This
= (POP3Transport
*)iface
;
473 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessRETRResp
);
476 static void POP3Transport_CallbackProcessTOPResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
478 POP3Transport
*This
= (POP3Transport
*)iface
;
479 POP3RESPONSE response
;
484 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
487 /* FIXME: handle error */
491 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
495 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessTOPResp
);
499 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
502 static void POP3Transport_CallbackRecvTOPResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
504 POP3Transport
*This
= (POP3Transport
*)iface
;
507 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessTOPResp
);
510 static void POP3Transport_CallbackProcessLISTResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
512 POP3Transport
*This
= (POP3Transport
*)iface
;
513 POP3RESPONSE response
;
518 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
521 /* FIXME: handle error */
525 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
529 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessLISTResp
);
533 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
536 static void POP3Transport_CallbackRecvLISTResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
538 POP3Transport
*This
= (POP3Transport
*)iface
;
541 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessLISTResp
);
544 static void POP3Transport_CallbackProcessUIDLResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
546 POP3Transport
*This
= (POP3Transport
*)iface
;
547 POP3RESPONSE response
;
552 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
555 /* FIXME: handle error */
559 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
563 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessUIDLResp
);
567 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
570 static void POP3Transport_CallbackRecvUIDLResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
572 POP3Transport
*This
= (POP3Transport
*)iface
;
575 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessUIDLResp
);
578 static void POP3Transport_CallbackProcessSTATResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
580 POP3Transport
*This
= (POP3Transport
*)iface
;
581 POP3RESPONSE response
;
586 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
589 /* FIXME: handle error */
593 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
596 static void POP3Transport_CallbackRecvSTATResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
598 POP3Transport
*This
= (POP3Transport
*)iface
;
601 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessSTATResp
);
604 static void POP3Transport_CallbackProcessPASSResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
606 POP3Transport
*This
= (POP3Transport
*)iface
;
607 POP3RESPONSE response
;
612 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
615 /* FIXME: handle error */
619 InternetTransport_ChangeStatus(&This
->InetTransport
, IXP_AUTHORIZED
);
620 InternetTransport_ChangeStatus(&This
->InetTransport
, IXP_CONNECTED
);
622 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
625 static void POP3Transport_CallbackRecvPASSResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
627 POP3Transport
*This
= (POP3Transport
*)iface
;
630 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessPASSResp
);
633 static void POP3Transport_CallbackProcessUSERResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
635 static const char pass
[] = "PASS ";
636 POP3Transport
*This
= (POP3Transport
*)iface
;
637 POP3RESPONSE response
;
644 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
647 /* FIXME: handle error */
651 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
653 len
= sizeof(pass
) + strlen(This
->InetTransport
.ServerInfo
.szPassword
) + 2; /* "\r\n" */
654 command
= HeapAlloc(GetProcessHeap(), 0, len
);
656 strcpy(command
, pass
);
657 strcat(command
, This
->InetTransport
.ServerInfo
.szPassword
);
658 strcat(command
, "\r\n");
660 init_parser(This
, POP3_PASS
);
662 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvPASSResp
);
663 HeapFree(GetProcessHeap(), 0, command
);
666 static void POP3Transport_CallbackRecvUSERResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
668 POP3Transport
*This
= (POP3Transport
*)iface
;
671 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessUSERResp
);
674 static void POP3Transport_CallbackSendUSERCmd(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
676 static const char user
[] = "USER ";
677 POP3Transport
*This
= (POP3Transport
*)iface
;
683 len
= sizeof(user
) + strlen(This
->InetTransport
.ServerInfo
.szUserName
) + 2; /* "\r\n" */
684 command
= HeapAlloc(GetProcessHeap(), 0, len
);
686 strcpy(command
, user
);
687 strcat(command
, This
->InetTransport
.ServerInfo
.szUserName
);
688 strcat(command
, "\r\n");
689 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvUSERResp
);
691 HeapFree(GetProcessHeap(), 0, command
);
694 static void POP3Transport_CallbackProcessQUITResponse(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
696 POP3Transport
*This
= (POP3Transport
*)iface
;
697 POP3RESPONSE response
;
700 TRACE("%s\n", debugstr_an(pBuffer
, cbBuffer
));
702 hr
= POP3Transport_ParseResponse(This
, pBuffer
, &response
);
705 /* FIXME: handle error */
709 IPOP3Callback_OnResponse((IPOP3Callback
*)This
->InetTransport
.pCallback
, &response
);
710 InternetTransport_DropConnection(&This
->InetTransport
);
713 static void POP3Transport_CallbackRecvQUITResp(IInternetTransport
*iface
, char *pBuffer
, int cbBuffer
)
715 POP3Transport
*This
= (POP3Transport
*)iface
;
718 InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackProcessQUITResponse
);
721 static HRESULT WINAPI
POP3Transport_QueryInterface(IPOP3Transport
*iface
, REFIID riid
, void **ppv
)
723 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
725 if (IsEqualIID(riid
, &IID_IUnknown
) ||
726 IsEqualIID(riid
, &IID_IInternetTransport
) ||
727 IsEqualIID(riid
, &IID_IPOP3Transport
))
730 IPOP3Transport_AddRef(iface
);
734 FIXME("no interface for %s\n", debugstr_guid(riid
));
735 return E_NOINTERFACE
;
738 static ULONG WINAPI
POP3Transport_AddRef(IPOP3Transport
*iface
)
740 POP3Transport
*This
= (POP3Transport
*)iface
;
741 return InterlockedIncrement((LONG
*)&This
->refs
);
744 static ULONG WINAPI
POP3Transport_Release(IPOP3Transport
*iface
)
746 POP3Transport
*This
= (POP3Transport
*)iface
;
747 ULONG refs
= InterlockedDecrement((LONG
*)&This
->refs
);
750 TRACE("destroying %p\n", This
);
751 if (This
->InetTransport
.Status
!= IXP_DISCONNECTED
)
752 InternetTransport_DropConnection(&This
->InetTransport
);
753 if (This
->InetTransport
.pCallback
) ITransportCallback_Release(This
->InetTransport
.pCallback
);
754 HeapFree(GetProcessHeap(), 0, This
);
759 static HRESULT WINAPI
POP3Transport_GetServerInfo(IPOP3Transport
*iface
,
760 LPINETSERVER pInetServer
)
762 POP3Transport
*This
= (POP3Transport
*)iface
;
764 TRACE("(%p)\n", pInetServer
);
765 return InternetTransport_GetServerInfo(&This
->InetTransport
, pInetServer
);
768 static IXPTYPE WINAPI
POP3Transport_GetIXPType(IPOP3Transport
*iface
)
774 static HRESULT WINAPI
POP3Transport_IsState(IPOP3Transport
*iface
, IXPISSTATE isstate
)
776 FIXME("(%u)\n", isstate
);
780 static HRESULT WINAPI
POP3Transport_InetServerFromAccount(
781 IPOP3Transport
*iface
, IImnAccount
*pAccount
, LPINETSERVER pInetServer
)
783 POP3Transport
*This
= (POP3Transport
*)iface
;
785 TRACE("(%p, %p)\n", pAccount
, pInetServer
);
786 return InternetTransport_InetServerFromAccount(&This
->InetTransport
, pAccount
, pInetServer
);
789 static HRESULT WINAPI
POP3Transport_Connect(IPOP3Transport
*iface
,
790 LPINETSERVER pInetServer
, boolean fAuthenticate
, boolean fCommandLogging
)
792 POP3Transport
*This
= (POP3Transport
*)iface
;
795 TRACE("(%p, %s, %s)\n", pInetServer
, fAuthenticate
? "TRUE" : "FALSE", fCommandLogging
? "TRUE" : "FALSE");
797 hr
= InternetTransport_Connect(&This
->InetTransport
, pInetServer
, fAuthenticate
, fCommandLogging
);
801 init_parser(This
, POP3_USER
);
802 return InternetTransport_ReadLine(&This
->InetTransport
, POP3Transport_CallbackSendUSERCmd
);
805 static HRESULT WINAPI
POP3Transport_HandsOffCallback(IPOP3Transport
*iface
)
807 POP3Transport
*This
= (POP3Transport
*)iface
;
810 return InternetTransport_HandsOffCallback(&This
->InetTransport
);
813 static HRESULT WINAPI
POP3Transport_Disconnect(IPOP3Transport
*iface
)
816 return IPOP3Transport_CommandQUIT(iface
);
819 static HRESULT WINAPI
POP3Transport_DropConnection(IPOP3Transport
*iface
)
821 POP3Transport
*This
= (POP3Transport
*)iface
;
824 return InternetTransport_DropConnection(&This
->InetTransport
);
827 static HRESULT WINAPI
POP3Transport_GetStatus(IPOP3Transport
*iface
,
828 IXPSTATUS
*pCurrentStatus
)
830 POP3Transport
*This
= (POP3Transport
*)iface
;
833 return InternetTransport_GetStatus(&This
->InetTransport
, pCurrentStatus
);
836 static HRESULT WINAPI
POP3Transport_InitNew(IPOP3Transport
*iface
,
837 LPSTR pszLogFilePath
, IPOP3Callback
*pCallback
)
839 POP3Transport
*This
= (POP3Transport
*)iface
;
841 TRACE("(%s, %p)\n", debugstr_a(pszLogFilePath
), pCallback
);
847 FIXME("not using log file of %s, use Wine debug logging instead\n",
848 debugstr_a(pszLogFilePath
));
850 IPOP3Callback_AddRef(pCallback
);
851 This
->InetTransport
.pCallback
= (ITransportCallback
*)pCallback
;
852 This
->InetTransport
.fInitialised
= TRUE
;
857 static HRESULT WINAPI
POP3Transport_MarkItem(IPOP3Transport
*iface
, POP3MARKTYPE marktype
,
858 DWORD dwPopId
, boolean fMarked
)
860 FIXME("(%u, %lu, %d)\n", marktype
, dwPopId
, fMarked
);
864 static HRESULT WINAPI
POP3Transport_CommandAUTH(IPOP3Transport
*iface
, LPSTR pszAuthType
)
866 FIXME("(%s)\n", pszAuthType
);
870 static HRESULT WINAPI
POP3Transport_CommandUSER(IPOP3Transport
*iface
, LPSTR username
)
872 static const char user
[] = "USER ";
873 POP3Transport
*This
= (POP3Transport
*)iface
;
877 TRACE("(%s)\n", username
);
879 len
= sizeof(user
) + strlen(username
) + 2; /* "\r\n" */
880 if (!(command
= HeapAlloc(GetProcessHeap(), 0, len
))) return S_FALSE
;
882 strcpy(command
, user
);
883 strcat(command
, username
);
884 strcat(command
, "\r\n");
886 init_parser(This
, POP3_USER
);
887 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvUSERResp
);
889 HeapFree(GetProcessHeap(), 0, command
);
893 static HRESULT WINAPI
POP3Transport_CommandPASS(IPOP3Transport
*iface
, LPSTR password
)
895 static const char pass
[] = "PASS ";
896 POP3Transport
*This
= (POP3Transport
*)iface
;
900 TRACE("(%p)\n", password
);
902 len
= sizeof(pass
) + strlen(password
) + 2; /* "\r\n" */
903 if (!(command
= HeapAlloc(GetProcessHeap(), 0, len
))) return S_FALSE
;
905 strcpy(command
, pass
);
906 strcat(command
, password
);
907 strcat(command
, "\r\n");
909 init_parser(This
, POP3_PASS
);
910 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvPASSResp
);
912 HeapFree(GetProcessHeap(), 0, command
);
916 static HRESULT WINAPI
POP3Transport_CommandLIST(
917 IPOP3Transport
*iface
, POP3CMDTYPE cmdtype
, DWORD dwPopId
)
919 static const char list
[] = "LIST %lu\r\n";
920 static char list_all
[] = "LIST\r\n";
921 POP3Transport
*This
= (POP3Transport
*)iface
;
925 TRACE("(%u, %lu)\n", cmdtype
, dwPopId
);
929 len
= sizeof(list
) + 10 + 2; /* "4294967296" + "\r\n" */
930 if (!(command
= HeapAlloc(GetProcessHeap(), 0, len
))) return S_FALSE
;
931 sprintf(command
, list
, dwPopId
);
933 else command
= list_all
;
935 init_parser(This
, POP3_LIST
);
936 This
->type
= cmdtype
;
937 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvLISTResp
);
939 if (dwPopId
) HeapFree(GetProcessHeap(), 0, command
);
943 static HRESULT WINAPI
POP3Transport_CommandTOP(
944 IPOP3Transport
*iface
, POP3CMDTYPE cmdtype
, DWORD dwPopId
, DWORD cPreviewLines
)
946 static const char top
[] = "TOP %lu %lu\r\n";
947 POP3Transport
*This
= (POP3Transport
*)iface
;
951 TRACE("(%u, %lu, %lu)\n", cmdtype
, dwPopId
, cPreviewLines
);
953 len
= sizeof(top
) + 20 + 2; /* 2 * "4294967296" + "\r\n" */
954 if (!(command
= HeapAlloc(GetProcessHeap(), 0, len
))) return S_FALSE
;
955 sprintf(command
, top
, dwPopId
, cPreviewLines
);
957 This
->preview_lines
= cPreviewLines
;
958 init_parser(This
, POP3_TOP
);
959 This
->type
= cmdtype
;
960 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvTOPResp
);
962 HeapFree(GetProcessHeap(), 0, command
);
966 static HRESULT WINAPI
POP3Transport_CommandQUIT(IPOP3Transport
*iface
)
968 static const char command
[] = "QUIT\r\n";
969 POP3Transport
*This
= (POP3Transport
*)iface
;
973 InternetTransport_ChangeStatus(&This
->InetTransport
, IXP_DISCONNECTING
);
975 init_parser(This
, POP3_QUIT
);
976 return InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvQUITResp
);
979 static HRESULT WINAPI
POP3Transport_CommandSTAT(IPOP3Transport
*iface
)
981 static const char stat
[] = "STAT\r\n";
982 POP3Transport
*This
= (POP3Transport
*)iface
;
986 init_parser(This
, POP3_STAT
);
987 InternetTransport_DoCommand(&This
->InetTransport
, stat
, POP3Transport_CallbackRecvSTATResp
);
991 static HRESULT WINAPI
POP3Transport_CommandNOOP(IPOP3Transport
*iface
)
993 static const char noop
[] = "NOOP\r\n";
994 POP3Transport
*This
= (POP3Transport
*)iface
;
998 init_parser(This
, POP3_NOOP
);
999 InternetTransport_DoCommand(&This
->InetTransport
, noop
, POP3Transport_CallbackRecvNOOPResp
);
1003 static HRESULT WINAPI
POP3Transport_CommandRSET(IPOP3Transport
*iface
)
1005 static const char rset
[] = "RSET\r\n";
1006 POP3Transport
*This
= (POP3Transport
*)iface
;
1010 init_parser(This
, POP3_RSET
);
1011 InternetTransport_DoCommand(&This
->InetTransport
, rset
, POP3Transport_CallbackRecvRSETResp
);
1015 static HRESULT WINAPI
POP3Transport_CommandUIDL(
1016 IPOP3Transport
*iface
, POP3CMDTYPE cmdtype
, DWORD dwPopId
)
1018 static const char uidl
[] = "UIDL %lu\r\n";
1019 static char uidl_all
[] = "UIDL\r\n";
1020 POP3Transport
*This
= (POP3Transport
*)iface
;
1024 TRACE("(%u, %lu)\n", cmdtype
, dwPopId
);
1028 len
= sizeof(uidl
) + 10 + 2; /* "4294967296" + "\r\n" */
1029 if (!(command
= HeapAlloc(GetProcessHeap(), 0, len
))) return S_FALSE
;
1030 sprintf(command
, uidl
, dwPopId
);
1032 else command
= uidl_all
;
1034 init_parser(This
, POP3_UIDL
);
1035 This
->type
= cmdtype
;
1036 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvUIDLResp
);
1038 if (dwPopId
) HeapFree(GetProcessHeap(), 0, command
);
1042 static HRESULT WINAPI
POP3Transport_CommandDELE(
1043 IPOP3Transport
*iface
, POP3CMDTYPE cmdtype
, DWORD dwPopId
)
1045 static const char dele
[] = "DELE %lu\r\n";
1046 POP3Transport
*This
= (POP3Transport
*)iface
;
1050 TRACE("(%u, %lu)\n", cmdtype
, dwPopId
);
1052 len
= sizeof(dele
) + 10 + 2; /* "4294967296" + "\r\n" */
1053 if (!(command
= HeapAlloc(GetProcessHeap(), 0, len
))) return S_FALSE
;
1054 sprintf(command
, dele
, dwPopId
);
1056 init_parser(This
, POP3_DELE
);
1057 This
->type
= cmdtype
;
1058 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvDELEResp
);
1060 HeapFree(GetProcessHeap(), 0, command
);
1064 static HRESULT WINAPI
POP3Transport_CommandRETR(
1065 IPOP3Transport
*iface
, POP3CMDTYPE cmdtype
, DWORD dwPopId
)
1067 static const char retr
[] = "RETR %lu\r\n";
1068 POP3Transport
*This
= (POP3Transport
*)iface
;
1072 TRACE("(%u, %lu)\n", cmdtype
, dwPopId
);
1074 len
= sizeof(retr
) + 10 + 2; /* "4294967296" + "\r\n" */
1075 if (!(command
= HeapAlloc(GetProcessHeap(), 0, len
))) return S_FALSE
;
1076 sprintf(command
, retr
, dwPopId
);
1078 init_parser(This
, POP3_RETR
);
1079 This
->type
= cmdtype
;
1080 InternetTransport_DoCommand(&This
->InetTransport
, command
, POP3Transport_CallbackRecvRETRResp
);
1082 HeapFree(GetProcessHeap(), 0, command
);
1086 static const IPOP3TransportVtbl POP3TransportVtbl
=
1088 POP3Transport_QueryInterface
,
1089 POP3Transport_AddRef
,
1090 POP3Transport_Release
,
1091 POP3Transport_GetServerInfo
,
1092 POP3Transport_GetIXPType
,
1093 POP3Transport_IsState
,
1094 POP3Transport_InetServerFromAccount
,
1095 POP3Transport_Connect
,
1096 POP3Transport_HandsOffCallback
,
1097 POP3Transport_Disconnect
,
1098 POP3Transport_DropConnection
,
1099 POP3Transport_GetStatus
,
1100 POP3Transport_InitNew
,
1101 POP3Transport_MarkItem
,
1102 POP3Transport_CommandAUTH
,
1103 POP3Transport_CommandUSER
,
1104 POP3Transport_CommandPASS
,
1105 POP3Transport_CommandLIST
,
1106 POP3Transport_CommandTOP
,
1107 POP3Transport_CommandQUIT
,
1108 POP3Transport_CommandSTAT
,
1109 POP3Transport_CommandNOOP
,
1110 POP3Transport_CommandRSET
,
1111 POP3Transport_CommandUIDL
,
1112 POP3Transport_CommandDELE
,
1113 POP3Transport_CommandRETR
1116 HRESULT WINAPI
CreatePOP3Transport(IPOP3Transport
**ppTransport
)
1119 POP3Transport
*This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
1121 return E_OUTOFMEMORY
;
1123 This
->InetTransport
.u
.vtblPOP3
= &POP3TransportVtbl
;
1125 hr
= InternetTransport_Init(&This
->InetTransport
);
1128 HeapFree(GetProcessHeap(), 0, This
);
1132 *ppTransport
= (IPOP3Transport
*)&This
->InetTransport
.u
.vtblPOP3
;
1133 IPOP3Transport_AddRef(*ppTransport
);
1138 static HRESULT WINAPI
POP3TransportCF_QueryInterface(LPCLASSFACTORY iface
,
1139 REFIID riid
, LPVOID
*ppv
)
1142 if (IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IClassFactory
))
1145 IClassFactory_AddRef(iface
);
1148 return E_NOINTERFACE
;
1151 static ULONG WINAPI
POP3TransportCF_AddRef(LPCLASSFACTORY iface
)
1153 return 2; /* non-heap based object */
1156 static ULONG WINAPI
POP3TransportCF_Release(LPCLASSFACTORY iface
)
1158 return 1; /* non-heap based object */
1161 static HRESULT WINAPI
POP3TransportCF_CreateInstance(LPCLASSFACTORY iface
,
1162 LPUNKNOWN pUnk
, REFIID riid
, LPVOID
*ppv
)
1165 IPOP3Transport
*pPop3Transport
;
1167 TRACE("(%p, %s, %p)\n", pUnk
, debugstr_guid(riid
), ppv
);
1172 return CLASS_E_NOAGGREGATION
;
1174 hr
= CreatePOP3Transport(&pPop3Transport
);
1178 hr
= IPOP3Transport_QueryInterface(pPop3Transport
, riid
, ppv
);
1179 IPOP3Transport_Release(pPop3Transport
);
1184 static HRESULT WINAPI
POP3TransportCF_LockServer(LPCLASSFACTORY iface
, BOOL fLock
)
1186 FIXME("(%d)\n",fLock
);
1190 static const IClassFactoryVtbl POP3TransportCFVtbl
=
1192 POP3TransportCF_QueryInterface
,
1193 POP3TransportCF_AddRef
,
1194 POP3TransportCF_Release
,
1195 POP3TransportCF_CreateInstance
,
1196 POP3TransportCF_LockServer
1198 static const IClassFactoryVtbl
*POP3TransportCF
= &POP3TransportCFVtbl
;
1200 HRESULT
POP3TransportCF_Create(REFIID riid
, LPVOID
*ppv
)
1202 return IClassFactory_QueryInterface((IClassFactory
*)&POP3TransportCF
, riid
, ppv
);