11 #include <sys/types.h>
19 #include "sysdep_decls.h"
20 #include "citserver.h"
23 #include "dynloader.h"
30 #include "internet_addressing.h"
40 struct citpop3 { /* Information about the current session */
45 #define POP3 ((struct citpop3 *)CtdlGetUserData(SYM_POP3))
50 void pop3_cleanup_function(void) {
53 lprintf(9, "Performing POP3 cleanup hook\n");
55 if (POP3->num_msgs > 0) for (i=0; i<POP3->num_msgs; ++i) {
56 fclose(POP3->msgs[i].temp);
58 if (POP3->msgs != NULL) phree(POP3->msgs);
64 * Here's where our POP3 session begins its happy day.
66 void pop3_greeting(void) {
68 strcpy(CC->cs_clientname, "POP3 session");
70 CtdlAllocUserData(SYM_POP3, sizeof(struct citpop3));
74 cprintf("+OK Welcome to the Citadel/UX POP3 server at %s\r\n",
80 * Specify user name (implements POP3 "USER" command)
82 void pop3_user(char *argbuf) {
86 cprintf("-ERR You are already logged in.\r\n");
90 strcpy(username, argbuf);
93 lprintf(9, "Trying <%s>\n", username);
94 if (CtdlLoginExistingUser(username) == login_ok) {
95 cprintf("+OK Password required for %s\r\n", username);
98 cprintf("-ERR No such user.\r\n");
104 * Authorize with password (implements POP3 "PASS" command)
106 void pop3_pass(char *argbuf) {
109 strcpy(password, argbuf);
112 lprintf(9, "Trying <%s>\n", password);
113 if (CtdlTryPassword(password) == pass_ok) {
114 if (getroom(&CC->quickroom, MAILROOM) == 0) {
115 cprintf("+OK %s is logged in!\r\n",
116 CC->usersupp.fullname);
117 lprintf(9, "POP3 password login successful\n");
120 cprintf("-ERR can't find your mailbox\r\n");
124 cprintf("-ERR That is NOT the password! Go away!\r\n");
131 * list available msgs
133 void pop3_list(char *argbuf) {
134 cprintf("-ERR oops, not finished\r\n");
141 * Main command loop for POP3 sessions.
143 void pop3_command_loop(void) {
147 memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
148 if (client_gets(cmdbuf) < 1) {
149 lprintf(3, "POP3 socket is broken. Ending session.\r\n");
153 lprintf(5, "citserver[%3d]: %s\r\n", CC->cs_pid, cmdbuf);
154 while (strlen(cmdbuf) < 5) strcat(cmdbuf, " ");
156 if (!strncasecmp(cmdbuf, "NOOP", 4)) {
157 cprintf("+OK This command successfully did nothing.\r\n");
160 else if (!strncasecmp(cmdbuf, "QUIT", 4)) {
161 cprintf("+OK Goodbye...\r\n");
166 else if (!strncasecmp(cmdbuf, "USER", 4)) {
167 pop3_user(&cmdbuf[5]);
170 else if (!strncasecmp(cmdbuf, "PASS", 4)) {
171 pop3_pass(&cmdbuf[5]);
174 else if (!CC->logged_in) {
175 cprintf("-ERR Not logged in.\r\n");
178 else if (!strncasecmp(cmdbuf, "LIST", 4)) {
179 pop3_list(&cmdbuf[5]);
183 cprintf("500 I'm afraid I can't do that, Dave.\r\n");
190 char *Dynamic_Module_Init(void)
192 SYM_POP3 = CtdlGetDynamicSymbol();
193 CtdlRegisterServiceHook(POP3_PORT,
196 CtdlRegisterSessionHook(pop3_cleanup_function, EVT_STOP);