bug-mailutils
[Top][All Lists]
Advanced

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

RE: [bug-mailutils] Stream usage


From: Alain Magloire
Subject: RE: [bug-mailutils] Stream usage
Date: Wed, 7 Sep 2005 15:03:13 -0400


> -----Original Message-----
> From: address@hidden [mailto:bug-mailutils-
> address@hidden On Behalf Of Simon Walter
> Sent: Wednesday, September 07, 2005 1:27 PM
> To: address@hidden
> Subject: [bug-mailutils] Stream usage
> 
> 
> Hello
> 
> I'm using mailutil libs in a small mailrobot.
> 
> while developing the mailbox is a simple mailfile.
> in productive the mailbox is pop3.
> 
> I have written a function to search with a regular expression through
> the mailbody and return everything after a separator.
> 
> when I use the mailfile I can call the function twice, but when i use
> a pop3-account the second call of the function doesn't enter the
> while-loop.
> 
> so there must be a difference between a memory-based stream and a
> file-based...
> is this a bug or am I doing something wrong?
> 

It's been a long time since I play with mailutils, but basically yes, there
is a difference, not so much between the stream but the underlying
implementation (POP3 vs File access, Mailbox).  For POP3 protocol, when you
issue a command to retrieve data whether it is the header, the body or the
full message, the command is not cancelable.

So you may have broken out of the loop too early (before reading the entire
message/body) because of regex match.  In this scenario, when you come back
the second time to read another message, the stream reading returns EBUSY or
something like that, meaning the last TOP/RETR command sent to the pop
server is not complete.

You can take a few steps to remedy:
- do not break out of the loop before you finish reading the message
- Or make a copy of the message in a second stream. For example use a
memory_stream(or a file_stream) to hold temporary the message then do the
matching on that stream.  This will isolate you form network hiccup for
protocols like POP3 that are limited.

We take some steps to hide the underlying protocol to the user, but in the
end .. it may not be enough.  I'm thinking maybe we should look at a
shadowing mailbox or something similar to hide those mundane
protocol/networking detail to the users ... hmmm...

> <code>
> char *mc_get_field_value(data_t *data, regex_t *regexp, char *sep) {
> 
>   char *value = NULL;
>   body_t body;
>   stream_t stream;
>   char *p;
>   char buf[128];
>   off_t off = 0;
>   size_t rd;
> 
>   int regex_ret;
>   regmatch_t regmatch[RE_SIZE];
> 
>   /* ||| */
> 
>   message_get_body(*(data->msg), &body);
>   body_get_stream(body, &stream);
> 
>   while(value == NULL
>         && stream_readline(stream, buf, sizeof(buf), off, &rd) == 0
>         && rd != 0) {
>     off += rd;
> 
>     if ((regex_ret = regexec(regexp, buf, RE_SIZE, regmatch, 0)) == 0) {
>       if((p = strstr(buf,sep)) != NULL) {
>         value = strdup(p+strlen(sep));
>         if((p = strchr(value,'\n')) != NULL)
>           *p = '\0';
>         break;
>       }
>     }
>   }
> 
>   return value;
> }
> </code>
> 
> --
> Mit freundlichen Grüßen
> 
> Simon Walter
> NETHINKS GmbH, Technik
> Bahnhofstraße 16
> 36037 Fulda
> Tel: +49 661 25000-0
> Fax: +49 661 25000-49
> eMail: address@hidden
> 
> 
> _______________________________________________
> Bug-mailutils mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/bug-mailutils




reply via email to

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