Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
slsrepo committed Jun 10, 2021
0 parents commit 4e752f4
Show file tree
Hide file tree
Showing 644 changed files with 182,837 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// swift-tools-version:5.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "libetpan-swift",
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "libetpan",
targets: ["libetpan"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "libetpan",
cSettings: [
.define("HAVE_CONFIG_H", to: "1"),
.define("HAVE_CFNETWORK", to: "1"),
.define("LIBETPAN_IOS_DISABLE_SSL", to: "1"),
.define("NO_MACROS", to: "1"),
]
)
]
)
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
## LibEtPan

The purpose of this mail library is to provide a portable, efficient framework for different kinds of mail access: IMAP, SMTP, POP and NNTP.

It provides an API for C language.

[![Build Status](https://travis-ci.org/dinhviethoa/libetpan.png?branch=master)](https://travis-ci.org/dinhviethoa/libetpan)
[![Code Quality: Cpp](https://img.shields.io/lgtm/grade/cpp/g/dinhviethoa/libetpan.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/dinhviethoa/libetpan/context:cpp)
[![Total Alerts](https://img.shields.io/lgtm/alerts/g/dinhviethoa/libetpan.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/dinhviethoa/libetpan/alerts)

## Features

- IMAP
- SMTP
- POP
- NNTP
- RFC822/MIME message builder
- RFC822/MIME message parser
- Maildir
- mbox
- MH

## Build instructions

### Unix

You need to install autoconf, automake and libtool.
They can be installed using [brew](http://brew.sh/).

$ ./autogen.sh
$ make

You can use flag --with-poll for using poll() instead of select() for checking connection status

### How to link with it

$ gcc -c -o sample.o sample.c `pkg-config libetpan --cflags`
$ gcc -o sample sample.o `pkg-config libetpan --libs`

### Mac / iOS

- Download Xcode
- Open `build-mac/libetpan.xcodeproj`
- Choose the correct target "static libetpan" for Mac or "libetpan ios" for iOS.
- Build

### Setup a Mac project

- Add `libetpan.xcodeproj` as sub-project
- Link with libetpan.a

### Setup an iOS project

- Add `libetpan.xcodeproj` as sub-project
- Link with libetpan-ios.a
- Set "Other Linker Flags": `-lsasl2`

### Build on Windows

- See README and Visual Studio Solution in build-windows folder

## More information

See http://etpan.org/libetpan.html for more information and examples.
55 changes: 55 additions & 0 deletions Sources/libetpan/data-types/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# libEtPan! -- a mail stuff library
#
# Copyright (C) 2007 g10 Code GmbH
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the libEtPan! project nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.

include $(top_srcdir)/rules.mk

etpaninclude_HEADERS = \
mmapstring.h mailstream.h mailstream_helper.h mail.h \
mailstream_low.h \
mailstream_socket.h mailstream_ssl.h mailstream_cfstream.h \
mailstream_compress.h \
mailstream_types.h \
carray.h clist.h chash.h \
charconv.h mailsem.h maillock.h

AM_CPPFLAGS = -I$(top_builddir)/include

noinst_LTLIBRARIES = libdata-types.la

libdata_types_la_SOURCES = connect.h connect.c base64.h hmac-md5.h \
md5global.h md5namespace.h md5.h md5.c mmapstring.c mailstream_helper.c \
mailstream_low.c mailstream.c mailstream_socket.c \
mailstream_ssl.c carray.c clist.c chash.c \
charconv.c maillock.c base64.c mail_cache_db_types.h \
mail_cache_db.h mail_cache_db.c mail_cache_lmdb.c mailsem.c mailsasl.h \
mailsasl.c mailstream_cancel_types.h mailstream_cancel.h \
mailstream_cancel.c timeutils.h timeutils.c \
mmapstring_private.h mailstream_ssl_private.h \
mailstream_cfstream.c mailstream_cfstream.h \
mailstream_compress.c mailstream_compress.h
148 changes: 148 additions & 0 deletions Sources/libetpan/data-types/base64.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
* libEtPan! -- a mail stuff library
*
* Copyright (C) 2001, 2005 - Juergen Graf
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the libEtPan! project nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

/*
* $Id: base64.c,v 1.3 2005/06/01 12:21:57 smarinier Exp $
*/

#include "base64.h"

#include <stdlib.h>

#define OUTPUT_SIZE 513
#define CHAR64(c) (((c) < 0 || (c) > 127) ? -1 : index_64[(c)])

static char index_64[128] = {
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,62, -1,-1,-1,63,
52,53,54,55, 56,57,58,59, 60,61,-1,-1, -1,-1,-1,-1,
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11,12,13,14,
15,16,17,18, 19,20,21,22, 23,24,25,-1, -1,-1,-1,-1,
-1,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
41,42,43,44, 45,46,47,48, 49,50,51,-1, -1,-1,-1,-1
};

static char basis_64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

LIBETPAN_EXPORT
char * encode_base64(const char * in, int len)
{
char * output, * tmp;
unsigned char oval;
int out_len;
const unsigned char * uin = (const unsigned char *) in;

out_len = ((len + 2) / 3 * 4) + 1;

if ((len > 0) && (in == NULL))
return NULL;

output = malloc(out_len);
if (!output)
return NULL;

tmp = output;
while (len >= 3) {
*tmp++ = basis_64[uin[0] >> 2];
*tmp++ = basis_64[((uin[0] << 4) & 0x30) | (uin[1] >> 4)];
*tmp++ = basis_64[((uin[1] << 2) & 0x3c) | (uin[2] >> 6)];
*tmp++ = basis_64[uin[2] & 0x3f];
uin += 3;
len -= 3;
}
if (len > 0) {
*tmp++ = basis_64[uin[0] >> 2];
oval = (uin[0] << 4) & 0x30;
if (len > 1) oval |= uin[1] >> 4;
*tmp++ = basis_64[oval];
*tmp++ = (len < 2) ? '=' : basis_64[(uin[1] << 2) & 0x3c];
*tmp++ = '=';
}

*tmp = '\0';

return output;
}

LIBETPAN_EXPORT
char * decode_base64(const char * in, int len)
{
char * output, * out;
int i, c1, c2, c3, c4, out_len;

out_len = 0;

output = malloc(OUTPUT_SIZE);
if (output == NULL)
return NULL;
out = output;

if (in[0] == '+' && in[1] == ' ')
in += 2;

for (i = 0; i < (len / 4); i++) {
c1 = in[0];
c2 = in[1];
c3 = in[2];
c4 = in[3];
if (CHAR64(c1) == -1 || CHAR64(c2) == -1 ||
(c3 != '=' && CHAR64(c3) == -1) ||
(c4 != '=' && CHAR64(c4) == -1)) {
free(out);
return NULL;
}

in += 4;
*output++ = (CHAR64(c1) << 2) | (CHAR64(c2) >> 4);
if (++out_len >= OUTPUT_SIZE)
return NULL;

if (c3 != '=') {
*output++ = ((CHAR64(c2) << 4) & 0xf0) | (CHAR64(c3) >> 2);
if (++out_len >= OUTPUT_SIZE)
return NULL;

if (c4 != '=') {
*output++ = ((CHAR64(c3) << 6) & 0xc0) | CHAR64(c4);
if (++out_len >= OUTPUT_SIZE)
return NULL;
}
}
}

*output = 0;

return out;
}


65 changes: 65 additions & 0 deletions Sources/libetpan/data-types/base64.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* libEtPan! -- a mail stuff library
*
* Copyright (C) 2001, 2005 - Juergen Graf
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the libEtPan! project nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

/*
* $Id: base64.h,v 1.3 2005/06/01 12:21:57 smarinier Exp $
*/

#ifndef BASE64_H
#define BASE64_H

#ifdef __cplusplus
extern "C" {
#endif

#ifndef LIBETPAN_CONFIG_H
# include "libetpan-config.h"
#endif

/**
* creates (malloc) a new base64 encoded string from a standard 8bit string
* don't forget to free it when time comes ;)
*/
LIBETPAN_EXPORT
char * encode_base64(const char * in, int len);

/**
* creates (malloc) a new standard 8bit string from an base64 encoded string
* don't forget to free it when time comes ;)
*/
LIBETPAN_EXPORT
char * decode_base64(const char * in, int len);

#ifdef __cplusplus
}
#endif

#endif
Loading

0 comments on commit 4e752f4

Please sign in to comment.