New mailsend
This commit is contained in:
Regular → Executable
+366
-51
@@ -13,7 +13,12 @@
|
||||
#include "mailsend.h"
|
||||
|
||||
static Sll
|
||||
*one_line_head = NULL,
|
||||
*custom_headers_head = NULL,
|
||||
*attachment_head=NULL,
|
||||
*oneline_attachment_head = NULL,
|
||||
*msg_body_attachment_head = NULL,
|
||||
*embed_image_attachment_head = NULL,
|
||||
*server_caps=NULL,
|
||||
*addr_head=NULL;
|
||||
|
||||
@@ -31,9 +36,21 @@ void print_server_caps(void)
|
||||
}
|
||||
}
|
||||
|
||||
void print_one_lines(void)
|
||||
{
|
||||
Sll
|
||||
*l;
|
||||
for (l = one_line_head; l; l = l->next)
|
||||
{
|
||||
(void) fprintf(stdout,"LINE: '%s'\n",(char *) l->data);
|
||||
(void) fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void printAddressList2(Sll *list)
|
||||
{
|
||||
/*
|
||||
Sll
|
||||
*l;
|
||||
|
||||
@@ -44,9 +61,37 @@ void printAddressList2(Sll *list)
|
||||
{
|
||||
addr=(Address *) l->data;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void print_attachemtn_list()
|
||||
void print_oneline_attachment_list(void)
|
||||
{
|
||||
Sll
|
||||
*l;
|
||||
|
||||
Attachment
|
||||
*a;
|
||||
|
||||
if (!g_verbose)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (l=oneline_attachment_head; l; l=l->next)
|
||||
{
|
||||
a=(Attachment *) l->data;
|
||||
(void) fprintf(stderr,"Message: %s\n",a->oneline_msg);
|
||||
(void) fprintf(stderr,"Mime type: %s\n",a->mime_type);
|
||||
(void) fprintf(stderr,"Disposition: %s\n",a->content_disposition);
|
||||
if (a->content_transfer_encoding)
|
||||
(void) fprintf(stderr,"Encoding type: %s\n",a->content_transfer_encoding);
|
||||
else
|
||||
(void) fprintf(stderr,"Encoding type: none\n");
|
||||
(void) fprintf(stderr,"\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void print_attachment_list(void)
|
||||
{
|
||||
Sll
|
||||
*l;
|
||||
@@ -57,13 +102,19 @@ void print_attachemtn_list()
|
||||
for (l=attachment_head; l; l=l->next)
|
||||
{
|
||||
a=(Attachment *) l->data;
|
||||
/*
|
||||
(void) fprintf(stderr,"File path: %s\n",a->file_path);
|
||||
(void) fprintf(stderr,"File name: %s\n",a->file_name);
|
||||
if (a->attachment_name)
|
||||
(void) fprintf(stderr,"Attachment name: %s\n",a->attachment_name);
|
||||
(void) fprintf(stderr,"Mime type: %s\n",a->mime_type);
|
||||
(void) fprintf(stderr,"Disposition: %s\n",a->content_disposition);
|
||||
if (a->content_id)
|
||||
(void) fprintf(stderr,"Content-ID: %s\n",a->content_id);
|
||||
if (a->content_transfer_encoding)
|
||||
(void) fprintf(stderr,"Encoding type: %s\n",a->content_transfer_encoding);
|
||||
else
|
||||
(void) fprintf(stderr,"Encoding type: none\n");
|
||||
(void) fprintf(stderr,"\n");
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,6 +184,56 @@ int add_server_cap_to_list(char *cap)
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
** Add each line entered with -H to list of lines
|
||||
** they represent custom headers in the mail.
|
||||
** For example X-Priority etc. can be added that way
|
||||
*/
|
||||
int add_customer_header_to_list(char *line)
|
||||
{
|
||||
Sll
|
||||
*nl = NULL;
|
||||
|
||||
char
|
||||
*l;
|
||||
|
||||
if (line == NULL || *line == '\0')
|
||||
{
|
||||
return (-1);
|
||||
}
|
||||
l = strdup(line);
|
||||
CHECK_MALLOC(l);
|
||||
nl = allocateNode((void *) l);
|
||||
CHECK_MALLOC(nl);
|
||||
appendNode(&custom_headers_head, &nl);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
** Add each line entered with -M to a list of lines
|
||||
** return 0 on success, -1 otherwise
|
||||
*/
|
||||
int add_one_line_to_list(char *line)
|
||||
{
|
||||
Sll
|
||||
*nl = NULL;
|
||||
|
||||
char
|
||||
*l;
|
||||
|
||||
if (line == NULL || *line == '\0')
|
||||
{
|
||||
return (-1);
|
||||
}
|
||||
l = strdup(line);
|
||||
CHECK_MALLOC(l);
|
||||
nl = allocateNode((void *) l);
|
||||
CHECK_MALLOC(nl);
|
||||
appendNode(&one_line_head, &nl);
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -141,6 +242,8 @@ int add_server_cap_to_list(char *cap)
|
||||
int add_attachment_to_list(char *file_path_mime)
|
||||
{
|
||||
int
|
||||
rc,
|
||||
separator,
|
||||
ntokens;
|
||||
|
||||
Sll
|
||||
@@ -150,7 +253,7 @@ int add_attachment_to_list(char *file_path_mime)
|
||||
**tokens=NULL,
|
||||
*file_path=NULL,
|
||||
*file_name=NULL,
|
||||
*mime_type=NULL,
|
||||
*mime_type,
|
||||
*content_disposition="attachment";
|
||||
|
||||
Attachment
|
||||
@@ -160,13 +263,17 @@ int add_attachment_to_list(char *file_path_mime)
|
||||
return(-1);
|
||||
|
||||
/* Tokenize the string "file,mime_type,something" */
|
||||
tokens=mutilsTokenize(file_path_mime,',',&ntokens);
|
||||
separator = *g_attach_sep;
|
||||
showVerbose("Separator: %c\n",separator);
|
||||
tokens=mutilsTokenize(file_path_mime,separator,&ntokens);
|
||||
if (tokens == NULL)
|
||||
{
|
||||
errorMsg("Could not parse attachment string: \"%s\"",file_path_mime);
|
||||
exit(1);
|
||||
exit_error();
|
||||
}
|
||||
|
||||
showVerbose("ntokens: %d\n",ntokens);
|
||||
|
||||
/* get the file name out */
|
||||
file_path=tokens[0];
|
||||
if ((file_name=strrchr(file_path,'/')) ||
|
||||
@@ -179,9 +286,7 @@ int add_attachment_to_list(char *file_path_mime)
|
||||
file_name=file_path;
|
||||
}
|
||||
|
||||
a=(Attachment *) malloc(sizeof(Attachment));
|
||||
CHECK_MALLOC(a);
|
||||
|
||||
a = allocate_attachment();
|
||||
a->file_path=xStrdup(file_path);
|
||||
a->file_name=xStrdup(file_name);
|
||||
|
||||
@@ -190,9 +295,11 @@ int add_attachment_to_list(char *file_path_mime)
|
||||
case 1: /* Only File_path/name given */
|
||||
{
|
||||
|
||||
/*
|
||||
mime_type="application/octet-stream";
|
||||
a->mime_type=xStrdup(mime_type);
|
||||
a->content_disposition=xStrdup("attachment");
|
||||
*/
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -200,75 +307,228 @@ int add_attachment_to_list(char *file_path_mime)
|
||||
{
|
||||
mime_type=tokens[1];
|
||||
a->mime_type=xStrdup(mime_type);
|
||||
a->content_disposition=xStrdup("attachment");
|
||||
break;
|
||||
}
|
||||
|
||||
case 3:
|
||||
case 3: /* filepath/name, mime_type, disposition given */
|
||||
case 4: /* filepath/name, mime_type, disposition, attchment name given */
|
||||
case 5: /* content-id */
|
||||
case 6: /* encoding type */
|
||||
{
|
||||
mime_type=tokens[1];
|
||||
a->mime_type=xStrdup(mime_type);
|
||||
content_disposition=tokens[2];
|
||||
if (*content_disposition == 'a')
|
||||
{
|
||||
a->content_disposition=xStrdup("attachment");
|
||||
}
|
||||
else if (*content_disposition == 'i')
|
||||
{
|
||||
a->content_disposition=xStrdup("inline");
|
||||
}
|
||||
else
|
||||
{
|
||||
a->content_disposition=xStrdup("attachment");
|
||||
}
|
||||
|
||||
if (ntokens == 4)
|
||||
{
|
||||
a->attachment_name = xStrdup(tokens[3]);
|
||||
}
|
||||
if (ntokens == 5)
|
||||
{
|
||||
a->attachment_name = xStrdup(tokens[3]);
|
||||
if (strncmp(tokens[4],"none",4) != 0)
|
||||
a->content_id = xStrdup(tokens[4]);
|
||||
}
|
||||
if (ntokens == 6)
|
||||
{
|
||||
a->attachment_name = xStrdup(tokens[3]);
|
||||
if (strncmp(tokens[4],"none",4) != 0)
|
||||
a->content_id = xStrdup(tokens[4]);
|
||||
a->content_transfer_encoding = xStrdup(tokens[5]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
default:
|
||||
{
|
||||
errorMsg("Invalid string specified with -a \"%s\"",file_path_mime);
|
||||
exit(1);
|
||||
exit_error();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
rc = mutils_file_is_binary(a->file_path);
|
||||
if (rc == -1)
|
||||
{
|
||||
errorMsg("Could not determine file type of %s",a->file_path);
|
||||
}
|
||||
if (rc == MUTILS_TRUE)
|
||||
{
|
||||
mime_type = get_mime_type(a->file_path);
|
||||
if (*g_mime_type != '\0')
|
||||
{
|
||||
if ((mutilsStrcasecmp(g_mime_type,"text/html") == 0) ||
|
||||
(mutilsStrcasecmp(g_mime_type,"text/plain") == 0))
|
||||
{
|
||||
a->charset = xStrdup("none");
|
||||
a->mime_type = xStrdup(mime_type);
|
||||
a->content_transfer_encoding = xStrdup("base64");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (a->mime_type == NULL)
|
||||
{
|
||||
if (*g_mime_type != '\0')
|
||||
{
|
||||
a->mime_type = xStrdup(g_mime_type);
|
||||
}
|
||||
else
|
||||
{
|
||||
a->mime_type = xStrdup(get_mime_type(a->file_path));
|
||||
}
|
||||
}
|
||||
if (a->content_transfer_encoding == NULL)
|
||||
{
|
||||
if (*g_content_transfer_encoding == '\0')
|
||||
{
|
||||
a->content_transfer_encoding = xStrdup("base64");
|
||||
}
|
||||
}
|
||||
|
||||
if (a->content_id == NULL)
|
||||
{
|
||||
if (*g_content_id != '\0')
|
||||
{
|
||||
a->content_id = xStrdup(g_content_id);
|
||||
}
|
||||
}
|
||||
|
||||
if (a->attachment_name == NULL)
|
||||
{
|
||||
a->attachment_name = xStrdup(file_name);
|
||||
}
|
||||
|
||||
na=allocateNode((void *) a);
|
||||
CHECK_MALLOC(na);
|
||||
|
||||
appendNode(&attachment_head,&na);
|
||||
|
||||
/*
|
||||
print_attachemtn_list();
|
||||
*/
|
||||
#if 0
|
||||
if ((mime_type=strchr(file_path_mime,ATTACHMENT_SEP)))
|
||||
{
|
||||
*mime_type++='\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
mime_type="application/octet-stream";
|
||||
}
|
||||
|
||||
|
||||
/* get the file name out */
|
||||
if ((file_name=strrchr(file_path_mime,'/')) || (file_name=strrchr(file_path_mime,'\\')))
|
||||
{
|
||||
file_name++;
|
||||
}
|
||||
else
|
||||
{
|
||||
file_name=file_path_mime;
|
||||
}
|
||||
|
||||
a=(Attachment *) malloc(sizeof(Attachment));
|
||||
CHECK_MALLOC(a);
|
||||
|
||||
a->file_path=xStrdup(file_path_mime);
|
||||
a->file_name=xStrdup(file_name);
|
||||
a->mime_type=xStrdup(mime_type);
|
||||
na=allocateNode((void *) a);
|
||||
CHECK_MALLOC(na);
|
||||
|
||||
appendNode(&attachment_head,&na);
|
||||
#endif /* 0 */
|
||||
|
||||
/*print_attachemtn_list();*/
|
||||
return(0);
|
||||
}
|
||||
|
||||
int add_embed_image_to_attachment_list(const char *image_file)
|
||||
{
|
||||
Sll
|
||||
*na=NULL;
|
||||
|
||||
Attachment
|
||||
*a=NULL;
|
||||
|
||||
if (image_file == NULL || *image_file == '\0')
|
||||
{
|
||||
return(-1);
|
||||
}
|
||||
a=allocate_attachment(); /* defaults will be set */
|
||||
|
||||
a->file_path = xStrdup(image_file);
|
||||
if (a->charset)
|
||||
{
|
||||
(void) free((char *) a->charset);
|
||||
a->charset = xStrdup("none");
|
||||
}
|
||||
|
||||
if (a->mime_type == NULL)
|
||||
{
|
||||
if (*g_mime_type != '\0')
|
||||
{
|
||||
a->mime_type = xStrdup(g_mime_type);
|
||||
}
|
||||
else
|
||||
{
|
||||
a->mime_type = xStrdup(get_mime_type(a->file_path));
|
||||
}
|
||||
}
|
||||
|
||||
if (a->content_transfer_encoding == NULL)
|
||||
{
|
||||
if (*g_content_transfer_encoding == '\0')
|
||||
{
|
||||
a->content_transfer_encoding = xStrdup("base64");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
na=allocateNode((void *) a);
|
||||
CHECK_MALLOC(na);
|
||||
appendNode(&embed_image_attachment_head,&na);
|
||||
return(0);
|
||||
|
||||
}
|
||||
|
||||
int add_msg_body_to_attachment_list(const char *msg_body_file)
|
||||
{
|
||||
Sll
|
||||
*na=NULL;
|
||||
|
||||
Attachment
|
||||
*a=NULL;
|
||||
|
||||
if (msg_body_file == NULL || *msg_body_file == '\0')
|
||||
{
|
||||
return(-1);
|
||||
}
|
||||
a=allocate_attachment(); /* defaults will be set */
|
||||
|
||||
a->file_path = xStrdup(msg_body_file);
|
||||
|
||||
na=allocateNode((void *) a);
|
||||
CHECK_MALLOC(na);
|
||||
appendNode(&msg_body_attachment_head,&na);
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** create a list of Attachment for one line messages
|
||||
** it uses -mime-type and -enc-type, so these two flags
|
||||
** must specified first before -M
|
||||
*/
|
||||
int add_oneline_to_attachment_list(char *oneline_msg)
|
||||
{
|
||||
Sll
|
||||
*na=NULL;
|
||||
|
||||
Attachment
|
||||
*a=NULL;
|
||||
|
||||
if (oneline_msg == NULL || *oneline_msg == '\0')
|
||||
{
|
||||
return(-1);
|
||||
}
|
||||
a=allocate_attachment(); /* defaults will be set */
|
||||
|
||||
a->oneline_msg=xStrdup(oneline_msg);
|
||||
a->content_disposition=xStrdup("inline");
|
||||
if (*g_mime_type == '\0')
|
||||
{
|
||||
a->mime_type = xStrdup("text/plain");
|
||||
}
|
||||
|
||||
if (a->content_transfer_encoding == NULL)
|
||||
{
|
||||
a->content_transfer_encoding = xStrdup("none");
|
||||
}
|
||||
na=allocateNode((void *) a);
|
||||
CHECK_MALLOC(na);
|
||||
|
||||
appendNode(&oneline_attachment_head,&na);
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -421,7 +681,7 @@ int addAddressesFromFileToList(char *address_file)
|
||||
if (addr == NULL)
|
||||
{
|
||||
errorMsg("addAddressToList: malloc problem for newAddress()");
|
||||
return (-1);
|
||||
goto ExitProcessing;
|
||||
}
|
||||
/* fill with data */
|
||||
showVerbose("Label: %s\n",label);
|
||||
@@ -434,7 +694,7 @@ int addAddressesFromFileToList(char *address_file)
|
||||
{
|
||||
errorMsg("addAddressToList: malloc problem with allocateNode()");
|
||||
(void) free ((char *) addr);
|
||||
return (-1);
|
||||
goto ExitProcessing;
|
||||
}
|
||||
appendNode(&addr_head,&list);
|
||||
}
|
||||
@@ -443,6 +703,10 @@ int addAddressesFromFileToList(char *address_file)
|
||||
(void) fclose(fp);
|
||||
|
||||
return (0);
|
||||
ExitProcessing:
|
||||
if (fp != (FILE *) NULL)
|
||||
(void) fclose(fp);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
|
||||
@@ -451,15 +715,66 @@ Sll *getAddressList(void)
|
||||
return (addr_head);
|
||||
}
|
||||
|
||||
Sll *get_one_line_list(void)
|
||||
{
|
||||
return (one_line_head);
|
||||
}
|
||||
|
||||
Sll *get_custom_header_list(void)
|
||||
{
|
||||
return (custom_headers_head);
|
||||
}
|
||||
|
||||
Sll *get_attachment_list(void)
|
||||
{
|
||||
return(attachment_head);
|
||||
}
|
||||
Sll *get_oneline_attachment_list(void)
|
||||
{
|
||||
return(oneline_attachment_head);
|
||||
}
|
||||
|
||||
Sll *get_server_cap_list(void)
|
||||
{
|
||||
return(server_caps);
|
||||
}
|
||||
|
||||
Sll *get_msg_body_attachment_list(void)
|
||||
{
|
||||
return(msg_body_attachment_head);
|
||||
}
|
||||
|
||||
Sll *get_embed_image_attachment_list(void)
|
||||
{
|
||||
return (embed_image_attachment_head);
|
||||
}
|
||||
|
||||
Attachment *allocate_attachment(void)
|
||||
{
|
||||
Attachment
|
||||
*a;
|
||||
a = (Attachment *) malloc(sizeof(Attachment));
|
||||
CHECK_MALLOC(a);
|
||||
memset(a,0,sizeof(Attachment));
|
||||
|
||||
a->charset = xStrdup(g_charset); /* default is "utf-8" */
|
||||
if (*g_mime_type != '\0')
|
||||
{
|
||||
a->mime_type = xStrdup(g_mime_type);
|
||||
}
|
||||
|
||||
if (*g_content_transfer_encoding != '\0')
|
||||
a->content_transfer_encoding = xStrdup(g_content_transfer_encoding);
|
||||
|
||||
a->attach_separator = *g_attach_sep;
|
||||
a->content_disposition = xStrdup(g_content_disposition);
|
||||
if (*g_attach_name != '\0')
|
||||
{
|
||||
a->attachment_name = xStrdup(g_attach_name);
|
||||
}
|
||||
|
||||
return(a);
|
||||
}
|
||||
|
||||
/* just a debug routine */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user