Compare commits

..

2 Commits

Author SHA1 Message Date
79e19d3d15
add a very limited INCLUDE_ONLY option 2023-12-04 15:23:04 -08:00
e0690b07eb
add docker-based build 2023-12-04 15:22:21 -08:00
3 changed files with 79 additions and 0 deletions

41
Dockerfile Normal file
View File

@ -0,0 +1,41 @@
#FROM debian:bookworm-20231030-slim
FROM debian:bullseye-20220801
# need to add
# removed
# libsasl2-modules \
# ca-certificates \
# version pinning is being handled in our from line
# hadolint ignore=DL3008
RUN true && \
apt-get update && \
groupadd --gid 1000 user && \
useradd -m --home-dir /home/user --shell /bin/sh --uid 1000 --gid 1000 user && \
apt-get install -y --no-install-recommends \
libsasl2-2 \
libsasl2-dev \
perl \
libdatetime-format-dateparse-perl \
autoconf \
automake \
zlib1g-dev \
libdb-dev \
libsasl2-dev \
libssl-dev \
gcc \
make \
git \
&& \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
true
# Built with
# apt install build-essential dh-autoreconf git
# apt install libssl-dev
# apt install zlib1g-dev
# apt install libsasl2-dev
WORKDIR /home/user
USER user

3
build Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
# Note we assume this is run with podman. Take -u 0:0 out if using docker
docker run -u 0:0 -it --rm -v $(pwd):/make -w /make isync-build make

View File

@ -920,6 +920,28 @@ maildir_compare( const void *l, const void *r )
return strcmp( lm->base, rm->base ); return strcmp( lm->base, rm->base );
} }
int is_gmail(const char* name) {
// NOTE: This is not an exact science. For instance, there is a good
// shot that mail sent from containers will end up matching this pattern
char token[16]; // If host name is longer than 12, then we already have our answer
// we expect files in the form of: "1700172103.R12128272304961211247.hostname,U=27:2,S"
// we are looking for "hostname"
// All gmail mails have a hostname in the form of "ff6d55f971cc".
// All are 12 characters long
// All are hexadecimal
if (sscanf(name, "%*[^.].%*[^.].%15[^,]", token) == 1) {
token[14] = '\0';
size_t len = strlen(token);
if (len != 12) return 0;
if (strspn(token, "0123456789abcdef") == len) return 1;
}
// We are here because a) the input format is not as expected,
// or b) the hostname is not gmail
return 0;
}
static int static int
maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t *msglist ) maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t *msglist )
{ {
@ -992,11 +1014,24 @@ maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t *msglist )
return DRV_BOX_BAD; return DRV_BOX_BAD;
} }
const char *filter = getenv("MBSYNC_MAILDIR_IGNORE"); const char *filter = getenv("MBSYNC_MAILDIR_IGNORE");
const char *MAGIC_INCLUDE = "^[^\\.]+\\.[^\\.]+\\.[0-9a-f]{12}\\,.*";
char *include = getenv("MBSYNC_MAILDIR_INCLUDE_ONLY");
if (include && strncmp(MAGIC_INCLUDE, include, strlen(MAGIC_INCLUDE)) != 0) {
include = NULL;
error("MBSYNC_MAILDIR_INCLUDE_ONLY can only be '%s'\n", MAGIC_INCLUDE);
}
if (include && filter) {
include = NULL;
error("MBSYNC_MAILDIR_IGNORE cannot be used with MBSYNC_MAILDIR_INCLUDE_ONLY. INCLUDE_ONLY will be ignored\n");
}
while ((e = readdir( d ))) { while ((e = readdir( d ))) {
if (*e->d_name == '.') if (*e->d_name == '.')
continue; continue;
if (filter && strstr(e->d_name, filter)) if (filter && strstr(e->d_name, filter))
continue; continue;
if (include && !is_gmail(e->d_name))
continue;
ctx->total_msgs++; ctx->total_msgs++;
ctx->recent_msgs += i; ctx->recent_msgs += i;
#ifdef USE_DB #ifdef USE_DB