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, "%u", &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, "%u", &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, "%u %u", &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, "%u %u", &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, "%u", &list->dwPopId);
192 if ((p = strchr(This->response, ' ')))
194 while (*p == ' ') p++;
195 sscanf(p, "%u", &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, POP3CMDTYPE type)
316 This->state = STATE_NONE;
317 This->command = command;
321 static HRESULT POP3Transport_ParseResponse(POP3Transport *This, char *pszResponse, POP3RESPONSE *pResponse)
325 TRACE("response: %s\n", debugstr_a(pszResponse));
327 This->response = pszResponse;
328 This->valid_info = FALSE;
329 TRACE("state %u\n", This->state);
331 if (SUCCEEDED((hr = parse_response(This))))
333 switch (This->command)
335 case POP3_UIDL: hr = parse_uidl_response(This, &pResponse->u.rUidlInfo); break;
336 case POP3_STAT: hr = parse_stat_response(This, &pResponse->u.rStatInfo); break;
337 case POP3_LIST: hr = parse_list_response(This, &pResponse->u.rListInfo); break;
338 case POP3_DELE: hr = parse_dele_response(This, &pResponse->u.dwPopId); break;
339 case POP3_RETR: hr = parse_retr_response(This, &pResponse->u.rRetrInfo); break;
340 case POP3_TOP: hr = parse_top_response(This, &pResponse->u.rTopInfo); break;
342 This->state = STATE_DONE;
346 pResponse->command = This->command;
347 pResponse->fDone = (This->state == STATE_DONE);
348 pResponse->fValidInfo = This->valid_info;
349 pResponse->rIxpResult.hrResult = hr;
350 pResponse->rIxpResult.pszResponse = pszResponse;
351 pResponse->rIxpResult.uiServerError = 0;
352 pResponse->rIxpResult.hrServerError = pResponse->rIxpResult.hrResult;
353 pResponse->rIxpResult.dwSocketError = WSAGetLastError();
354 pResponse->rIxpResult.pszProblem = NULL;
355 pResponse->pTransport = (IPOP3Transport *)&This->InetTransport.u.vtblPOP3;
357 if (This->InetTransport.pCallback && This->InetTransport.fCommandLogging)
359 ITransportCallback_OnCommand(This->InetTransport.pCallback, CMD_RESP,
360 pResponse->rIxpResult.pszResponse, pResponse->rIxpResult.hrServerError,
361 (IInternetTransport *)&This->InetTransport.u.vtbl);
366 static void POP3Transport_CallbackProcessDELEResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
368 POP3Transport *This = (POP3Transport *)iface;
369 POP3RESPONSE response;
374 hr = POP3Transport_ParseResponse(This, pBuffer, &response);
377 /* FIXME: handle error */
381 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
384 static void POP3Transport_CallbackRecvDELEResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
386 POP3Transport *This = (POP3Transport *)iface;
389 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessDELEResp);
392 static void POP3Transport_CallbackProcessNOOPResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
394 POP3Transport *This = (POP3Transport *)iface;
395 POP3RESPONSE response;
400 hr = POP3Transport_ParseResponse(This, pBuffer, &response);
403 /* FIXME: handle error */
407 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
410 static void POP3Transport_CallbackRecvNOOPResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
412 POP3Transport *This = (POP3Transport *)iface;
415 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessNOOPResp);
418 static void POP3Transport_CallbackProcessRSETResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
420 POP3Transport *This = (POP3Transport *)iface;
421 POP3RESPONSE response;
426 hr = POP3Transport_ParseResponse(This, pBuffer, &response);
429 /* FIXME: handle error */
433 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
436 static void POP3Transport_CallbackRecvRSETResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
438 POP3Transport *This = (POP3Transport *)iface;
441 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessRSETResp);
444 static void POP3Transport_CallbackProcessRETRResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
446 POP3Transport *This = (POP3Transport *)iface;
447 POP3RESPONSE response;
452 hr = POP3Transport_ParseResponse(This, pBuffer, &response);
455 /* FIXME: handle error */
459 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
463 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessRETRResp);
467 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
470 static void POP3Transport_CallbackRecvRETRResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
472 POP3Transport *This = (POP3Transport *)iface;
475 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessRETRResp);
478 static void POP3Transport_CallbackProcessTOPResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
480 POP3Transport *This = (POP3Transport *)iface;
481 POP3RESPONSE response;
486 hr = POP3Transport_ParseResponse(This, pBuffer, &response);
489 /* FIXME: handle error */
493 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
497 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessTOPResp);
501 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
504 static void POP3Transport_CallbackRecvTOPResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
506 POP3Transport *This = (POP3Transport *)iface;
509 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessTOPResp);
512 static void POP3Transport_CallbackProcessLISTResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
514 POP3Transport *This = (POP3Transport *)iface;
515 POP3RESPONSE response;
520 hr = POP3Transport_ParseResponse(This, pBuffer, &response);
523 /* FIXME: handle error */
527 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
531 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessLISTResp);
535 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
538 static void POP3Transport_CallbackRecvLISTResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
540 POP3Transport *This = (POP3Transport *)iface;
543 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessLISTResp);
546 static void POP3Transport_CallbackProcessUIDLResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
548 POP3Transport *This = (POP3Transport *)iface;
549 POP3RESPONSE response;
554 hr = POP3Transport_ParseResponse(This, pBuffer, &response);
557 /* FIXME: handle error */
561 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
565 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessUIDLResp);
569 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
572 static void POP3Transport_CallbackRecvUIDLResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
574 POP3Transport *This = (POP3Transport *)iface;
577 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessUIDLResp);
580 static void POP3Transport_CallbackProcessSTATResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
582 POP3Transport *This = (POP3Transport *)iface;
583 POP3RESPONSE response;
588 hr = POP3Transport_ParseResponse(This, pBuffer, &response);
591 /* FIXME: handle error */
595 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
598 static void POP3Transport_CallbackRecvSTATResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
600 POP3Transport *This = (POP3Transport *)iface;
603 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessSTATResp);
606 static void POP3Transport_CallbackProcessPASSResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
608 POP3Transport *This = (POP3Transport *)iface;
609 POP3RESPONSE response;
614 hr = POP3Transport_ParseResponse(This, pBuffer, &response);
617 /* FIXME: handle error */
621 InternetTransport_ChangeStatus(&This->InetTransport, IXP_AUTHORIZED);
622 InternetTransport_ChangeStatus(&This->InetTransport, IXP_CONNECTED);
624 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
627 static void POP3Transport_CallbackRecvPASSResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
629 POP3Transport *This = (POP3Transport *)iface;
632 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessPASSResp);
635 static void POP3Transport_CallbackProcessUSERResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
637 static char pass[] = "PASS ";
638 POP3Transport *This = (POP3Transport *)iface;
639 POP3RESPONSE response;
646 hr = POP3Transport_ParseResponse(This, pBuffer, &response);
649 /* FIXME: handle error */
653 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
655 len = sizeof(pass) + strlen(This->InetTransport.ServerInfo.szPassword) + 2; /* "\r\n" */
656 command = HeapAlloc(GetProcessHeap(), 0, len);
658 strcpy(command, pass);
659 strcat(command, This->InetTransport.ServerInfo.szPassword);
660 strcat(command, "\r\n");
662 init_parser(This, POP3_PASS, POP3_NONE);
664 InternetTransport_DoCommand(&This->InetTransport, command, POP3Transport_CallbackRecvPASSResp);
665 HeapFree(GetProcessHeap(), 0, command);
668 static void POP3Transport_CallbackRecvUSERResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
670 POP3Transport *This = (POP3Transport *)iface;
673 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessUSERResp);
676 static void POP3Transport_CallbackSendUSERCmd(IInternetTransport *iface, char *pBuffer, int cbBuffer)
678 static char user[] = "USER ";
679 POP3Transport *This = (POP3Transport *)iface;
685 len = sizeof(user) + strlen(This->InetTransport.ServerInfo.szUserName) + 2; /* "\r\n" */
686 command = HeapAlloc(GetProcessHeap(), 0, len);
688 strcpy(command, user);
689 strcat(command, This->InetTransport.ServerInfo.szUserName);
690 strcat(command, "\r\n");
691 InternetTransport_DoCommand(&This->InetTransport, command, POP3Transport_CallbackRecvUSERResp);
693 HeapFree(GetProcessHeap(), 0, command);
696 static void POP3Transport_CallbackProcessQUITResponse(IInternetTransport *iface, char *pBuffer, int cbBuffer)
698 POP3Transport *This = (POP3Transport *)iface;
699 POP3RESPONSE response;
702 TRACE("%s\n", debugstr_an(pBuffer, cbBuffer));
704 hr = POP3Transport_ParseResponse(This, pBuffer, &response);
707 /* FIXME: handle error */
711 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
712 InternetTransport_DropConnection(&This->InetTransport);
715 static void POP3Transport_CallbackRecvQUITResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
717 POP3Transport *This = (POP3Transport *)iface;
720 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessQUITResponse);
723 static HRESULT WINAPI POP3Transport_QueryInterface(IPOP3Transport *iface, REFIID riid, void **ppv)
725 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
727 if (IsEqualIID(riid, &IID_IUnknown) ||
728 IsEqualIID(riid, &IID_IInternetTransport) ||
729 IsEqualIID(riid, &IID_IPOP3Transport))
732 IUnknown_AddRef(iface);
736 FIXME("no interface for %s\n", debugstr_guid(riid));
737 return E_NOINTERFACE;
740 static ULONG WINAPI POP3Transport_AddRef(IPOP3Transport *iface)
742 POP3Transport *This = (POP3Transport *)iface;
743 return InterlockedIncrement((LONG *)&This->refs);
746 static ULONG WINAPI POP3Transport_Release(IPOP3Transport *iface)
748 POP3Transport *This = (POP3Transport *)iface;
749 ULONG refs = InterlockedDecrement((LONG *)&This->refs);
752 TRACE("destroying %p\n", This);
753 if (This->InetTransport.Status != IXP_DISCONNECTED)
754 InternetTransport_DropConnection(&This->InetTransport);
755 if (This->InetTransport.pCallback) ITransportCallback_Release(This->InetTransport.pCallback);
756 HeapFree(GetProcessHeap(), 0, This);
761 static HRESULT WINAPI POP3Transport_GetServerInfo(IPOP3Transport *iface,
762 LPINETSERVER pInetServer)
764 POP3Transport *This = (POP3Transport *)iface;
766 TRACE("(%p)\n", pInetServer);
767 return InternetTransport_GetServerInfo(&This->InetTransport, pInetServer);
770 static IXPTYPE WINAPI POP3Transport_GetIXPType(IPOP3Transport *iface)
776 static HRESULT WINAPI POP3Transport_IsState(IPOP3Transport *iface, IXPISSTATE isstate)
778 FIXME("(%u)\n", isstate);
782 static HRESULT WINAPI POP3Transport_InetServerFromAccount(
783 IPOP3Transport *iface, IImnAccount *pAccount, LPINETSERVER pInetServer)
785 POP3Transport *This = (POP3Transport *)iface;
787 TRACE("(%p, %p)\n", pAccount, pInetServer);
788 return InternetTransport_InetServerFromAccount(&This->InetTransport, pAccount, pInetServer);
791 static HRESULT WINAPI POP3Transport_Connect(IPOP3Transport *iface,
792 LPINETSERVER pInetServer, boolean fAuthenticate, boolean fCommandLogging)
794 POP3Transport *This = (POP3Transport *)iface;
797 TRACE("(%p, %s, %s)\n", pInetServer, fAuthenticate ? "TRUE" : "FALSE", fCommandLogging ? "TRUE" : "FALSE");
799 hr = InternetTransport_Connect(&This->InetTransport, pInetServer, fAuthenticate, fCommandLogging);
803 init_parser(This, POP3_USER, POP3_NONE);
804 return InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackSendUSERCmd);
807 static HRESULT WINAPI POP3Transport_HandsOffCallback(IPOP3Transport *iface)
809 POP3Transport *This = (POP3Transport *)iface;
812 return InternetTransport_HandsOffCallback(&This->InetTransport);
815 static HRESULT WINAPI POP3Transport_Disconnect(IPOP3Transport *iface)
818 return IPOP3Transport_CommandQUIT(iface);
821 static HRESULT WINAPI POP3Transport_DropConnection(IPOP3Transport *iface)
823 POP3Transport *This = (POP3Transport *)iface;
826 return InternetTransport_DropConnection(&This->InetTransport);
829 static HRESULT WINAPI POP3Transport_GetStatus(IPOP3Transport *iface,
830 IXPSTATUS *pCurrentStatus)
832 POP3Transport *This = (POP3Transport *)iface;
835 return InternetTransport_GetStatus(&This->InetTransport, pCurrentStatus);
838 static HRESULT WINAPI POP3Transport_InitNew(IPOP3Transport *iface,
839 LPSTR pszLogFilePath, IPOP3Callback *pCallback)
841 POP3Transport *This = (POP3Transport *)iface;
843 TRACE("(%s, %p)\n", debugstr_a(pszLogFilePath), pCallback);
849 FIXME("not using log file of %s, use Wine debug logging instead\n",
850 debugstr_a(pszLogFilePath));
852 IPOP3Callback_AddRef(pCallback);
853 This->InetTransport.pCallback = (ITransportCallback *)pCallback;
854 This->InetTransport.fInitialised = TRUE;
859 static HRESULT WINAPI POP3Transport_MarkItem(IPOP3Transport *iface, POP3MARKTYPE marktype,
860 DWORD dwPopId, boolean fMarked)
862 FIXME("(%u, %u, %d)\n", marktype, dwPopId, fMarked);
866 static HRESULT WINAPI POP3Transport_CommandAUTH(IPOP3Transport *iface, LPSTR pszAuthType)
868 FIXME("(%s)\n", pszAuthType);
872 static HRESULT WINAPI POP3Transport_CommandUSER(IPOP3Transport *iface, LPSTR username)
874 static char user[] = "USER ";
875 POP3Transport *This = (POP3Transport *)iface;
879 TRACE("(%s)\n", username);
881 len = sizeof(user) + strlen(username) + 2; /* "\r\n" */
882 if (!(command = HeapAlloc(GetProcessHeap(), 0, len))) return S_FALSE;
884 strcpy(command, user);
885 strcat(command, username);
886 strcat(command, "\r\n");
888 init_parser(This, POP3_USER, POP3_NONE);
889 InternetTransport_DoCommand(&This->InetTransport, command, POP3Transport_CallbackRecvUSERResp);
891 HeapFree(GetProcessHeap(), 0, command);
895 static HRESULT WINAPI POP3Transport_CommandPASS(IPOP3Transport *iface, LPSTR password)
897 static char pass[] = "PASS ";
898 POP3Transport *This = (POP3Transport *)iface;
902 TRACE("(%p)\n", password);
904 len = sizeof(pass) + strlen(password) + 2; /* "\r\n" */
905 if (!(command = HeapAlloc(GetProcessHeap(), 0, len))) return S_FALSE;
907 strcpy(command, pass);
908 strcat(command, password);
909 strcat(command, "\r\n");
911 init_parser(This, POP3_PASS, POP3_NONE);
912 InternetTransport_DoCommand(&This->InetTransport, command, POP3Transport_CallbackRecvPASSResp);
914 HeapFree(GetProcessHeap(), 0, command);
918 static HRESULT WINAPI POP3Transport_CommandLIST(
919 IPOP3Transport *iface, POP3CMDTYPE cmdtype, DWORD dwPopId)
921 static char list[] = "LIST %u\r\n";
922 static char list_all[] = "LIST\r\n";
923 POP3Transport *This = (POP3Transport *)iface;
927 TRACE("(%u, %u)\n", cmdtype, dwPopId);
931 len = sizeof(list) + 10 + 2; /* "4294967296" + "\r\n" */
932 if (!(command = HeapAlloc(GetProcessHeap(), 0, len))) return S_FALSE;
933 sprintf(command, list, dwPopId);
935 else command = list_all;
937 init_parser(This, POP3_LIST, 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 char top[] = "TOP %u %u\r\n";
948 POP3Transport *This = (POP3Transport *)iface;
952 TRACE("(%u, %u, %u)\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, cmdtype);
960 InternetTransport_DoCommand(&This->InetTransport, command, POP3Transport_CallbackRecvTOPResp);
962 HeapFree(GetProcessHeap(), 0, command);
966 static HRESULT WINAPI POP3Transport_CommandQUIT(IPOP3Transport *iface)
968 static char command[] = "QUIT\r\n";
969 POP3Transport *This = (POP3Transport *)iface;
973 InternetTransport_ChangeStatus(&This->InetTransport, IXP_DISCONNECTING);
975 init_parser(This, POP3_QUIT, POP3_NONE);
976 return InternetTransport_DoCommand(&This->InetTransport, command, POP3Transport_CallbackRecvQUITResp);
979 static HRESULT WINAPI POP3Transport_CommandSTAT(IPOP3Transport *iface)
981 static char stat[] = "STAT\r\n";
982 POP3Transport *This = (POP3Transport *)iface;
986 init_parser(This, POP3_STAT, POP3_NONE);
987 InternetTransport_DoCommand(&This->InetTransport, stat, POP3Transport_CallbackRecvSTATResp);
991 static HRESULT WINAPI POP3Transport_CommandNOOP(IPOP3Transport *iface)
993 static char noop[] = "NOOP\r\n";
994 POP3Transport *This = (POP3Transport *)iface;
998 init_parser(This, POP3_NOOP, POP3_NONE);
999 InternetTransport_DoCommand(&This->InetTransport, noop, POP3Transport_CallbackRecvNOOPResp);
1003 static HRESULT WINAPI POP3Transport_CommandRSET(IPOP3Transport *iface)
1005 static char rset[] = "RSET\r\n";
1006 POP3Transport *This = (POP3Transport *)iface;
1010 init_parser(This, POP3_RSET, POP3_NONE);
1011 InternetTransport_DoCommand(&This->InetTransport, rset, POP3Transport_CallbackRecvRSETResp);
1015 static HRESULT WINAPI POP3Transport_CommandUIDL(
1016 IPOP3Transport *iface, POP3CMDTYPE cmdtype, DWORD dwPopId)
1018 static char uidl[] = "UIDL %u\r\n";
1019 static char uidl_all[] = "UIDL\r\n";
1020 POP3Transport *This = (POP3Transport *)iface;
1024 TRACE("(%u, %u)\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, cmdtype);
1035 InternetTransport_DoCommand(&This->InetTransport, command, POP3Transport_CallbackRecvUIDLResp);
1037 if (dwPopId) HeapFree(GetProcessHeap(), 0, command);
1041 static HRESULT WINAPI POP3Transport_CommandDELE(
1042 IPOP3Transport *iface, POP3CMDTYPE cmdtype, DWORD dwPopId)
1044 static char dele[] = "DELE %u\r\n";
1045 POP3Transport *This = (POP3Transport *)iface;
1049 TRACE("(%u, %u)\n", cmdtype, dwPopId);
1051 len = sizeof(dele) + 10 + 2; /* "4294967296" + "\r\n" */
1052 if (!(command = HeapAlloc(GetProcessHeap(), 0, len))) return S_FALSE;
1053 sprintf(command, dele, dwPopId);
1055 init_parser(This, POP3_DELE, cmdtype);
1056 InternetTransport_DoCommand(&This->InetTransport, command, POP3Transport_CallbackRecvDELEResp);
1058 HeapFree(GetProcessHeap(), 0, command);
1062 static HRESULT WINAPI POP3Transport_CommandRETR(
1063 IPOP3Transport *iface, POP3CMDTYPE cmdtype, DWORD dwPopId)
1065 static char retr[] = "RETR %u\r\n";
1066 POP3Transport *This = (POP3Transport *)iface;
1070 TRACE("(%u, %u)\n", cmdtype, dwPopId);
1072 len = sizeof(retr) + 10 + 2; /* "4294967296" + "\r\n" */
1073 if (!(command = HeapAlloc(GetProcessHeap(), 0, len))) return S_FALSE;
1074 sprintf(command, retr, dwPopId);
1076 init_parser(This, POP3_RETR, cmdtype);
1077 InternetTransport_DoCommand(&This->InetTransport, command, POP3Transport_CallbackRecvRETRResp);
1079 HeapFree(GetProcessHeap(), 0, command);
1083 static const IPOP3TransportVtbl POP3TransportVtbl =
1085 POP3Transport_QueryInterface,
1086 POP3Transport_AddRef,
1087 POP3Transport_Release,
1088 POP3Transport_GetServerInfo,
1089 POP3Transport_GetIXPType,
1090 POP3Transport_IsState,
1091 POP3Transport_InetServerFromAccount,
1092 POP3Transport_Connect,
1093 POP3Transport_HandsOffCallback,
1094 POP3Transport_Disconnect,
1095 POP3Transport_DropConnection,
1096 POP3Transport_GetStatus,
1097 POP3Transport_InitNew,
1098 POP3Transport_MarkItem,
1099 POP3Transport_CommandAUTH,
1100 POP3Transport_CommandUSER,
1101 POP3Transport_CommandPASS,
1102 POP3Transport_CommandLIST,
1103 POP3Transport_CommandTOP,
1104 POP3Transport_CommandQUIT,
1105 POP3Transport_CommandSTAT,
1106 POP3Transport_CommandNOOP,
1107 POP3Transport_CommandRSET,
1108 POP3Transport_CommandUIDL,
1109 POP3Transport_CommandDELE,
1110 POP3Transport_CommandRETR
1113 HRESULT WINAPI CreatePOP3Transport(IPOP3Transport **ppTransport)
1116 POP3Transport *This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
1118 return E_OUTOFMEMORY;
1120 This->InetTransport.u.vtblPOP3 = &POP3TransportVtbl;
1122 hr = InternetTransport_Init(&This->InetTransport);
1125 HeapFree(GetProcessHeap(), 0, This);
1129 *ppTransport = (IPOP3Transport *)&This->InetTransport.u.vtblPOP3;
1130 IPOP3Transport_AddRef(*ppTransport);
1135 static HRESULT WINAPI POP3TransportCF_QueryInterface(LPCLASSFACTORY iface,
1136 REFIID riid, LPVOID *ppv)
1139 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory))
1142 IUnknown_AddRef(iface);
1145 return E_NOINTERFACE;
1148 static ULONG WINAPI POP3TransportCF_AddRef(LPCLASSFACTORY iface)
1150 return 2; /* non-heap based object */
1153 static ULONG WINAPI POP3TransportCF_Release(LPCLASSFACTORY iface)
1155 return 1; /* non-heap based object */
1158 static HRESULT WINAPI POP3TransportCF_CreateInstance(LPCLASSFACTORY iface,
1159 LPUNKNOWN pUnk, REFIID riid, LPVOID *ppv)
1162 IPOP3Transport *pPop3Transport;
1164 TRACE("(%p, %s, %p)\n", pUnk, debugstr_guid(riid), ppv);
1169 return CLASS_E_NOAGGREGATION;
1171 hr = CreatePOP3Transport(&pPop3Transport);
1175 hr = IPOP3Transport_QueryInterface(pPop3Transport, riid, ppv);
1176 IPOP3Transport_Release(pPop3Transport);
1181 static HRESULT WINAPI POP3TransportCF_LockServer(LPCLASSFACTORY iface, BOOL fLock)
1183 FIXME("(%d)\n",fLock);
1187 static const IClassFactoryVtbl POP3TransportCFVtbl =
1189 POP3TransportCF_QueryInterface,
1190 POP3TransportCF_AddRef,
1191 POP3TransportCF_Release,
1192 POP3TransportCF_CreateInstance,
1193 POP3TransportCF_LockServer
1195 static const IClassFactoryVtbl *POP3TransportCF = &POP3TransportCFVtbl;
1197 HRESULT POP3TransportCF_Create(REFIID riid, LPVOID *ppv)
1199 return IClassFactory_QueryInterface((IClassFactory *)&POP3TransportCF, riid, ppv);