commit 1686710b857394c3e40443c3e1bd4719e949a74c
parent bbd442e865ec996b4af0a345a49d04b9cbc87e43
Author: pancake <nopcode.org>
Date: Tue, 4 May 2010 10:17:55 +0200
Fix send mails with relative ans absolute paths
Diffstat:
dmc.c | | | 21 | ++++++++++++++------- |
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/dmc.c b/dmc.c
@@ -64,6 +64,7 @@ static char *cfgget(const char *key) {
static char *gethdr(const char *path, const char *file, const char *hdr) {
char line[1024], *ret = NULL;
FILE *fd;
+ int i;
snprintf (line, sizeof (line), "%s/%s", path, file);
fd = fopen (line, "r");
if (fd) {
@@ -71,8 +72,13 @@ static char *gethdr(const char *path, const char *file, const char *hdr) {
while (!feof (fd)) {
fgets (line, sizeof (line), fd);
if (!memcmp (line, hdr, len)) {
- line[strlen (line)-2] = '\0';
- ret = strdup (line+len);
+ i = strlen (line)-1;
+ if (i>len) {
+ line[i--] = '\0';
+ if (line[i]=='\r'||line[i]=='\n')
+ line[i] = '\0';
+ ret = strdup (line+len);
+ } else ret = strdup ("");
break;
}
}
@@ -213,7 +219,8 @@ static void dmcpush(const char *name) {
char *n = de->d_name;
if (*n != '.' && !strstr (n, ".d")) {
snprintf (file, sizeof (file), "%s/%s", path, n);
- printf ("--> %s\n", file);
+ printf ("%s: ", file);
+ fflush (stdout);
if (dmcsend (file)) {
// TODO: remove .d
unlink (file);
@@ -276,13 +283,13 @@ static int dmcsend(const char *file) {
char line[512];
char *user = cfgget ("USER=");
char *mail = cfgget ("MAIL=");
- char *to = gethdr ("/", file, "To: ");
+ char *to = gethdr ((*file=='/')?"/":"./", file, "To: ");
/* TODO: Implement non-msmtp method */
snprintf (line, sizeof (line),
"dmc-pack `ls %s.d/* 2>/dev/null` < %s "
- "| msmtp --user=\"%s\" --from=\"%s\" \"%s\" < %s",
- file, file,
- user, mail, to, file);
+ "| msmtp --user=\"%s\" --from=\"%s\" \"%s\"",
+ file, file, user, mail, to);
+ // printf ("%s\n", line);
if (system (line) != 0) {
fprintf (stderr, "Error ocurred while sending %s\n", file);
return 0;