bug-mailutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-mailutils] Stream write error.


From: Alastair Poole
Subject: [bug-mailutils] Stream write error.
Date: Tue, 18 Apr 2006 19:31:34 +1000

Hello,

I am currently experimenting with the library in the hope of future use.
However I have a problem when writing to a stream.  It fails, though why
I do not know, I have investigated the source but am still unsure.  Here
is the relevant code.  Hopefully someone will know why this fails. (I
can send messages fine, just no data).

#include "xmta_mailer.h"
#include "xmta_stdinc.h"

int xmta_mailer_open(char *from, char *email, char *data)
{
        extern xm_config_t config;
        char auth_string[BUFSIZ];
        mailer_t mailer;
        int status;

        if(config.s_protocol == SMTP) {
                sprintf(auth_string, "smtp://:address@hidden", 
config.s_password,
                                        config.s_server);
        }
        
        printf("Auth string %s\n", auth_string);
        
        status = mailer_create(&mailer, auth_string);
        if(status) {
                fprintf(stderr, "Error: Unable to create mailer\n");
                return XM_FAILURE;
        }       

        status = mailer_open(mailer, MU_STREAM_WRITE | MU_STREAM_CREAT);
        if(status) {
                fprintf(stderr, "Error: Unable to open mailer\n");
                return XM_FAILURE;
        }

        
        xmta_mailer_compose(&mailer, from, email, data);
        

        mailer_close(mailer);
        mailer_destroy(&mailer);

        return XM_SUCCESS;
}

int xmta_mailer_compose(mailer_t *mailer, char *from, char *email, char *data)
{
        int status;
        message_t msg;
        body_t body;
        stream_t stream;
        size_t ret;
        address_t afrom, ato;
        off_t offset = 0;
        const char *data2 = "DATA\r\nTHIS IS A MESSAGE\r\n.\r\n";

        message_create(&msg, *mailer);
        
        stream_create(&stream, MU_STREAM_WRITE, msg);

        status = stream_setbufsiz(stream, strlen(data2)+1);
        printf("stream_setbufsiz = %s\n",mu_strerror(status));

        status = stream_sequential_write(stream, data2 + offset, strlen(data2));

        printf("stream_seq_write = %s\n", mu_strerror(status));

        /* Always returns Invalid Argument (22) (EINVAL) for stream_write */
        /* and stream_sequential_write. However we do send the mail,      */
        /* just no data...*/

        body_create(&body, &msg);
        body_set_stream(body, stream, msg); 

        message_set_body(msg, body, NULL);      
        
        address_create(&afrom, from);
        address_create(&ato, "address@hidden");
        
        mailer_send_message(*mailer, msg, afrom, ato);
        
        return XM_SUCCESS;
}

Thanks in advance,


Alastair

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]