Commit 526e7396 526e7396c582c91ed466d5c351360eda2b2548d4 by Jakob Kaivo

Update pop3d more so it compiles against latest API (needs work still)

1 parent 50d842d2
...@@ -2,5 +2,7 @@ AUTOMAKE_OPTIONS = gnu 1.4 ...@@ -2,5 +2,7 @@ AUTOMAKE_OPTIONS = gnu 1.4
2 ACLOCAL_AMFLAGS = -I m4 2 ACLOCAL_AMFLAGS = -I m4
3 3
4 # imap4d 4 # imap4d
5 SUBDIRS = include doc m4 lib mailbox from mail libmailbox pop3d 5 SUBDIRS = include doc m4 lib mailbox from mail pop3d
6 #SUBDIRS = lib mailbox mail doc m4 6 #SUBDIRS = imap4d
7
8 EXTRA_DIST = mailutils.spec mailutils.spec.in
......
...@@ -71,7 +71,7 @@ AC_CHECK_FUNC(socket, [true], ...@@ -71,7 +71,7 @@ AC_CHECK_FUNC(socket, [true],
71 AC_CHECK_LIB(socket, socket, LIBS="-lsocket $LIBS")) 71 AC_CHECK_LIB(socket, socket, LIBS="-lsocket $LIBS"))
72 72
73 dnl Output Makefiles 73 dnl Output Makefiles
74 AC_OUTPUT(Makefile include/Makefile include/mailutils/Makefile m4/Makefile doc/Makefile 74 AC_OUTPUT(Makefile mailutils.spec include/Makefile include/mailutils/Makefile
75 lib/Makefile mailbox/Makefile mailbox/include/Makefile libmailbox/Makefile 75 m4/Makefile doc/Makefile lib/Makefile mailbox/Makefile
76 from/Makefile mail/Makefile pop3d/Makefile) 76 mailbox/include/Makefile from/Makefile mail/Makefile pop3d/Makefile)
77 77
......
...@@ -10,4 +10,4 @@ mail_SOURCES = alias.c alt.c bang.c cd.c copy.c delete.c discard.c dp.c \ ...@@ -10,4 +10,4 @@ mail_SOURCES = alias.c alt.c bang.c cd.c copy.c delete.c discard.c dp.c \
10 headers.c help.c hold.c if.c list.c mail.c mail.h mbox.c next.c pipe.c \ 10 headers.c help.c hold.c if.c list.c mail.c mail.h mbox.c next.c pipe.c \
11 previous.c print.c printall.c quit.c relist.c reply.c retain.c save.c \ 11 previous.c print.c printall.c quit.c relist.c reply.c retain.c save.c \
12 send.c set.c shell.c size.c source.c top.c touch.c unalias.c \ 12 send.c set.c shell.c size.c source.c top.c touch.c unalias.c \
13 undelete.c unset.c util.c visual.c write.c z.c 13 undelete.c unset.c util.c visual.c write.c z.c table.h
......
1 # -*- Shell-script -*-
2 %define ver @VERSION@
3 %define RELEASE 1
4 %define prefix /usr
5
6 Summary: GNU mail utilities
7 Name: mailutils
8 Version: %ver
9 Release: %rel
10 Copyright: GPL
11 Source: ftp://ftp.gnu.org/pub/mailutils/mailutils-%{ver}.tar.gz
12 BuildRoot: /var/tmp/mailutils-%{PACKAGE_VERSION}-root
13 Packager: Jakob 'sparky' Kaivo <jkaivo@gnu.org>
14 URL: http://www.gnu.org/software/mailutils/mailutils.html
15 Group: Console/Mail
16
17 %description
18 GNU mail utilities
19
20 %package libmailbox
21 Summary: GNU mail utilities mailbox access library
22 Copyright: LGPL
23 Group: Development/Libraries
24
25 %description libmailbox
26 The runtime library libmailbox. This library contains various mailbox
27 access routines and support for a number of mailbox types, such as
28 mbox, Maildir, POP3, and IMAP4.
29
30 %package libmailbox-devel
31 Summary: GNU mail utilities mailbox access library development
32 Copyright: LGPL
33 Requires: libmailbox
34 Group: Development/Libraries
35
36 %description libmailbox-devel
37 The static library and header files for libmailbox. API documentation
38 is in mailutils-doc.
39
40 %package doc
41 Summary: GNU mail utitlies documentation
42 Prereq: /sbin/install-info
43 Group: Development/Libraries
44
45 %description doc
46 API reference for libmailbox and user documentation for the rest of
47 the GNU mail utilities.
48
49 %package mail
50 Summary: GNU mail utilties mail(x) replacement
51 Requires: libmailbox
52 Group: Console/Mail
53
54 %description mail
55 A replacement for /bin/mail(x) conforming to the UNIX98 specification
56 for mailx.
57
58 %package pop3d
59 Summary: GNU mail utilites POP3 daemon
60 Requires: libmailbox
61 Group: Networking/Daemons
62
63 %description pop3d
64 The GNU POP3 daemon. Uses libmailbox to support different styles of
65 mailboxes.
66
67 %prep
68 %setup
69
70 %build
71 ./configure --prefix=%prefix
72 make
73
74 %install
75 rm -rf $RPM_BUILD_ROOT
76 make prefix=$RPM_BUILD_ROOT%{prefix} install-strip
77 gzip -9n $RPM_BUILD_ROOT%{prefix}/info/*
78
79 %clean
80 rm -rf $RPM_BUILD_ROOT
81
82 %post libmailbox -p /sbin/ldconfig
83
84 %postun libmailbox -p /sbin/ldconfig
85
86 %post doc
87 /sbin/install-info %{prefix}/info/mailutils.info.gz %{prefix}/info/dir
88
89 %preun doc
90 /sbin/install-info --delete %{prefix}/info/mailutils.info.gz \
91 %{prefix}/info/dif
92
93 %files libmailbox
94 %defattr(-, root, root)
95 %{prefix}/lib/libmailbox.so.*
96
97 %files libmailbox-devel
98 %defattr(-, root, root)
99 %{prefix}/lib/lib*.so
100 %{prefix}/lib/*a
101
102 %files doc
103 %defattr(-, root, root)
104 %doc AUTHORS COPYING ChangeLog NEWS README THANKS TODO
105 %{prefix}/info/*
106
107 %files mail
108 %defattr(-, root, root)
109 %{prefix}/bin/mail
110
111 %files pop3d
112 %defattr(-, root, root)
113 %{prefix}/sbin/pop3d
...@@ -169,46 +169,23 @@ pop3_apop (const char *arg) ...@@ -169,46 +169,23 @@ pop3_apop (const char *arg)
169 return ERR_BAD_LOGIN; 169 return ERR_BAD_LOGIN;
170 } 170 }
171 171
172 #ifdef MAILSPOOLHOME 172 if (mailbox_create_default (&mbox, username) != 0)
173 if (pw != NULL)
174 { 173 {
175 chdir (pw->pw_dir); 174 free (username);
176 mbox = mbox_open (MAILSPOOLHOME); 175 state = AUTHORIZATION;
176 return ERR_UNKNOWN;
177 } 177 }
178 else 178 else if (mailbox_open (mbox, 0) != 0)
179 mbox = NULL;
180
181 if (mbox == NULL)
182 {
183 chdir (_PATH_MAILDIR);
184 #endif /* MAILSPOOLHOME */
185 mbox = mbox_open (username);
186 if (mbox == NULL)
187 { 179 {
180 free (username);
188 state = AUTHORIZATION; 181 state = AUTHORIZATION;
189 return ERR_MBOX_LOCK; 182 return ERR_MBOX_LOCK;
190 } 183 }
191 #ifdef MAILSPOOLHOME
192 }
193 #endif
194
195 #if 0
196 if ((pw->pw_uid < 1)
197 #ifdef MAILSPOOLHOME
198 /* Drop mail group for home dirs */
199 || setgid (pw->pw_gid) == -1
200 #endif
201 || setuid (pw->pw_uid) == -1)
202 {
203 pop3_unlock ();
204 free (mailbox);
205 return ERR_BAD_LOGIN;
206 }
207 #endif /* 0 */
208 184
209 state = TRANSACTION; 185 state = TRANSACTION;
210 fprintf (ofile, "+OK opened mailbox for %s\r\n", username); 186 fprintf (ofile, "+OK opened mailbox for %s\r\n", username);
211 syslog (LOG_INFO, "User %s logged in with mailbox %s", username, mbox->name); 187 /* FIXME: how to get mailbox name? */
188 syslog (LOG_INFO, "User %s logged in with mailbox %s", username, NULL);
212 return OK; 189 return OK;
213 } 190 }
214 191
......
...@@ -30,8 +30,8 @@ pop3_dele (const char *arg) ...@@ -30,8 +30,8 @@ pop3_dele (const char *arg)
30 if (state != TRANSACTION) 30 if (state != TRANSACTION)
31 return ERR_WRONG_STATE; 31 return ERR_WRONG_STATE;
32 32
33 num = atoi (arg) - 1; 33 num = atoi (arg);
34 if (mbox_delete(mbox, num) != 0) 34 if (/* FIXME: mailbox_delete (mbox, num) != */ 0)
35 return ERR_NO_MESG; 35 return ERR_NO_MESG;
36 36
37 fprintf (ofile, "+OK Message %d marked\r\n", num + 1); 37 fprintf (ofile, "+OK Message %d marked\r\n", num + 1);
......
...@@ -22,7 +22,8 @@ ...@@ -22,7 +22,8 @@
22 int 22 int
23 pop3_list (const char *arg) 23 pop3_list (const char *arg)
24 { 24 {
25 int mesg = 0; 25 int mesg = 0, size = 0;
26 message_t msg;
26 27
27 if (state != TRANSACTION) 28 if (state != TRANSACTION)
28 return ERR_WRONG_STATE; 29 return ERR_WRONG_STATE;
...@@ -30,20 +31,29 @@ pop3_list (const char *arg) ...@@ -30,20 +31,29 @@ pop3_list (const char *arg)
30 if (strchr (arg, ' ') != NULL) 31 if (strchr (arg, ' ') != NULL)
31 return ERR_BAD_ARGS; 32 return ERR_BAD_ARGS;
32 33
34 /* FIXME: how to find if mailbox is deleted, how to get size */
35
33 if (strlen (arg) == 0) 36 if (strlen (arg) == 0)
34 { 37 {
38 int total;
39 mailbox_messages_count (mbox, &total);
35 fprintf (ofile, "+OK\r\n"); 40 fprintf (ofile, "+OK\r\n");
36 for (mesg = 0; mesg < mbox->messages ; mesg++) 41 for (mesg = 1; mesg <= total; mesg++)
37 if (!mbox_is_deleted(mbox, mesg)) 42 {
38 fprintf (ofile, "%d %d\r\n", mesg + 1, mbox->sizes[mesg]); 43 mailbox_get_message (mbox, &msg, mesg);
44 /* if ! deleted */
45 /* message_get_size (msg, &size); */
46 fprintf (ofile, "%d %d\r\n", mesg, size);
47 }
39 fprintf (ofile, ".\r\n"); 48 fprintf (ofile, ".\r\n");
40 } 49 }
41 else 50 else
42 { 51 {
43 mesg = atoi (arg) - 1; 52 mesg = atoi (arg);
44 if (mesg > mbox->messages || mbox_is_deleted(mbox, mesg)) 53 if (mailbox_get_message (mbox, &msg, mesg) != 0)
45 return ERR_NO_MESG; 54 return ERR_NO_MESG;
46 fprintf (ofile, "+OK %d %d\r\n", mesg + 1, mbox->sizes[mesg]); 55 /* message_get_size (msg, &size); */
56 fprintf (ofile, "+OK %d %d\r\n", mesg, size);
47 } 57 }
48 58
49 return OK; 59 return OK;
......
...@@ -64,6 +64,9 @@ ...@@ -64,6 +64,9 @@
64 /* Longest legal POP command */ 64 /* Longest legal POP command */
65 #define POP_MAXCMDLEN 255 65 #define POP_MAXCMDLEN 255
66 66
67 /* Buffer size to use for output */
68 #define BUFFERSIZE 1024
69
67 #define _GNU_SOURCE 70 #define _GNU_SOURCE
68 #include <stdarg.h> 71 #include <stdarg.h>
69 #include <stdio.h> 72 #include <stdio.h>
...@@ -136,6 +139,7 @@ ...@@ -136,6 +139,7 @@
136 #define ERR_FILE 12 139 #define ERR_FILE 12
137 #define ERR_NO_OFILE 13 140 #define ERR_NO_OFILE 13
138 #define ERR_TIMEOUT 14 141 #define ERR_TIMEOUT 14
142 #define ERR_UNKNOWN 15
139 143
140 mailbox_t mbox; 144 mailbox_t mbox;
141 145
......
...@@ -22,8 +22,8 @@ ...@@ -22,8 +22,8 @@
22 int 22 int
23 pop3_retr (const char *arg) 23 pop3_retr (const char *arg)
24 { 24 {
25 unsigned int mesg, size; 25 unsigned int mesg, size, read = 0;
26 char *buf; 26 char buf[BUFFERSIZE];
27 message_t msg; 27 message_t msg;
28 header_t hdr; 28 header_t hdr;
29 body_t body; 29 body_t body;
...@@ -35,12 +35,7 @@ pop3_retr (const char *arg) ...@@ -35,12 +35,7 @@ pop3_retr (const char *arg)
35 if (state != TRANSACTION) 35 if (state != TRANSACTION)
36 return ERR_WRONG_STATE; 36 return ERR_WRONG_STATE;
37 37
38 mesg = atoi (arg) - 1; 38 mesg = atoi (arg);
39
40 #ifdef OLD_API
41 if (mesg >= mbox->messages || mbox_is_deleted(mbox, mesg))
42 return ERR_NO_MESG;
43 #endif
44 39
45 if (mailbox_get_message (mbox, mesg, &msg) != 0) 40 if (mailbox_get_message (mbox, mesg, &msg) != 0)
46 return ERR_NO_MESG; 41 return ERR_NO_MESG;
...@@ -49,20 +44,27 @@ pop3_retr (const char *arg) ...@@ -49,20 +44,27 @@ pop3_retr (const char *arg)
49 message_get_body (msg, &body); 44 message_get_body (msg, &body);
50 45
51 /* Header */ 46 /* Header */
47 fprintf (ofile, "+OK\r\n");
52 header_get_stream (hdr, &stream); 48 header_get_stream (hdr, &stream);
53 header_size (hdr, &size); 49 header_size (hdr, &size);
54 buf = malloc (size); 50 while (read < size)
55 stream_read (stream, buf, size, 0, NULL); 51 {
56 fprintf (ofile, "+OK\r\n%s", buf); 52 stream_read (stream, buf, BUFFERSIZE, 0, NULL);
57 free(buf); 53 fprintf (ofile, "%s", buf);
54 read += BUFFERSIZE;
55 }
56
58 57
59 /* body */ 58 /* body */
60 body_get_stream (body, &stream); 59 body_get_stream (body, &stream);
61 body_lines (body, &size); 60 body_lines (body, &size);
62 buf = malloc (size); 61 while (read < size)
63 stream_read (stream, buf, size, 0, NULL); 62 {
64 fprintf (ofile, "%s.\r\n", buf); 63 stream_read (stream, buf, BUFFERSIZE, 0, NULL);
65 free (buf); 64 fprintf (ofile, "%s", buf);
65 read += BUFFERSIZE;
66 }
67 fprintf (ofile, ".\r\n");
66 68
67 return OK; 69 return OK;
68 } 70 }
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
22 int 22 int
23 pop3_rset (const char *arg) 23 pop3_rset (const char *arg)
24 { 24 {
25 int i; 25 int i = 0, total = 0;
26 26
27 if (strlen (arg) != 0) 27 if (strlen (arg) != 0)
28 return ERR_BAD_ARGS; 28 return ERR_BAD_ARGS;
...@@ -30,8 +30,10 @@ pop3_rset (const char *arg) ...@@ -30,8 +30,10 @@ pop3_rset (const char *arg)
30 if (state != TRANSACTION) 30 if (state != TRANSACTION)
31 return ERR_WRONG_STATE; 31 return ERR_WRONG_STATE;
32 32
33 for (i = 0; i < mbox->messages; i++) 33 mailbox_messages_count (mbox, &total);
34 mbox_undelete (mbox, i); 34
35 for (i = 1; i <= total; i++)
36 /* FIXME: undelete message i */ ;
35 37
36 fprintf (ofile, "+OK\r\n"); 38 fprintf (ofile, "+OK\r\n");
37 return OK; 39 return OK;
......
...@@ -31,7 +31,8 @@ pop3_stat (const char *arg) ...@@ -31,7 +31,8 @@ pop3_stat (const char *arg)
31 if (state != TRANSACTION) 31 if (state != TRANSACTION)
32 return ERR_WRONG_STATE; 32 return ERR_WRONG_STATE;
33 33
34 mailbox_size (mbox, &size); 34 /* FIXME: unimplemented! */
35 /* mailbox_size (mbox, &size); */
35 mailbox_messages_count (mbox, &mesgs); 36 mailbox_messages_count (mbox, &mesgs);
36 37
37 fprintf (ofile, "+OK %d %d\r\n", mesgs, (int)size); 38 fprintf (ofile, "+OK %d %d\r\n", mesgs, (int)size);
......
...@@ -38,7 +38,7 @@ pop3_top (const char *arg) ...@@ -38,7 +38,7 @@ pop3_top (const char *arg)
38 38
39 mesgc = pop3_cmd (arg); 39 mesgc = pop3_cmd (arg);
40 linesc = pop3_args (arg); 40 linesc = pop3_args (arg);
41 mesg = atoi (mesgc) - 1; 41 mesg = atoi (mesgc);
42 lines = strlen (linesc) > 0 ? atoi (linesc) : -1; 42 lines = strlen (linesc) > 0 ? atoi (linesc) : -1;
43 free (mesgc); 43 free (mesgc);
44 free (linesc); 44 free (linesc);
...@@ -46,11 +46,6 @@ pop3_top (const char *arg) ...@@ -46,11 +46,6 @@ pop3_top (const char *arg)
46 if (lines < 0) 46 if (lines < 0)
47 return ERR_BAD_ARGS; 47 return ERR_BAD_ARGS;
48 48
49 #ifdef OLD_API
50 if (mesg > mbox->messages || mbox_is_deleted(mbox, mesg))
51 return ERR_NO_MESG;
52 #endif
53
54 if (mailbox_get_message (mbox, mesg, &msg) != 0) 49 if (mailbox_get_message (mbox, mesg, &msg) != 0)
55 return ERR_NO_MESG; 50 return ERR_NO_MESG;
56 51
......
...@@ -166,28 +166,18 @@ pop3_user (const char *arg) ...@@ -166,28 +166,18 @@ pop3_user (const char *arg)
166 openlog ("gnu-pop3d", LOG_PID, LOG_MAIL); 166 openlog ("gnu-pop3d", LOG_PID, LOG_MAIL);
167 #endif /* USE_LIBPAM */ 167 #endif /* USE_LIBPAM */
168 168
169 #ifdef MAILSPOOLHOME
170 if (pw != NULL)
171 {
172 chdir (pw->pw_dir);
173 mbox = mbox_open (MAILSPOOLHOME);
174 }
175 else
176 mbox = NULL;
177 169
178 if (mbox == NULL) /* We should check errno here... */ 170 if (mailbox_create_default (&mbox, arg) != 0)
179 { 171 {
180 chdir (_PATH_MAILDIR); 172 state = AUTHORIZATION;
181 #endif /* MAILSPOOLHOME */ 173 return ERR_UNKNOWN;
182 mbox = mbox_open (arg); 174 }
183 if (mbox == NULL) /* And here */ 175 else if (mailbox_open (mbox, 0) != 0)
184 { 176 {
185 state = AUTHORIZATION; 177 state = AUTHORIZATION;
186 return ERR_MBOX_LOCK; 178 return ERR_MBOX_LOCK;
187 } 179 }
188 #ifdef MAILSPOOLHOME 180
189 }
190 #endif
191 username = strdup (arg); 181 username = strdup (arg);
192 if (username == NULL) 182 if (username == NULL)
193 pop3_abquit (ERR_NO_MEM); 183 pop3_abquit (ERR_NO_MEM);
...@@ -196,11 +186,10 @@ pop3_user (const char *arg) ...@@ -196,11 +186,10 @@ pop3_user (const char *arg)
196 if (pw != NULL && pw->pw_uid > 1) 186 if (pw != NULL && pw->pw_uid > 1)
197 setuid (pw->pw_uid); 187 setuid (pw->pw_uid);
198 188
199 mbox_lock (mbox, MO_RLOCK | MO_WLOCK);
200
201 fprintf (ofile, "+OK opened mailbox for %s\r\n", username); 189 fprintf (ofile, "+OK opened mailbox for %s\r\n", username);
190 /* FIXME: mailbox name */
202 syslog (LOG_INFO, "User '%s' logged in with mailbox '%s'", username, 191 syslog (LOG_INFO, "User '%s' logged in with mailbox '%s'", username,
203 mbox->name); 192 NULL);
204 return OK; 193 return OK;
205 } 194 }
206 else if (strcasecmp (cmd, "QUIT") == 0) 195 else if (strcasecmp (cmd, "QUIT") == 0)
......