11 #include <sys/types.h>
19 #include "sysdep_decls.h"
20 #include "citserver.h"
23 #include "dynloader.h"
30 #include "internet_addressing.h"
31 #include "serv_pop3.h"
37 void pop3_cleanup_function(void) {
40 /* Don't do this stuff if this is not a POP3 session! */
41 if (CC->h_command_function != pop3_command_loop) return;
43 lprintf(9, "Performing POP3 cleanup hook\n");
45 if (POP3->num_msgs > 0) for (i=0; i<POP3->num_msgs; ++i) {
46 fclose(POP3->msgs[i].temp);
48 if (POP3->msgs != NULL) phree(POP3->msgs);
50 lprintf(9, "Finished POP3 cleanup hook\n");
56 * Here's where our POP3 session begins its happy day.
58 void pop3_greeting(void) {
60 strcpy(CC->cs_clientname, "POP3 session");
62 CtdlAllocUserData(SYM_POP3, sizeof(struct citpop3));
66 cprintf("+OK Welcome to the Citadel/UX POP3 server at %s\r\n",
72 * Specify user name (implements POP3 "USER" command)
74 void pop3_user(char *argbuf) {
78 cprintf("-ERR You are already logged in.\r\n");
82 strcpy(username, argbuf);
85 lprintf(9, "Trying <%s>\n", username);
86 if (CtdlLoginExistingUser(username) == login_ok) {
87 cprintf("+OK Password required for %s\r\n", username);
90 cprintf("-ERR No such user.\r\n");
96 * Authorize with password (implements POP3 "PASS" command)
98 void pop3_pass(char *argbuf) {
101 strcpy(password, argbuf);
104 lprintf(9, "Trying <%s>\n", password);
105 if (CtdlTryPassword(password) == pass_ok) {
106 if (getroom(&CC->quickroom, MAILROOM) == 0) {
107 cprintf("+OK %s is logged in!\r\n",
108 CC->usersupp.fullname);
109 lprintf(9, "POP3 password login successful\n");
112 cprintf("-ERR can't find your mailbox\r\n");
116 cprintf("-ERR That is NOT the password! Go away!\r\n");
123 * list available msgs
125 void pop3_list(char *argbuf) {
126 cprintf("-ERR oops, not finished\r\n");
133 * Main command loop for POP3 sessions.
135 void pop3_command_loop(void) {
139 memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
140 if (client_gets(cmdbuf) < 1) {
141 lprintf(3, "POP3 socket is broken. Ending session.\r\n");
145 lprintf(5, "citserver[%3d]: %s\r\n", CC->cs_pid, cmdbuf);
146 while (strlen(cmdbuf) < 5) strcat(cmdbuf, " ");
148 if (!strncasecmp(cmdbuf, "NOOP", 4)) {
149 cprintf("+OK This command successfully did nothing.\r\n");
152 else if (!strncasecmp(cmdbuf, "QUIT", 4)) {
153 cprintf("+OK Goodbye...\r\n");
158 else if (!strncasecmp(cmdbuf, "USER", 4)) {
159 pop3_user(&cmdbuf[5]);
162 else if (!strncasecmp(cmdbuf, "PASS", 4)) {
163 pop3_pass(&cmdbuf[5]);
166 else if (!CC->logged_in) {
167 cprintf("-ERR Not logged in.\r\n");
170 else if (!strncasecmp(cmdbuf, "LIST", 4)) {
171 pop3_list(&cmdbuf[5]);
175 cprintf("500 I'm afraid I can't do that, Dave.\r\n");
182 char *Dynamic_Module_Init(void)
184 SYM_POP3 = CtdlGetDynamicSymbol();
185 CtdlRegisterServiceHook(POP3_PORT,
188 CtdlRegisterSessionHook(pop3_cleanup_function, EVT_STOP);