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
ACLOCAL_AMFLAGS = -I m4
# imap4d
SUBDIRS = include doc m4 lib mailbox from mail libmailbox pop3d
#SUBDIRS = lib mailbox mail doc m4
SUBDIRS = include doc m4 lib mailbox from mail pop3d
#SUBDIRS = imap4d
EXTRA_DIST = mailutils.spec mailutils.spec.in
......
......@@ -71,7 +71,7 @@ AC_CHECK_FUNC(socket, [true],
AC_CHECK_LIB(socket, socket, LIBS="-lsocket $LIBS"))
dnl Output Makefiles
AC_OUTPUT(Makefile include/Makefile include/mailutils/Makefile m4/Makefile doc/Makefile
lib/Makefile mailbox/Makefile mailbox/include/Makefile libmailbox/Makefile
from/Makefile mail/Makefile pop3d/Makefile)
AC_OUTPUT(Makefile mailutils.spec include/Makefile include/mailutils/Makefile
m4/Makefile doc/Makefile lib/Makefile mailbox/Makefile
mailbox/include/Makefile from/Makefile mail/Makefile pop3d/Makefile)
......
......@@ -10,4 +10,4 @@ mail_SOURCES = alias.c alt.c bang.c cd.c copy.c delete.c discard.c dp.c \
headers.c help.c hold.c if.c list.c mail.c mail.h mbox.c next.c pipe.c \
previous.c print.c printall.c quit.c relist.c reply.c retain.c save.c \
send.c set.c shell.c size.c source.c top.c touch.c unalias.c \
undelete.c unset.c util.c visual.c write.c z.c
undelete.c unset.c util.c visual.c write.c z.c table.h
......
# -*- Shell-script -*-
%define ver @VERSION@
%define RELEASE 1
%define prefix /usr
Summary: GNU mail utilities
Name: mailutils
Version: %ver
Release: %rel
Copyright: GPL
Source: ftp://ftp.gnu.org/pub/mailutils/mailutils-%{ver}.tar.gz
BuildRoot: /var/tmp/mailutils-%{PACKAGE_VERSION}-root
Packager: Jakob 'sparky' Kaivo <jkaivo@gnu.org>
URL: http://www.gnu.org/software/mailutils/mailutils.html
Group: Console/Mail
%description
GNU mail utilities
%package libmailbox
Summary: GNU mail utilities mailbox access library
Copyright: LGPL
Group: Development/Libraries
%description libmailbox
The runtime library libmailbox. This library contains various mailbox
access routines and support for a number of mailbox types, such as
mbox, Maildir, POP3, and IMAP4.
%package libmailbox-devel
Summary: GNU mail utilities mailbox access library development
Copyright: LGPL
Requires: libmailbox
Group: Development/Libraries
%description libmailbox-devel
The static library and header files for libmailbox. API documentation
is in mailutils-doc.
%package doc
Summary: GNU mail utitlies documentation
Prereq: /sbin/install-info
Group: Development/Libraries
%description doc
API reference for libmailbox and user documentation for the rest of
the GNU mail utilities.
%package mail
Summary: GNU mail utilties mail(x) replacement
Requires: libmailbox
Group: Console/Mail
%description mail
A replacement for /bin/mail(x) conforming to the UNIX98 specification
for mailx.
%package pop3d
Summary: GNU mail utilites POP3 daemon
Requires: libmailbox
Group: Networking/Daemons
%description pop3d
The GNU POP3 daemon. Uses libmailbox to support different styles of
mailboxes.
%prep
%setup
%build
./configure --prefix=%prefix
make
%install
rm -rf $RPM_BUILD_ROOT
make prefix=$RPM_BUILD_ROOT%{prefix} install-strip
gzip -9n $RPM_BUILD_ROOT%{prefix}/info/*
%clean
rm -rf $RPM_BUILD_ROOT
%post libmailbox -p /sbin/ldconfig
%postun libmailbox -p /sbin/ldconfig
%post doc
/sbin/install-info %{prefix}/info/mailutils.info.gz %{prefix}/info/dir
%preun doc
/sbin/install-info --delete %{prefix}/info/mailutils.info.gz \
%{prefix}/info/dif
%files libmailbox
%defattr(-, root, root)
%{prefix}/lib/libmailbox.so.*
%files libmailbox-devel
%defattr(-, root, root)
%{prefix}/lib/lib*.so
%{prefix}/lib/*a
%files doc
%defattr(-, root, root)
%doc AUTHORS COPYING ChangeLog NEWS README THANKS TODO
%{prefix}/info/*
%files mail
%defattr(-, root, root)
%{prefix}/bin/mail
%files pop3d
%defattr(-, root, root)
%{prefix}/sbin/pop3d
......@@ -169,46 +169,23 @@ pop3_apop (const char *arg)
return ERR_BAD_LOGIN;
}
#ifdef MAILSPOOLHOME
if (pw != NULL)
if (mailbox_create_default (&mbox, username) != 0)
{
chdir (pw->pw_dir);
mbox = mbox_open (MAILSPOOLHOME);
}
else
mbox = NULL;
if (mbox == NULL)
{
chdir (_PATH_MAILDIR);
#endif /* MAILSPOOLHOME */
mbox = mbox_open (username);
if (mbox == NULL)
{
state = AUTHORIZATION;
return ERR_MBOX_LOCK;
}
#ifdef MAILSPOOLHOME
free (username);
state = AUTHORIZATION;
return ERR_UNKNOWN;
}
#endif
#if 0
if ((pw->pw_uid < 1)
#ifdef MAILSPOOLHOME
/* Drop mail group for home dirs */
|| setgid (pw->pw_gid) == -1
#endif
|| setuid (pw->pw_uid) == -1)
else if (mailbox_open (mbox, 0) != 0)
{
pop3_unlock ();
free (mailbox);
return ERR_BAD_LOGIN;
free (username);
state = AUTHORIZATION;
return ERR_MBOX_LOCK;
}
#endif /* 0 */
state = TRANSACTION;
fprintf (ofile, "+OK opened mailbox for %s\r\n", username);
syslog (LOG_INFO, "User %s logged in with mailbox %s", username, mbox->name);
/* FIXME: how to get mailbox name? */
syslog (LOG_INFO, "User %s logged in with mailbox %s", username, NULL);
return OK;
}
......
......@@ -30,8 +30,8 @@ pop3_dele (const char *arg)
if (state != TRANSACTION)
return ERR_WRONG_STATE;
num = atoi (arg) - 1;
if (mbox_delete(mbox, num) != 0)
num = atoi (arg);
if (/* FIXME: mailbox_delete (mbox, num) != */ 0)
return ERR_NO_MESG;
fprintf (ofile, "+OK Message %d marked\r\n", num + 1);
......
......@@ -22,7 +22,8 @@
int
pop3_list (const char *arg)
{
int mesg = 0;
int mesg = 0, size = 0;
message_t msg;
if (state != TRANSACTION)
return ERR_WRONG_STATE;
......@@ -30,20 +31,29 @@ pop3_list (const char *arg)
if (strchr (arg, ' ') != NULL)
return ERR_BAD_ARGS;
/* FIXME: how to find if mailbox is deleted, how to get size */
if (strlen (arg) == 0)
{
int total;
mailbox_messages_count (mbox, &total);
fprintf (ofile, "+OK\r\n");
for (mesg = 0; mesg < mbox->messages ; mesg++)
if (!mbox_is_deleted(mbox, mesg))
fprintf (ofile, "%d %d\r\n", mesg + 1, mbox->sizes[mesg]);
for (mesg = 1; mesg <= total; mesg++)
{
mailbox_get_message (mbox, &msg, mesg);
/* if ! deleted */
/* message_get_size (msg, &size); */
fprintf (ofile, "%d %d\r\n", mesg, size);
}
fprintf (ofile, ".\r\n");
}
else
{
mesg = atoi (arg) - 1;
if (mesg > mbox->messages || mbox_is_deleted(mbox, mesg))
mesg = atoi (arg);
if (mailbox_get_message (mbox, &msg, mesg) != 0)
return ERR_NO_MESG;
fprintf (ofile, "+OK %d %d\r\n", mesg + 1, mbox->sizes[mesg]);
/* message_get_size (msg, &size); */
fprintf (ofile, "+OK %d %d\r\n", mesg, size);
}
return OK;
......
......@@ -64,6 +64,9 @@
/* Longest legal POP command */
#define POP_MAXCMDLEN 255
/* Buffer size to use for output */
#define BUFFERSIZE 1024
#define _GNU_SOURCE
#include <stdarg.h>
#include <stdio.h>
......@@ -136,6 +139,7 @@
#define ERR_FILE 12
#define ERR_NO_OFILE 13
#define ERR_TIMEOUT 14
#define ERR_UNKNOWN 15
mailbox_t mbox;
......
......@@ -22,8 +22,8 @@
int
pop3_retr (const char *arg)
{
unsigned int mesg, size;
char *buf;
unsigned int mesg, size, read = 0;
char buf[BUFFERSIZE];
message_t msg;
header_t hdr;
body_t body;
......@@ -35,12 +35,7 @@ pop3_retr (const char *arg)
if (state != TRANSACTION)
return ERR_WRONG_STATE;
mesg = atoi (arg) - 1;
#ifdef OLD_API
if (mesg >= mbox->messages || mbox_is_deleted(mbox, mesg))
return ERR_NO_MESG;
#endif
mesg = atoi (arg);
if (mailbox_get_message (mbox, mesg, &msg) != 0)
return ERR_NO_MESG;
......@@ -49,20 +44,27 @@ pop3_retr (const char *arg)
message_get_body (msg, &body);
/* Header */
fprintf (ofile, "+OK\r\n");
header_get_stream (hdr, &stream);
header_size (hdr, &size);
buf = malloc (size);
stream_read (stream, buf, size, 0, NULL);
fprintf (ofile, "+OK\r\n%s", buf);
free(buf);
while (read < size)
{
stream_read (stream, buf, BUFFERSIZE, 0, NULL);
fprintf (ofile, "%s", buf);
read += BUFFERSIZE;
}
/* body */
body_get_stream (body, &stream);
body_lines (body, &size);
buf = malloc (size);
stream_read (stream, buf, size, 0, NULL);
fprintf (ofile, "%s.\r\n", buf);
free (buf);
while (read < size)
{
stream_read (stream, buf, BUFFERSIZE, 0, NULL);
fprintf (ofile, "%s", buf);
read += BUFFERSIZE;
}
fprintf (ofile, ".\r\n");
return OK;
}
......
......@@ -22,7 +22,7 @@
int
pop3_rset (const char *arg)
{
int i;
int i = 0, total = 0;
if (strlen (arg) != 0)
return ERR_BAD_ARGS;
......@@ -30,8 +30,10 @@ pop3_rset (const char *arg)
if (state != TRANSACTION)
return ERR_WRONG_STATE;
for (i = 0; i < mbox->messages; i++)
mbox_undelete (mbox, i);
mailbox_messages_count (mbox, &total);
for (i = 1; i <= total; i++)
/* FIXME: undelete message i */ ;
fprintf (ofile, "+OK\r\n");
return OK;
......
......@@ -31,7 +31,8 @@ pop3_stat (const char *arg)
if (state != TRANSACTION)
return ERR_WRONG_STATE;
mailbox_size (mbox, &size);
/* FIXME: unimplemented! */
/* mailbox_size (mbox, &size); */
mailbox_messages_count (mbox, &mesgs);
fprintf (ofile, "+OK %d %d\r\n", mesgs, (int)size);
......
......@@ -38,7 +38,7 @@ pop3_top (const char *arg)
mesgc = pop3_cmd (arg);
linesc = pop3_args (arg);
mesg = atoi (mesgc) - 1;
mesg = atoi (mesgc);
lines = strlen (linesc) > 0 ? atoi (linesc) : -1;
free (mesgc);
free (linesc);
......@@ -46,11 +46,6 @@ pop3_top (const char *arg)
if (lines < 0)
return ERR_BAD_ARGS;
#ifdef OLD_API
if (mesg > mbox->messages || mbox_is_deleted(mbox, mesg))
return ERR_NO_MESG;
#endif
if (mailbox_get_message (mbox, mesg, &msg) != 0)
return ERR_NO_MESG;
......
......@@ -166,28 +166,18 @@ pop3_user (const char *arg)
openlog ("gnu-pop3d", LOG_PID, LOG_MAIL);
#endif /* USE_LIBPAM */
#ifdef MAILSPOOLHOME
if (pw != NULL)
if (mailbox_create_default (&mbox, arg) != 0)
{
chdir (pw->pw_dir);
mbox = mbox_open (MAILSPOOLHOME);
state = AUTHORIZATION;
return ERR_UNKNOWN;
}
else
mbox = NULL;
if (mbox == NULL) /* We should check errno here... */
else if (mailbox_open (mbox, 0) != 0)
{
chdir (_PATH_MAILDIR);
#endif /* MAILSPOOLHOME */
mbox = mbox_open (arg);
if (mbox == NULL) /* And here */
{
state = AUTHORIZATION;
return ERR_MBOX_LOCK;
}
#ifdef MAILSPOOLHOME
state = AUTHORIZATION;
return ERR_MBOX_LOCK;
}
#endif
username = strdup (arg);
if (username == NULL)
pop3_abquit (ERR_NO_MEM);
......@@ -196,11 +186,10 @@ pop3_user (const char *arg)
if (pw != NULL && pw->pw_uid > 1)
setuid (pw->pw_uid);
mbox_lock (mbox, MO_RLOCK | MO_WLOCK);
fprintf (ofile, "+OK opened mailbox for %s\r\n", username);
/* FIXME: mailbox name */
syslog (LOG_INFO, "User '%s' logged in with mailbox '%s'", username,
mbox->name);
NULL);
return OK;
}
else if (strcasecmp (cmd, "QUIT") == 0)
......