Exposed additional helper functions
This commit is contained in:
parent
520a783ed6
commit
b60fe0e379
2
Makefile
2
Makefile
|
@ -53,6 +53,7 @@ dist:
|
|||
$(PACKAGE)-$(VERSION)/include/project.conf \
|
||||
$(PACKAGE)-$(VERSION)/include/Mailer/account.h \
|
||||
$(PACKAGE)-$(VERSION)/include/Mailer/folder.h \
|
||||
$(PACKAGE)-$(VERSION)/include/Mailer/helper.c \
|
||||
$(PACKAGE)-$(VERSION)/include/Mailer/mailer.h \
|
||||
$(PACKAGE)-$(VERSION)/include/Mailer/message.h \
|
||||
$(PACKAGE)-$(VERSION)/include/Mailer/plugin.h \
|
||||
|
@ -68,6 +69,7 @@ dist:
|
|||
$(PACKAGE)-$(VERSION)/src/callbacks.c \
|
||||
$(PACKAGE)-$(VERSION)/src/compose.c \
|
||||
$(PACKAGE)-$(VERSION)/src/folder.c \
|
||||
$(PACKAGE)-$(VERSION)/src/helper.c \
|
||||
$(PACKAGE)-$(VERSION)/src/mailer.c \
|
||||
$(PACKAGE)-$(VERSION)/src/message.c \
|
||||
$(PACKAGE)-$(VERSION)/src/compose-main.c \
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2011 Pierre Pronchery <khorben@defora.org> */
|
||||
/* Copyright (c) 2010-2012 Pierre Pronchery <khorben@defora.org> */
|
||||
/* This file is part of DeforaOS Desktop Mailer */
|
||||
/* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -23,5 +23,6 @@
|
|||
# include "Mailer/mailer.h"
|
||||
# include "Mailer/account.h"
|
||||
# include "Mailer/transport.h"
|
||||
# include "Mailer/helper.h"
|
||||
|
||||
#endif /* !DESKTOP_MAILER_H */
|
||||
|
|
|
@ -18,6 +18,8 @@ install:
|
|||
$(INSTALL) -m 0644 -- account.h $(DESTDIR)$(PREFIX)/include/Desktop/Mailer/account.h
|
||||
$(MKDIR) $(DESTDIR)$(PREFIX)/include/Desktop/Mailer
|
||||
$(INSTALL) -m 0644 -- folder.h $(DESTDIR)$(PREFIX)/include/Desktop/Mailer/folder.h
|
||||
$(MKDIR) $(DESTDIR)$(INCLUDEDIR)
|
||||
$(INSTALL) -m 0644 -- helper.c $(DESTDIR)$(INCLUDEDIR)/helper.c
|
||||
$(MKDIR) $(DESTDIR)$(PREFIX)/include/Desktop/Mailer
|
||||
$(INSTALL) -m 0644 -- mailer.h $(DESTDIR)$(PREFIX)/include/Desktop/Mailer/mailer.h
|
||||
$(MKDIR) $(DESTDIR)$(PREFIX)/include/Desktop/Mailer
|
||||
|
@ -30,6 +32,7 @@ install:
|
|||
uninstall:
|
||||
$(RM) -- $(DESTDIR)$(PREFIX)/include/Desktop/Mailer/account.h
|
||||
$(RM) -- $(DESTDIR)$(PREFIX)/include/Desktop/Mailer/folder.h
|
||||
$(RM) -- $(DESTDIR)$(INCLUDEDIR)/helper.c
|
||||
$(RM) -- $(DESTDIR)$(PREFIX)/include/Desktop/Mailer/mailer.h
|
||||
$(RM) -- $(DESTDIR)$(PREFIX)/include/Desktop/Mailer/message.h
|
||||
$(RM) -- $(DESTDIR)$(PREFIX)/include/Desktop/Mailer/plugin.h
|
||||
|
|
29
include/Mailer/helper.h
Normal file
29
include/Mailer/helper.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2011-2012 Pierre Pronchery <khorben@defora.org> */
|
||||
/* This file is part of DeforaOS Desktop Mailer */
|
||||
/* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
|
||||
|
||||
#ifndef DESKTOP_MAILER_HELPER_H
|
||||
# define DESKTOP_MAILER_HELPER_H
|
||||
|
||||
|
||||
/* public */
|
||||
/* functions */
|
||||
char * mailer_helper_get_email(char const * header);
|
||||
char * mailer_helper_get_name(char const * header);
|
||||
|
||||
int mailer_helper_is_email(char const * email);
|
||||
|
||||
#endif /* DESKTOP_MAILER_HELPER_H */
|
|
@ -1,4 +1,4 @@
|
|||
includes=account.h,folder.h,mailer.h,message.h,plugin.h,transport.h
|
||||
includes=account.h,folder.h,helper.c,mailer.h,message.h,plugin.h,transport.h
|
||||
dist=Makefile
|
||||
|
||||
[account.h]
|
||||
|
@ -7,6 +7,9 @@ install=$(PREFIX)/include/Desktop/Mailer
|
|||
[folder.h]
|
||||
install=$(PREFIX)/include/Desktop/Mailer
|
||||
|
||||
[helper.h]
|
||||
install=$(PREFIX)/include/Desktop/Mailer
|
||||
|
||||
[mailer.h]
|
||||
install=$(PREFIX)/include/Desktop/Mailer
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2011-2012 Pierre Pronchery <khorben@defora.org> */
|
||||
/* This file is part of DeforaOS Desktop Mailer */
|
||||
/* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
|
||||
|
||||
#ifndef DESKTOP_MAILER_TRANSPORT_H
|
||||
# define DESKTOP_MAILER_TRANSPORT_H
|
||||
|
||||
|
||||
/* FIXME implement */
|
||||
|
||||
#endif /* DESKTOP_MAILER_TRANSPORT_H */
|
|
@ -8,7 +8,7 @@ CPPFLAGSF= -I ../include
|
|||
CPPFLAGS?=
|
||||
CFLAGSF = -W `pkg-config --cflags libDesktop`
|
||||
CFLAGS = -Wall -g -O2 -pedantic
|
||||
LDFLAGS =
|
||||
LDFLAGS =
|
||||
AR ?= ar
|
||||
RANLIB ?= ranlib
|
||||
CCSHARED?= $(CC) -shared
|
||||
|
@ -24,7 +24,7 @@ all: subdirs $(TARGETS)
|
|||
subdirs:
|
||||
@for i in $(SUBDIRS); do (cd $$i && $(MAKE)) || exit; done
|
||||
|
||||
libMailer_OBJS = account.o callbacks.o compose.o folder.o mailer.o message.o
|
||||
libMailer_OBJS = account.o callbacks.o compose.o folder.o helper.o mailer.o message.o
|
||||
libMailer_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) -fPIC
|
||||
libMailer_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) `pkg-config --libs libDesktop` -lssl
|
||||
|
||||
|
@ -63,6 +63,9 @@ compose.o: compose.c callbacks.h mailer.h compose.h ../config.h
|
|||
folder.o: folder.c mailer.h folder.h
|
||||
$(CC) $(libMailer_CFLAGS) -c folder.c
|
||||
|
||||
helper.o: helper.c ../include/Mailer/helper.h
|
||||
$(CC) $(libMailer_CFLAGS) -c helper.c
|
||||
|
||||
mailer.o: mailer.c account.h callbacks.h compose.h mailer.h ../config.h
|
||||
$(CC) -D PREFIX=\"$(PREFIX)\" $(libMailer_CFLAGS) -c mailer.c
|
||||
|
||||
|
|
110
src/helper.c
Normal file
110
src/helper.c
Normal file
|
@ -0,0 +1,110 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2012 Pierre Pronchery <khorben@defora.org> */
|
||||
/* This file is part of DeforaOS Desktop Mailer */
|
||||
/* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "Mailer/helper.h"
|
||||
|
||||
|
||||
/* public */
|
||||
/* functions */
|
||||
/* mailer_helper_get_email */
|
||||
char * mailer_helper_get_email(char const * header)
|
||||
{
|
||||
char * ret;
|
||||
size_t len;
|
||||
char * buf = NULL;
|
||||
|
||||
if(header == NULL)
|
||||
return NULL;
|
||||
len = strlen(header);
|
||||
if((ret = malloc(len + 1)) == NULL || (buf = malloc(len + 1)) == NULL)
|
||||
{
|
||||
free(buf);
|
||||
free(ret);
|
||||
return NULL;
|
||||
}
|
||||
if(mailer_helper_is_email(header))
|
||||
{
|
||||
strcpy(ret, header);
|
||||
free(buf);
|
||||
return ret;
|
||||
}
|
||||
if(sscanf(header, "%[^(](%[^)])", ret, buf) == 2
|
||||
|| sscanf(header, "%[^<]<%[^>]>", buf, ret) == 2)
|
||||
{
|
||||
for(len = strlen(ret); len > 0 && isblank(ret[len - 1]); len--)
|
||||
ret[len - 1] = '\0';
|
||||
if(mailer_helper_is_email(ret))
|
||||
{
|
||||
free(buf);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
free(buf);
|
||||
free(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* mailer_helper_get_name */
|
||||
char * mailer_helper_get_name(char const * header)
|
||||
{
|
||||
char * ret;
|
||||
size_t len;
|
||||
char * buf = NULL;
|
||||
|
||||
if(header == NULL)
|
||||
return NULL;
|
||||
len = strlen(header);
|
||||
if((ret = malloc(len + 1)) == NULL || (buf = malloc(len + 1)) == NULL)
|
||||
{
|
||||
free(buf);
|
||||
free(ret);
|
||||
return NULL;
|
||||
}
|
||||
if(sscanf(header, "%[^(](%[^)])", buf, ret) == 2
|
||||
|| sscanf(header, "%[^<]<%[^>]>", ret, buf) == 2)
|
||||
{
|
||||
free(buf);
|
||||
return ret;
|
||||
}
|
||||
free(buf);
|
||||
free(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* mailer_helper_is_email */
|
||||
int mailer_helper_is_email(char const * header)
|
||||
{
|
||||
size_t i = 0;
|
||||
int c;
|
||||
|
||||
/* FIXME this is neither strict nor standard at the moment */
|
||||
for(i = 0; (c = header[i]) != '@'; i++)
|
||||
if(c == '\0')
|
||||
return 0;
|
||||
else if(!isalnum(c) && c != '.' && c != '_')
|
||||
return 0;
|
||||
for(i++; (c = header[i]) != '\0'; i++)
|
||||
if(!isalnum(c) && c != '.' && c != '_')
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
100
src/message.c
100
src/message.c
|
@ -62,11 +62,6 @@ static int _message_set_to(Message * message, char const * to);
|
|||
|
||||
/* useful */
|
||||
/* message headers */
|
||||
static char * _message_header_get_email(char const * header);
|
||||
static char * _message_header_get_name(char const * header);
|
||||
|
||||
static int _message_header_is_email(char const * header);
|
||||
|
||||
static int _message_header_set(MessageHeader * mh, char const * header,
|
||||
char const * value);
|
||||
|
||||
|
@ -345,9 +340,9 @@ static int _message_set_from(Message * message, char const * from)
|
|||
char * name;
|
||||
char * email;
|
||||
|
||||
if((email = _message_header_get_email(from)) == NULL)
|
||||
if((email = mailer_helper_get_email(from)) == NULL)
|
||||
return -1;
|
||||
name = _message_header_get_name(from);
|
||||
name = mailer_helper_get_name(from);
|
||||
_message_set(message, MHC_FROM, (name != NULL) ? name : email,
|
||||
MHC_FROM_EMAIL, email, -1);
|
||||
free(email);
|
||||
|
@ -380,9 +375,9 @@ static int _message_set_to(Message * message, char const * to)
|
|||
char * name;
|
||||
char * email;
|
||||
|
||||
if((email = _message_header_get_email(to)) == NULL)
|
||||
if((email = mailer_helper_get_email(to)) == NULL)
|
||||
return -1;
|
||||
name = _message_header_get_name(to);
|
||||
name = mailer_helper_get_name(to);
|
||||
_message_set(message, MHC_TO, (name != NULL) ? name : email,
|
||||
MHC_TO_EMAIL, email, -1);
|
||||
free(email);
|
||||
|
@ -392,92 +387,7 @@ static int _message_set_to(Message * message, char const * to)
|
|||
|
||||
|
||||
/* useful */
|
||||
/* message_header_get_email */
|
||||
static char * _message_header_get_email(char const * header)
|
||||
{
|
||||
char * ret;
|
||||
size_t len;
|
||||
char * buf = NULL;
|
||||
|
||||
if(header == NULL)
|
||||
return NULL;
|
||||
len = strlen(header);
|
||||
if((ret = malloc(len + 1)) == NULL || (buf = malloc(len + 1)) == NULL)
|
||||
{
|
||||
free(buf);
|
||||
free(ret);
|
||||
return NULL;
|
||||
}
|
||||
if(_message_header_is_email(header))
|
||||
{
|
||||
strcpy(ret, header);
|
||||
free(buf);
|
||||
return ret;
|
||||
}
|
||||
if(sscanf(header, "%[^(](%[^)])", ret, buf) == 2
|
||||
|| sscanf(header, "%[^<]<%[^>]>", buf, ret) == 2)
|
||||
{
|
||||
for(len = strlen(ret); len > 0 && isblank(ret[len - 1]); len--)
|
||||
ret[len - 1] = '\0';
|
||||
if(_message_header_is_email(ret))
|
||||
{
|
||||
free(buf);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
free(buf);
|
||||
free(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* message_header_get_name */
|
||||
static char * _message_header_get_name(char const * header)
|
||||
{
|
||||
char * ret;
|
||||
size_t len;
|
||||
char * buf = NULL;
|
||||
|
||||
if(header == NULL)
|
||||
return NULL;
|
||||
len = strlen(header);
|
||||
if((ret = malloc(len + 1)) == NULL || (buf = malloc(len + 1)) == NULL)
|
||||
{
|
||||
free(buf);
|
||||
free(ret);
|
||||
return NULL;
|
||||
}
|
||||
if(sscanf(header, "%[^(](%[^)])", buf, ret) == 2
|
||||
|| sscanf(header, "%[^<]<%[^>]>", ret, buf) == 2)
|
||||
{
|
||||
free(buf);
|
||||
return ret;
|
||||
}
|
||||
free(buf);
|
||||
free(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* message_header_is_email */
|
||||
static int _message_header_is_email(char const * header)
|
||||
{
|
||||
size_t i = 0;
|
||||
int c;
|
||||
|
||||
/* FIXME this is neither strict nor standard at the moment */
|
||||
for(i = 0; (c = header[i]) != '@'; i++)
|
||||
if(c == '\0')
|
||||
return 0;
|
||||
else if(!isalnum(c) && c != '.' && c != '_')
|
||||
return 0;
|
||||
for(i++; (c = header[i]) != '\0'; i++)
|
||||
if(!isalnum(c) && c != '.' && c != '_')
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* message headers */
|
||||
/* message_header_set */
|
||||
static int _message_header_set(MessageHeader * mh, char const * header,
|
||||
char const * value)
|
||||
|
|
|
@ -11,7 +11,7 @@ dist=Makefile,account.h,callbacks.h,common.c,compose.h,folder.h,mailer.h,message
|
|||
type=library
|
||||
cflags=-fPIC
|
||||
ldflags=`pkg-config --libs libDesktop` -lssl
|
||||
sources=account.c,callbacks.c,compose.c,folder.c,mailer.c,message.c
|
||||
sources=account.c,callbacks.c,compose.c,folder.c,helper.c,mailer.c,message.c
|
||||
install=$(LIBDIR)
|
||||
|
||||
[compose]
|
||||
|
@ -44,6 +44,9 @@ depends=compose.h
|
|||
[folder.c]
|
||||
depends=mailer.h,folder.h
|
||||
|
||||
[helper.c]
|
||||
depends=../include/Mailer/helper.h
|
||||
|
||||
[mailer.c]
|
||||
cppflags=-D PREFIX=\"$(PREFIX)\"
|
||||
depends=account.h,callbacks.h,compose.h,mailer.h,../config.h
|
||||
|
|
Loading…
Reference in New Issue
Block a user