Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated courier-imap, maildrop #30

Merged
merged 4 commits into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions courier-imap-x/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ libs/maildrop/maildrop
libs/maildrop/maildrop.1
libs/maildrop/maildropfilter.7
libs/maildrop/reformail
libs/maildrop/testtimer
libtool
maildiracl
maildiracl.1
Expand Down
2 changes: 1 addition & 1 deletion courier-imap-x/conf-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.2.2
5.2.3
7 changes: 7 additions & 0 deletions courier-imap-x/libs/imap/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
5.2.3

2023-02-19 Sam Varshavchik <[email protected]>

* all: update configure.ac to require at least version 2.0.5 of
libidn

5.2.2

2023-02-14 Sam Varshavchik <[email protected]>
Expand Down
1 change: 1 addition & 0 deletions courier-imap-x/libs/maildrop/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ reformail_LDADD = libmdcommon.la
reformail_DEPENDENCIES = $(reformail_LDADD)

bin_PROGRAMS=maildrop reformail mailbot
noinst_PROGRAMS=testtimer

mailbot_SOURCES=mailbot.c
mailbot_DEPENDENCIES=../rfc2045/librfc2045.la ../maildir/libmaildir.la \
Expand Down
129 changes: 14 additions & 115 deletions courier-imap-x/libs/maildrop/buffer.C
Original file line number Diff line number Diff line change
Expand Up @@ -7,135 +7,34 @@
#include <math.h>


#define CHUNK 512

void Buffer::append(int c)
{
int newsize=bufsize+CHUNK;
unsigned char *newbuf=new unsigned char[newsize];

if (!newbuf) outofmem();
if (bufsize) memcpy(newbuf, buf, bufsize);
if (buf) delete[] buf;
buf=newbuf;
bufsize = newsize;
buf[buflength++]=c;
}

void Buffer::set(const char *p)
void add_integer(std::string &b, unsigned long n)
{
int l=strlen(p);

if (bufsize < l)
{
int newsize=l + CHUNK-1;

newsize -= (newsize % CHUNK);
unsigned char *newbuf=new unsigned char[newsize];

if (!newbuf) outofmem();
if (buf) delete[] buf;
buf=newbuf;
bufsize=newsize;
}
memcpy(buf, p, l);
buflength=l;
}

int Buffer::operator-(const Buffer &o) const
{
int i;

for (i=0; i<buflength && i < o.buflength; i++)
{
if (buf[i] < o.buf[i]) return (-1);
if (buf[i] > o.buf[i]) return (1);
}
return (buflength < o.buflength ? -1:
buflength > o.buflength ? 1:0);
}

int Buffer::operator-(const char *o) const
{
int i;

for (i=0; i<buflength && o[i]; i++)
{
if (buf[i] < o[i]) return (-1);
if (buf[i] > o[i]) return (1);
}
return (i < buflength ? 1: o[i] ? -1:0);
}

Buffer &Buffer::operator=(const Buffer &o)
{
if (bufsize < o.buflength)
{
int newsize=(o.buflength + CHUNK-1);

newsize -= (newsize % CHUNK);
unsigned char *newbuf=new unsigned char[newsize];

if (!newbuf) outofmem();
if (buf) delete[] buf;
buf=newbuf;
bufsize=newsize;
}
if (o.buflength) memcpy(buf, o.buf, o.buflength);
buflength=o.buflength;
return (*this);
}

void Buffer::append(const void *p, int l)
{
if (bufsize - buflength < l)
{
int newsize=(buflength+l + CHUNK-1);

newsize -= (newsize % CHUNK);
unsigned char *newbuf=new unsigned char[newsize];

if (!newbuf) outofmem();
if (buf)
{
memcpy(newbuf, buf, buflength);
delete[] buf;
}
buf=newbuf;
bufsize=newsize;
}
if (l) memcpy(buf+buflength, p, l);
buflength += l;
}

void Buffer::append(unsigned long n)
{
char tbuf[40];
char *p=tbuf+sizeof(tbuf)-1;
char tbuf[40];
char *p=tbuf+sizeof(tbuf)-1;

*p=0;
do
{
*--p= (n % 10) + '0';
} while ( (n /= 10) != 0);
append(p);
}

b += p;
}

void Buffer::append(double d)
void add_number(std::string &buf, double d)
{
char tbuf[MAXLONGSIZE < 40 ? 40:MAXLONGSIZE+4];
char tbuf[MAXLONGSIZE < 40 ? 40:MAXLONGSIZE+4];

sprintf(tbuf, "%1.*g", MAXLONGSIZE, d);
operator += (tbuf);
buf += (tbuf);
}

