bug-mailutils
[Top][All Lists]
Advanced

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

Re: [bug-mailutils] Email


From: Sergey Poznyakoff
Subject: Re: [bug-mailutils] Email
Date: Wed, 02 Apr 2003 15:27:22 +0300

> > B)
> >

First of all, notice that any remote server supported by mailutils
is regarded as a mailbox and usual mailbox functions are applicable.
In particular, once the remote mailbox is opened, the messages may be
retrieved using mailbox_get_message() function.

> > 1) Initialize library

The only requirement is to register a pop_record:

list_t list;
registrar_get_list (&list);
list_append (bookie, pop_record);

> > 2) Log in to POP3 server using username/password

This boils down to the creating and opening a maibox with an URL
like "pop://some.server.net". To specify the username and password,
use the following syntax:

      pop://USERNAME:address@hidden

(To use more sophisticated authentication schemes you will have to use
so-called tickets. That's another topic.)

E.g.:

mailbox_t mbox;  

mailbox_create (&mbox, "pop://address@hidden:pop3.farlep.net");
mailbox_open (mbox, MU_STREAM_RDWR);

>From then on, operate with mbox as if it were a usual mailbox.

> > 3) Retrieve messages 1 at a time

size_t num;
message_t msg;
...
num = 1;
mailbox_get_message (mbox, num, &msg);
...

See mail/decode.c

> > 4) Detect and mime decode any file attachments to disk

int ismime;
if (message_is_multipart (msg, &ismime) == 0 && ismime)
  {
    /* It is a MIME multipart message */
    size_t nparts; /* number of parts in the message */
    size_t i;

    message_get_num_parts (mesg, &nparts);
    for (i = 1; i <= nparts; i++)
      {
        message_t part;
        body_t body;

        message_get_part (msg, i, &part);
        message_get_body (part, &body);
        
       ...

See mail/decode.c and mh/mhn.c for practical examples.

> > 5) Log off POP3 server

mailbox_destroy (&mbox);

The same sequence applies to any type of mailbox, no matter remote or
local. The only thing that changes is the URL given to
mailbox_create().

> Are you aware of any requirement that some SMTP servers allow for a user
> name and password.
> 
> My guess is that mail relay only puts a timeout after you "Retrieve"
> from a POP3 server. 
> This timeout will then let you "send" for a short period of time.
> 
> The password is supplied when you POP3 retrieve, not when you SMTP send.

Yes, you are referring to so-called DRAC (Dynamic Relay Authorization
Control). It is described at http://mail.cc.umanitoba.ca/drac.

> I have built a much more concise example from which to understand your
> response:

Great. It is quite correct. A minor explanation:

> //Do we use this function, or skip it?
> int message_create (message_t *pmsg, void *owner)

Not if you are working with the message retrieved from a mailbox.
You would only have to use this function if you were extending
libmailbox with a support for some new mailbox/mailer/whatever format.

> //What source code file would you look to obtain the content_type and
> encoding parameters?
> //For example, Base64 encoding?
> message_create_attachment (content_type, encoding, filename, &msg);

Content type and encoding are obtained from the headers Content-Type
and Content-Encoding in the attachment. See mh/mhn.c.

> I also did not see how to add plain text to the "body" of the message.

body_t body;
stream_t stream;
char buffer[BUFSIZE];
size_t offset, n;

message_get_body (msg, &body);
body_get_stream (body, &stream);

stream_write (stream, buffer, sizeof buffer, offset, &n);

`offset' is the offset into the body stream. Upon completion `n'
contains the number of bytes actually written. To simplify this,
you may use sequential stream access (stream_sequential_read,
stream_sequential_write, etc.) See mh/mhn.c

> Will there be any pause in the program in mailer_send_message( )
> and request data from standard input? 

No, it will not require any data from the stdin.

Regards,
Sergey












reply via email to

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