Subject: mail_append() function with IMAP4

From: "Guillaume Vaillant" <[email-masked]>
Date: Mon, 28 Oct 2002 18:31:29 +0100

Hello,

I'm a new user of the c-client API and I need help to use the
mail_append(Stream, mailbox, STRING *message) function.
In fact I want to put a new composed message with attachments in a
particular folder of my IMAP account.
To do that i try to connect on this folder and retrieve the stream : it's OK
And after I want to build this message and post it in the folder with the
mail_append function. My first question is :
Is it the good way and the good function to do this action ?

I have a big problem. I don't know how to create the STRING structure which
contains my message.
I think I have to give the : FROM, TO, Subject, Body and the local files to
Attach but I don't know how to do that.
Does someone can help me ?

Thank's
Guyom

-- 
------------------------------------------------------------------
 For information about this mailing list, and its archives, see: 
 http://www.washington.edu/imap/c-client-list.html
------------------------------------------------------------------

---

From: Mark Crispin <[email-masked]>
Date: Mon, 28 Oct 2002 09:43:23 -0800 (PST)

Yes, mail_append() is the correct function for uploading a message from your
client to a mailbox.

In short, what you need to put into the STRING structure is, in conjunction
with a stringdriver that you probably also write, the entire textual contents
of the message.  You have to build the message yourself.

There are some c-client functions which can help do this, but most of the work
you have to do yourself.  In particular, functions such as rfc822_output() can
help you build the message text.  In the most simple-minded case you can
simply write the text into a tmpfile and then read it back with your
stringdriver and STRING structure.

Your best bet is to look at the code in Pine's send.c source code, which is an
example of a sophisticated client that does something much better than the
"simple-minded case."  A detailed answer to your question is too complex to
answer in an email message.

---

From: "Guillaume Vaillant" <[email-masked]>
Date: Tue, 10 Dec 2002 19:12:15 +0100

Hello,
I'm a new user of the c-client API and I need help to manage memory leaks on
my application.
I use for example  the mail_fetchbody_full function which return a (char *)
data.
I want to know if I have to free this pointed memory or not ?

It's not the only one function for which i don't know who free the memory.
Where can i find help about that point
Does someone can help me ?

Thank's
Guyom

---

From: "Shawn Walker" <[email-masked]>
Date: Tue, 10 Dec 2002 12:28:58 -0600

Hello,

You need to run the garbage collector to get the cclient to free the
memory.  To do the following code after you call mail_fetchbody_full().

// Run the garbage collection to free up memory in cclient

mail_parameters(MailStream, SET_GETS, nil);
mail_gc(MailStream, GC_TEXTS);

---

From: Mark Crispin <[email-masked]>
Date: Tue, 10 Dec 2002 10:38:36 -0800 (Pacific Standard Time)

> I want to know if I have to free this pointed memory or not ?

You do not need to free any memory returned by any mail_???() function;
and in fact you must not free such memory.

The only memory that you ever need to free in c-client is memory from
certain calls that are documented to create memory, most notably cpystr(),
rfc822_binary(), rfc822_base64(), rfc822_8bit(), and rfc822_qprint().

-- Mark --

http://staff.washington.edu/mrc
Science does not emerge from voting, party politics, or public debate.

---

From: Mark Crispin <[email-masked]>
Date: Tue, 10 Dec 2002 10:40:27 -0800 (Pacific Standard Time)

> mail_gc(MailStream, GC_TEXTS);

This is an extremely BAD idea, unless of course you like writing
applications which are slow and waste network bandwidth.

c-client caches for a reason.  The only justification for using mail_gc()
is if you are writing a program for DOS, 16-bit Windows (Windows 3.x), or
old Macintosh systems.  It should never be used on modern systems except
in extreme circumstances; and certainly should not be used routinely.

-- Mark --

---

From: "Shawn Walker" <[email-masked]>
Date: Tue, 10 Dec 2002 12:45:44 -0600

>in extreme circumstances; and certainly should not be used routinely.

Then how does one get cclient to free the memory after it retrieve a VERY
large message from the server?  I debugged into cclient saw how the message
is being stored in memory and how to free it and the only way was to run
the garbage collector.

Shawn

---

From: Mark Crispin <[email-masked]>
Date: Tue, 10 Dec 2002 10:47:53 -0800 (Pacific Standard Time)

> is being stored in memory and how to free it and the only way was to run

What do you mean by "VERY large"?

Whenever you run the garbage collector, you destroy the entire cache,
which means that c-client is forced to re-fetch any data that it needs
again.  Unless you mean at least "tens of megabytes" by "VERY large", you
are causing more harm than good by doing so.

And even if it is that big, what if the user references it again?

Note that when you expunge a message, any cache associated with that
message is freed.

Memory is cheap.  Use it.

-- Mark --

---

From: "Shawn Walker" <[email-masked]>
Date: Tue, 10 Dec 2002 12:55:58 -0600

>Note that when you expunge a message, any cache associated with that

That is the "problem".  I have had several customers running low on
resources when the application was downloading a very large INBOX folder
(the folder contains several thousands messages with very large messages
that contains attachments).  The user was getting memory getting low on the
windows machine.  I was able to recreate the problem what the customers was
having and it was a problem.  I had to get cclient to free the memory to
keep that from happening.

Shawn

---

From: Mark Crispin <[email-masked]>
Date: Tue, 10 Dec 2002 11:11:50 -0800 (Pacific Standard Time)

On Tue, 10 Dec 2002, Shawn Walker wrote:
> that contains attachments).

Why is the application "downloading"?  Are you using IMAP like IMAP, or
like a fancy POP?

The c-client library is intended to be used for interactive access, and
not really for POP-like "downloading".

-- Mark --

---

From: "Shawn Walker" <[email-masked]>
Date: Tue, 10 Dec 2002 14:14:55 -0600

>not really for POP-like "downloading".

The user selected to download all messages and body.  So, that is what the
app is doing.  The users do that to do "off-line" mode.  But, cclient is
still hold the messages, even if the user manually select each message to
read, cclient cache them.  How to get cclient to free the memories?

Shawn