int Buffer::Int(const char *def) const
int extract_int(const std::string &buf, const char *def)
{
const unsigned char *p=buf;
int l=buflength;
int minus=0;
unsigned num=0;
const char *p=buf.c_str();
auto l=buf.size();
int minus=0;
unsigned num=0;

while (l && isspace(*p))
{
Expand All @@ -145,7 +44,7 @@ unsigned num=0;

if ((!l || (*p != '-' && (*p < '0' || *p > '9'))) && def != 0)
{
p= (const unsigned char *)def;
p=def;
l=strlen(def);
}

Expand Down
67 changes: 10 additions & 57 deletions courier-imap-x/libs/maildrop/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,18 @@


#include "config.h"
#include <string.h>
#include <string>

///////////////////////////////////////////////////////////////////////////
//
// Generic text/data buffer. Not null-terminated by default.
//
// This class is used to store arbitrary text strings. It is used by
// the lexical scanner to build up text that's recognized as a token,
// and the rest of the code to store strings.
//
///////////////////////////////////////////////////////////////////////////
void add_number(std::string &buf, double val);
void add_integer(std::string &buf, unsigned long n);
inline void set_integer(std::string &buf, unsigned long n)
{
std::string b;

class Buffer {
add_integer(b, n);
buf=b;
}

unsigned char *buf;
int bufsize;
int buflength;
public:
Buffer() : buf(0), bufsize(0), buflength(0) {}
~Buffer() { if (buf) delete[] buf; }
const unsigned char *Ptr() const { return (buf); }
operator const unsigned char *() const { return (buf); }
operator const char *() const { return ((const char *)buf); }
int Int(const char * =0) const;
int Length() const { return (buflength); }
void Length(int l) { if (l < buflength) buflength=l; }

Buffer(const Buffer &); // UNDEFINED
Buffer &operator=(const Buffer &);

void push(int c) { if (buflength < bufsize)
{
buf[buflength]=c;
++buflength;
}
else append(c); }
int pop() { return (buflength ? buf[--buflength]:0); }
int peek() { return (buflength ? buf[buflength-1]:0); }
void reset() { buflength=0; }

private:
void append(int);
public:
void append(const void *, int);
void set(const char *);
void append(const char *p) { append(p, strlen(p)); }
void set(unsigned long n) { buflength=0; append(n); }
void append(unsigned long n);
void append(double);
Buffer &operator=(const char *p) { set(p); return (*this); }
Buffer &operator += (const Buffer &p) { append(p.buf, p.buflength); return (*this); }
Buffer &operator += (const char *p) { append(p, strlen(p)); return (*this); }
Buffer &operator += (char c) { push(c); return (*this); }
int operator-(const Buffer &) const;
int operator-(const char *) const;
int operator==(const Buffer &b) const
{ return ( operator-(b) == 0); }
int operator==(const char *b) const
{ return ( operator-(b) == 0); }
} ;
int extract_int(const std::string &buf, const char * =0);

#endif
2 changes: 1 addition & 1 deletion courier-imap-x/libs/maildrop/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dnl
dnl Copyright 1998 - 2022 Double Precision, Inc. See COPYING for
dnl distribution information.

AC_INIT([maildrop],[3.1.1],[[email protected]])
AC_INIT([maildrop],[3.1.4],[[email protected]])
AC_CONFIG_MACRO_DIR([m4])

>confdefs.h # Kill PACKAGE_ macros
Expand Down
47 changes: 21 additions & 26 deletions courier-imap-x/libs/maildrop/deliver.C
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
** Copyright 1998 - 2008 Double Precision, Inc.
** Copyright 1998 - 2023 Double Precision, Inc.
** See COPYING for distribution information.
*/

Expand Down Expand Up @@ -53,31 +53,26 @@ FormatMbox format_mbox;

if (format_mbox.HasMsg()) return (0);

Buffer b;
std::string b;

if ( *mailbox == '!' || *mailbox == '|' )
{
Buffer cmdbuf;
std::string cmdbuf;

if (*mailbox == '!')
{
b="SENDMAIL";

const char *sendmail=GetVarStr(b);

cmdbuf=sendmail;
cmdbuf=GetVar("SENDMAIL");

cmdbuf += " -f '' ";
cmdbuf += mailbox+1;
}
else
cmdbuf= mailbox+1;

cmdbuf += '\0';

if (VerboseLevel() > 0)
merr << "maildrop: Delivering to |" <<
(const char *)cmdbuf << "\n";
cmdbuf.c_str() << "\n";

PipeFds pipe;

Expand All @@ -97,7 +92,7 @@ Buffer b;

try
{
subshell(cmdbuf);
subshell(cmdbuf.c_str());
}
catch (const char *p)
{
Expand Down Expand Up @@ -140,13 +135,13 @@ Buffer b;
log(mailbox, rc || wait_stat, format_mbox);

{
Buffer name, val;
std::string name, val;

if (rc) wait_stat= -1;
else wait_stat= WIFEXITED(wait_stat)
? WEXITSTATUS(wait_stat):-1;

val.append( (unsigned long)wait_stat);
add_integer(val, wait_stat);
name="EXITCODE";
SetVar(name, val);
}
Expand Down Expand Up @@ -188,13 +183,12 @@ Buffer b;

struct stat stat_buf;
Mio mio;
Buffer name_buf;
std::string name_buf;

name_buf="UMASK";
const char *um=GetVarStr(name_buf);
std::string um=GetVar("UMASK");
unsigned int umask_val=077;

sscanf(um, "%o", &umask_val);
sscanf(um.c_str(), "%o", &umask_val);

umask_val=umask(umask_val);

Expand Down Expand Up @@ -261,18 +255,19 @@ Buffer b;

void subshell(const char *cmd)
{
Buffer b;
std::string b;

b="SHELL";
std::string shell=GetVar("SHELL");

const char *shell=GetVarStr(b);
const char *p, *q;

const char *p, *q;

for (p=q=shell; *p; p++)
for (p=q=shell.c_str(); *p; p++)
if (*p == SLASH_CHAR) q=p+1;

char **env=ExportEnv();
std::vector<std::vector<char>> strings;
std::vector<char *> env;

ExportEnv(strings, env);

int n;

Expand All @@ -286,9 +281,9 @@ int n;
_exit(100);
}
ExitTrap::onfork();
execle(shell, q, "-c", cmd, (const char *)0, env);
execle(shell.c_str(), q, "-c", cmd, (const char *)NULL, env.data());
if (write (2, "Unable to execute ", 18) < 0 ||
write (2, shell, strlen(shell)) < 0 ||
write (2, shell.c_str(), shell.size()) < 0 ||
write (2, "\n", 1) < 0)
; /* ignored */
_exit(100);
Expand Down
Loading