mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-11-07 22:41:59 +01:00
added a utility to contrib/imap that adds seen flags to all messages in INBOX
This commit is contained in:
parent
9739809347
commit
ea8051299d
3
configure
vendored
3
configure
vendored
@ -4334,7 +4334,7 @@ CFLAGS="$static -O2 -Wall -g"
|
||||
LIBS="$antispam_libs $sunos_libs "
|
||||
OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o list.o parser.o parser_utils.o rules.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o imap.o extract.o $objs"
|
||||
|
||||
ac_config_files="$ac_config_files Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile test/Makefile"
|
||||
ac_config_files="$ac_config_files Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile test/Makefile contrib/imap/Makefile"
|
||||
|
||||
cat >confcache <<\_ACEOF
|
||||
# This file is a shell script that caches the results of configure
|
||||
@ -5045,6 +5045,7 @@ do
|
||||
"util/Makefile") CONFIG_FILES="$CONFIG_FILES util/Makefile" ;;
|
||||
"init.d/Makefile") CONFIG_FILES="$CONFIG_FILES init.d/Makefile" ;;
|
||||
"test/Makefile") CONFIG_FILES="$CONFIG_FILES test/Makefile" ;;
|
||||
"contrib/imap/Makefile") CONFIG_FILES="$CONFIG_FILES contrib/imap/Makefile" ;;
|
||||
|
||||
*) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
|
||||
esac
|
||||
|
@ -346,6 +346,6 @@ CFLAGS="$static -O2 -Wall -g"
|
||||
LIBS="$antispam_libs $sunos_libs "
|
||||
OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o list.o parser.o parser_utils.o rules.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o imap.o extract.o $objs"
|
||||
|
||||
AC_CONFIG_FILES([Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile test/Makefile])
|
||||
AC_CONFIG_FILES([Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile test/Makefile contrib/imap/Makefile])
|
||||
AC_OUTPUT
|
||||
|
||||
|
40
contrib/imap/Makefile.in
Normal file
40
contrib/imap/Makefile.in
Normal file
@ -0,0 +1,40 @@
|
||||
SHELL = @SHELL@
|
||||
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
bindir = @bindir@
|
||||
sbindir = @sbindir@
|
||||
includedir = @includedir@
|
||||
libdir = @libdir@
|
||||
libexecdir = @libexecdir@
|
||||
srcdir = @srcdir@
|
||||
sysconfdir = @sysconfdir@
|
||||
mandir = @mandir@
|
||||
datarootdir = @datarootdir@
|
||||
localstatedir = @localstatedir@
|
||||
|
||||
CC = @CC@
|
||||
CFLAGS = @CFLAGS@ @CPPFLAGS@
|
||||
DEFS = @defs@
|
||||
INCDIR = -I. -I.. -I../.. -I../../src -I../src @INCDIR@ @mysql_includes@
|
||||
LIBDIR = -L. @LIBDIR@ @LDFLAGS@ -L../src -L../../src
|
||||
LIBS = @LIBS@ @mysql_libs@
|
||||
RUNNING_USER = @RUNNING_USER@
|
||||
RUNNING_GROUP = `@id_bin@ -gn $(RUNNING_USER)`
|
||||
OBJS =
|
||||
|
||||
INSTALL = @INSTALL@
|
||||
|
||||
all: $(OBJS) imap-seen
|
||||
|
||||
imap-seen: imap-seen.c ../../src/libpiler.a
|
||||
$(CC) $(CFLAGS) $(INCDIR) $(DEFS) -o $@ $< -lpiler $(LIBS) $(LIBDIR)
|
||||
|
||||
|
||||
install:
|
||||
|
||||
clean:
|
||||
rm -f imap-seen
|
||||
|
||||
distclean: clean
|
||||
rm -f Makefile
|
162
contrib/imap/imap-seen.c
Normal file
162
contrib/imap/imap-seen.c
Normal file
@ -0,0 +1,162 @@
|
||||
/*
|
||||
* imap-seen.c, SJ
|
||||
*/
|
||||
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/socket.h>
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <ctype.h>
|
||||
#include <locale.h>
|
||||
#include <getopt.h>
|
||||
#include <syslog.h>
|
||||
#include <piler.h>
|
||||
|
||||
|
||||
#define SKIPLIST "junk,trash,spam,draft"
|
||||
#define MBOX_ARGS 1024
|
||||
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
|
||||
int quiet=0;
|
||||
|
||||
int connect_to_imap_server(int sd, int *seq, char *imapserver, char *username, char *password);
|
||||
|
||||
|
||||
void usage(){
|
||||
printf("usage: imap-seen [-c <config file>] -i <imap server> -u <imap username> -p <imap password>\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv){
|
||||
int c, rc=0, messages=0;
|
||||
char *configfile=CONFIG_FILE;
|
||||
char *imapserver=NULL, *username=NULL, *password=NULL, *skiplist=SKIPLIST;
|
||||
struct __config cfg;
|
||||
int sd, n;
|
||||
int seq=1;
|
||||
char *p, tag[SMALLBUFSIZE], tagok[SMALLBUFSIZE], buf[MAXBUFSIZE];
|
||||
|
||||
|
||||
while(1){
|
||||
|
||||
#ifdef _GNU_SOURCE
|
||||
static struct option long_options[] =
|
||||
{
|
||||
{"config", required_argument, 0, 'c' },
|
||||
{"imapserver", required_argument, 0, 'i' },
|
||||
{"username", required_argument, 0, 'u' },
|
||||
{"password", required_argument, 0, 'p' },
|
||||
{"skiplist", required_argument, 0, 'x' },
|
||||
{"help", no_argument, 0, 'h' },
|
||||
{0,0,0,0}
|
||||
};
|
||||
|
||||
int option_index = 0;
|
||||
|
||||
c = getopt_long(argc, argv, "c:i:u:p:x:h?", long_options, &option_index);
|
||||
#else
|
||||
c = getopt(argc, argv, "c:i:u:p:x:h?");
|
||||
#endif
|
||||
|
||||
if(c == -1) break;
|
||||
|
||||
switch(c){
|
||||
|
||||
case 'c' :
|
||||
configfile = optarg;
|
||||
break;
|
||||
|
||||
case 'i' :
|
||||
imapserver = optarg;
|
||||
break;
|
||||
|
||||
case 'u' :
|
||||
username = optarg;
|
||||
break;
|
||||
|
||||
case 'p' :
|
||||
password = optarg;
|
||||
break;
|
||||
|
||||
case 'x' :
|
||||
skiplist = optarg;
|
||||
break;
|
||||
|
||||
case 'h' :
|
||||
case '?' :
|
||||
usage();
|
||||
break;
|
||||
|
||||
|
||||
default :
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(!imapserver) usage();
|
||||
|
||||
cfg = read_config(configfile);
|
||||
|
||||
(void) openlog("imap-seen", LOG_PID, LOG_MAIL);
|
||||
|
||||
if(imapserver && username && password){
|
||||
|
||||
if((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1){
|
||||
printf("cannot create socket\n");
|
||||
return ERR;
|
||||
}
|
||||
|
||||
if(connect_to_imap_server(sd, &seq, imapserver, username, password) == ERR){
|
||||
close(sd);
|
||||
return ERR;
|
||||
}
|
||||
|
||||
|
||||
snprintf(tag, sizeof(tag)-1, "A%d", seq); snprintf(tagok, sizeof(tagok)-1, "\r\nA%d OK", (seq)++);
|
||||
snprintf(buf, sizeof(buf)-1, "%s SELECT \"INBOX\"\r\n", tag);
|
||||
send(sd, buf, strlen(buf), 0);
|
||||
|
||||
|
||||
n = recvtimeout(sd, buf, MAXBUFSIZE, 10);
|
||||
|
||||
p = strstr(buf, " EXISTS");
|
||||
if(p){
|
||||
*p = '\0';
|
||||
p = strrchr(buf, '\n');
|
||||
if(p){
|
||||
while(!isdigit(*p)){ p++; }
|
||||
messages = atoi(p);
|
||||
}
|
||||
}
|
||||
|
||||
printf("found %d messages\n", messages);
|
||||
|
||||
snprintf(tag, sizeof(tag)-1, "A%d", seq); snprintf(tagok, sizeof(tagok)-1, "\r\nA%d OK", (seq)++);
|
||||
snprintf(buf, sizeof(buf)-1, "%s STORE 1:%d +FLAGS (\\Seen)\r\n", tag, messages);
|
||||
send(sd, buf, strlen(buf), 0);
|
||||
|
||||
n = recvtimeout(sd, buf, MAXBUFSIZE, 10);
|
||||
|
||||
close(sd);
|
||||
}
|
||||
|
||||
if(quiet == 0) printf("\n");
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -293,7 +293,7 @@ int import_from_imap_server(char *imapserver, char *username, char *password, st
|
||||
|
||||
|
||||
void usage(){
|
||||
printf("usage: pilerimport [-c <config file>] -e <eml file> | -m <mailbox file> | -d <directory> | -i <imap server> -u <imap username> -p <imap password>\n");
|
||||
printf("usage: pilerimport [-c <config file>] -e <eml file> | -m <mailbox file> | -d <directory> | -i <imap server> -u <imap username> -p <imap password> [-F <foldername>] [-R]\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user