Subject: mail_free_*

From: Mike Trank <[email-masked]>
Date: Sun, 14 Nov 1999 19:46:35 -0600 (CST)

ok.

One thing that has never worked from me is mail_free_body,
mail_free_envelope and mail_free_elt.

I always get segmentation faults when I try to do these. I admit that I am
not always very concientious about doing free()'s, etc.

But when I try to do these, they always crash the program.

Is there anything that I have to know about the order in which they have
to be done or anything that I have to make sure that Ive done first before
calling these functions?

-- 
------------------------------------------------------------------
 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: Sun, 14 Nov 1999 20:02:38 -0800 (PST)

> not always very concientious about doing free()'s, etc.

The only time that you ever call mail_free_envelope() is with an envelope that
you created with mail_newenvelope().  Similarly, the only time that you ever
call mail_free_body() is with a body that you created with mail_newbody.

There is rarely an instance where it is appropriate for you to call
mail_free_elt(), since elts are only created with mail_new_cache_elt() which
is only called internally.  The exception is if you use an advanced concept
called "elt locking", in which you make a private pointer to an elt for use
someplace.  To keep the elt from going away if the message gets expunged (thus
invaliding your pointer, you increment its elt->lockcount.  When finished with
the pointer, call mail_free_elt() instead of doing elt->lockcount--, e.g.
	elt->lockcount++;	/* keep elt from going away */
	blurdybloop->elt = elt;	/* remember elt */
	... lots of code ...
	mail_free_elt (&blurdybloop->elt);

In particular, you do not call these functions on envelopes, bodys, or elts
that were returned by a c-client function, such as mail_fetch_structure() or
mail_elt().  The upshot is that the only time you ever call them is when you
make (and fill in) your own when SMTP sending or NNTP posting a message.

Similarly, you never fs_give() text data (always use fs_get() and fs_give()
instead of malloc() and free()) returned by mail_fetch_text() and friends.

The only time you ever fs_give() is when you call fs_get() or a c-client
function that returns a copy of data that you supply:
	cpystr(), rfc822_base64(), rfc822_binary(), rfc822_8bit(),
	rfc822_qprint().

---

From: Mike Trank <[email-masked]>
Date: Sun, 14 Nov 1999 22:54:50 -0600 (CST)

> call mail_free_body() is with a body that you created with mail_newbody.

Ohhhhhhhh. Ok. So I guess Il just leave them out.

Here's another problem that Im having right now. I am calling
"mail_move()". The messages get moved to the other mailbox, but the
original ones dont get deleted, the flags dont even get set. 

What is supposed to happen? Are the messages supposed to disapear or do
they just get flagged delete for the next "expunge". Im using the mbox
files, by the way.

Every time I do a move_mail(), the next instance of a c-client program
will always claim that it cant get write access to the file. Is that a
clue?

---

From: Mark Crispin <[email-masked]>
Date: Sun, 14 Nov 1999 21:37:00 -0800 (PST)

> original ones dont get deleted, the flags dont even get set.

In the standard UNIX mailbox format, the source mailbox flags aren't updated
until the next checkpoint: mail_check(), mail_expunge(), or mail_close().

> they just get flagged delete for the next "expunge".

The messages get the deleted flag for the next expunge.

> will always claim that it cant get write access to the file. Is that a

What is "the file" -- the source or the destination?  Please be more specific
about what, precisely, you are doing.

Also, please make sure that you have the latest version.  The current release
version is imap-4.6, but I recommend that you use the imap-4.7.BETA version
instead:
	ftp://ftp.cac.washington.edu/mail/imap-4.7.BETA.tar.Z