Hello, I have another problem related to this. Even when I create a copy of the message and use this copy to parse through the message I can't use the attributes of the original message for attribute_set_deleted(). The pointer _get_flags in the attribute struct gets invalid.
Marking the message as deleted before I work with the stream is no problem but thats a bad solution for me, because I only wan't to deleted a message if processing and forwarding went fine. Creating new attributes and set them to the message also fails at the destruction of the old attributes. Any suggestions? Alain Magloire <[EMAIL PROTECTED]> writes: >> -----Original Message----- >> From: [EMAIL PROTECTED] [mailto:bug-mailutils- >> [EMAIL PROTECTED] On Behalf Of Simon Walter >> Sent: Wednesday, September 07, 2005 1:27 PM >> To: [email protected] >> 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: [EMAIL PROTECTED] _______________________________________________ Bug-mailutils mailing list [email protected] http://lists.gnu.org/mailman/listinfo/bug-mailutils
