Index: openacs-4/packages/contacts/lib/email.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/lib/email.tcl,v
diff -u -r1.19 -r1.20
--- openacs-4/packages/contacts/lib/email.tcl	3 Feb 2006 01:29:28 -0000	1.19
+++ openacs-4/packages/contacts/lib/email.tcl	20 Feb 2006 09:13:58 -0000	1.20
@@ -31,7 +31,7 @@
 set recipients [list]
 foreach party_id $party_ids {
     if {![empty_string_p $party_id]} {
-	lappend recipients [list "<a href=\"[contact::url -party_id $party_id]\">[contact::name -party_id $party_id]</a> ([cc_email_from_party $party_id])" $party_id]
+	lappend recipients [list "<a href=\"[contact::url -party_id $party_id]\">[contact::name -party_id $party_id]</a> ([contact::message::email_address -party_id $party_id])" $party_id]
     }
 }
 
@@ -173,13 +173,13 @@
     } -on_submit {
 	
 	# We get the attribute_id of the salutation attribute
-	set attribute_id [db_string get_attribute_id { } -default {}]
+	set attribute_id [attribute::id -object_type "person" -attribute_name "salutation"]
 	    
 	# List to store know wich emails recieved the message
 	set recipients_addr [list]
 
 	set from [ad_conn user_id]
-	set from_addr [cc_email_from_party $from]
+	set from_addr [contact::email -party_id $from]
 
 	# Remove all spaces in cc
 	regsub -all " " $cc "" cc
@@ -216,7 +216,7 @@
 		set salutation "Dear ladies and gentlemen"
 		set locale [lang::user::site_wide_locale -user_id $party_id]
 	    }
-	    set to_addr [cc_email_from_party $party_id]
+	    set to_addr [contact::message::email_address -party_id $party_id]
 	    set date [lc_time_fmt [dt_sysdate] "%q"]
 	    set to $name
 
Index: openacs-4/packages/contacts/lib/email.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/lib/email.xql,v
diff -u -r1.1 -r1.2
--- openacs-4/packages/contacts/lib/email.xql	24 Oct 2005 18:11:03 -0000	1.1
+++ openacs-4/packages/contacts/lib/email.xql	20 Feb 2006 09:13:58 -0000	1.2
@@ -12,15 +12,4 @@
     </querytext>
 </fullquery>
 
-<fullquery name="get_attribute_id">
-    <querytext>
-	 select 
-		attribute_id 
-	from 
-		ams_attributes 
-	where 
-		attribute_name = 'salutation';	
-    </querytext>
-</fullquery>
-
-</queryset>
\ No newline at end of file
+</queryset>
Index: openacs-4/packages/contacts/lib/oo_mailing.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/lib/oo_mailing.tcl,v
diff -u -r1.7 -r1.8
--- openacs-4/packages/contacts/lib/oo_mailing.tcl	31 Jan 2006 11:49:22 -0000	1.7
+++ openacs-4/packages/contacts/lib/oo_mailing.tcl	20 Feb 2006 09:13:58 -0000	1.8
@@ -190,7 +190,7 @@
 		    set to_addr $employee(email)
 		} else {
 		    set name [contact::name -party_id $party_id]
-		    set to_addr [cc_email_from_party $party_id]
+		    set to_addr [contact::message::email_address -party_id $party_id]
 		    set salutation "Dear ladies and gentlemen"
 		    set locale [lang::user::site_wide_locale -user_id $party_id]
 		}
@@ -202,7 +202,7 @@
 		
 		# We are going to create a multirow which knows about the file (revision_id) and contains
 		# the parsed e-mail.
-		set to_addr [party::email -party_id $party_id]
+		set to_addr [contact::message::email_address -party_id $party_id]
 		template::multirow append messages $revision_id $to_addr "" [contact::message::interpolate -text $subject -values $values] [contact::message::interpolate -text $email_content -values $values]
 	    }
 
@@ -219,7 +219,7 @@
 
 	if {$subject ne ""} {
 	    set from [ad_conn user_id]
-	    set from_addr [cc_email_from_party $from]
+	    set from_addr [contact::email -party_id $from]
 	    set package_id [ad_conn package_id]
 
 	    template::multirow foreach messages {
Index: openacs-4/packages/contacts/tcl/contact-message-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/tcl/contact-message-procs.tcl,v
diff -u -r1.21 -r1.22
--- openacs-4/packages/contacts/tcl/contact-message-procs.tcl	15 Feb 2006 10:06:36 -0000	1.21
+++ openacs-4/packages/contacts/tcl/contact-message-procs.tcl	20 Feb 2006 09:13:58 -0000	1.22
@@ -158,84 +158,112 @@
 ad_proc -private contact::message::email_address_exists_p {
     {-party_id:required}
 } {
-    Does a email address exist for this party. Cached
+    Does a message email address exist for this party or his/her employer. Cached via contact::message::email_address.
 } {
-    return [util_memoize [list ::contact::message::email_address_exists_p_not_cached -party_id $party_id]]
+    return [string is false [empty_string_p [contact::message::email_address -party_id $party_id]]]
 }
 
-ad_proc -private contact::message::email_address_exists_p_not_cached {
+ad_proc -private contact::message::email_address {
     {-party_id:required}
 } {
-    Does a email address exist for this party
+    Does a message email address exist for this party
 } {
-    return [string is false [empty_string_p [contact::email -party_id $party_id]]]
+    return [util_memoize [list ::contact::message::email_address_not_cached -party_id $party_id]]
 }
 
-ad_proc -private contact::message::mailing_address_exists_p {
+ad_proc -private contact::message::email_address_not_cached {
     {-party_id:required}
 } {
-    Does a mailing address exist for this party. Cached
+    Does a message email address exist for this party
 } {
-    return [util_memoize [list ::contact::message::mailing_address_exists_p_not_cached -party_id $party_id]]
+    set email [contact::email -party_id $party_id]
+    if { $email eq "" } {
+	# if this person is the employee of
+        # an organization we can attempt to use
+        # that organizations email address
+	foreach employer_id [contact::util::get_employers] {
+	    set email [contact::email -party_id $employer_id]
+	    if { $email ne "" } {
+		break
+	    }
+	}
+    }
+    return $email
 }
 
-ad_proc -private contact::message::mailing_address_exists_p_not_cached {
+ad_proc -private contact::message::mailing_address_exists_p {
     {-party_id:required}
 } {
-    Does a mailing address exist for this party
+    Does a mailing address exist for this party. Cached via contact::message::mailing_address.
 } {
-    set attribute_ids [contact::message::mailing_address_attribute_id_priority]
-    set revision_id [contact::live_revision -party_id $party_id]
-    if { [llength $attribute_ids] > 0 } {
-        if { [db_0or1row mailing_address_exists_p " select '1' from ams_attribute_values where object_id = :revision_id and attribute_id in ('[join $attribute_ids {','}]') limit 1 "] } {
-            return 1
-        } else {
-            return 0
-        }
-    } else {
-        return 0
-    }
+    # since this check is almost always called by a page which
+    # will later ask for the mailing address we take on the 
+    # overhead of calling for the address, which is cached.
+    # this simplifies the code and thus "pre" caches the address
+    # for the user, which overall is faster
+
+    return [string is false [empty_string_p [contact::message::mailing_address -party_id $party_id -format "text"]]]
 }
 
 ad_proc -private contact::message::mailing_address {
     {-party_id:required}
     {-format "text/plain"}
 } {
-    Does a mailing address exist for this party
+    Returns a parties mailing address. Cached
 } {
     regsub -all "text/" $format "" format
     if { $format != "html" } {
 	set format "text"
     }
+    return [util_memoize [list ::contact::message::mailing_address_not_cached -party_id $party_id -format $format -package_id [ad_conn package_id]]]
+}
 
-    set attribute_ids [contact::message::mailing_address_attribute_id_priority]
+ad_proc -private contact::message::mailing_address_not_cached {
+    {-party_id:required}
+    {-format:required}
+    {-package_id:required}
+} {
+    Returns a parties mailing address
+} {
+    set attribute_ids [contact::message::mailing_address_attribute_id_priority -package_id $package_id]
     set revision_id [contact::live_revision -party_id $party_id]
     set mailing_address {}
-    db_foreach mailing_address_values "
-                   select attribute_id,
-                          ams_attribute_value__value(attribute_id,value_id) as value
-                     from ams_attribute_values
-                    where object_id = :revision_id
-                      and attribute_id in ('[join $attribute_ids {','}]')
-    " {
-	set attribute_value($attribute_id) $value
+    foreach attribute_id $attribute_ids {
+	set mailing_address [ams::value \
+				 -object_id $revision_id \
+				 -attribute_id $attribute_id \
+				 -format $format]
+	if { $mailing_address ne "" } {
+	    break
+	}
     }
-    foreach attribute $attribute_ids {
-	if { [info exists attribute_value($attribute)] } {
-	    set mailing_address [ams::widget \
-				     -widget postal_address \
-				     -request "value_${format}" \
-				     -value $value \
-				    ]
-
-            break
-        }
+    if { $mailing_address eq "" } {
+	# if this person is the employee of
+        # an organization we can attempt to use
+        # that organizations email address
+	foreach employer_id [contact::util::get_employers] {
+	    set mailing_address [contact::message::mailing_address -party_id $employer_id -package_id $package_id]
+	    if { $mailing_address ne "" } {
+		break
+	    }
+	}
     }
     return $mailing_address
 }
 
+
+
 ad_proc -private contact::message::mailing_address_attribute_id_priority {
+    {-package_id:required}
 } {
+    Returns the order of priority of attribute_ids for the letter mailing address. Cached
+} {
+    return [util_memoize [list ::contact::message::mailing_address_attribute_id_priority_not_cached -package_id $package_id]]
+}
+
+ad_proc -private contact::message::mailing_address_attribute_id_priority_not_cached {
+    {-package_id:required}
+} {
     Returns the order of priority of attribute_ids for the letter mailing address
 } {
     set attribute_ids [parameter::get -parameter "MailingAddressAttributeIdOrder" -default {}]
@@ -466,3 +494,32 @@
 
     return $new_file
 }
+
+
+
+
+
+
+
+
+ad_proc -public -callback contacts::redirect -impl contactspdfs {
+    {-party_id ""}
+    {-action ""}
+} {
+    redirect the contact to the correct pdf stuff
+} {
+
+    ns_log notice "got here..."
+    set url [ad_conn url]
+    if { [regexp "^[ad_conn package_url]pdfs/" $url match] } {
+	# this is a pdf url
+	set filename [lindex [ad_conn urlv] end]
+	if { ![regexp "^contacts_.*?_[ad_conn user_id](.*).pdf$" $filename match] || ![file exists "/tmp/${filename}"] } {
+	    ad_return_error "No Permission" "You do not have permission to view this file, or the temporary file has been deleted."
+	} else {
+	    ns_returnfile 200 "application/pdf" "/tmp/${filename}"
+	}
+    }
+
+}
+
Index: openacs-4/packages/contacts/tcl/contacts-callback-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/tcl/contacts-callback-procs.tcl,v
diff -u -r1.26 -r1.27
--- openacs-4/packages/contacts/tcl/contacts-callback-procs.tcl	16 Feb 2006 14:06:43 -0000	1.26
+++ openacs-4/packages/contacts/tcl/contacts-callback-procs.tcl	20 Feb 2006 09:13:58 -0000	1.27
@@ -17,6 +17,28 @@
     After instantiate callback
 } -
 
+ad_proc -public -callback contact::label {
+    {-request:required}
+    {-for ""}
+} {
+    You can request one of:
+    1. ad_form_option (list of pretty name key to be used in ad_form)
+    2. template (the template and stylesheet parts of a page template) the option selected
+       will be passed to the callback as 'for', so the template should only be returned if
+       it matches the option provided by this implementation from ad_form_option
+} -
+
+ad_proc -public -callback contact::envelope {
+    {-request:required}
+    {-for ""}
+} {
+    You can request one of:
+    1. ad_form_option (list of pretty name key to be used in ad_form)
+    2. template (the template and stylesheet parts of a page template) the option selected
+       will be passed to the callback as 'for', so the template should only be returned if
+       it matches the option provided by this implementation from ad_form_option
+} -
+
 ad_proc -public -callback contact::contact_form {
     {-package_id:required}
     {-form:required}
@@ -255,3 +277,132 @@
 	}
     }
 }
+
+
+ad_proc -public -callback contact::label -impl avery5160 {
+    {-request:required}
+    {-for ""}
+} {
+} {
+    switch $request {
+	ad_form_option {
+	    return [list "Avery 5160 (1in x 2.5in, 30 per sheet)" avery5160]
+	}
+	template {
+	    if { $for == "avery5160" } {
+		return {<template pageSize="(8.5in, 11in)"
+          leftMargin="0in"
+          rightMargin="0in"
+          topMargin="0in"
+          bottomMargin="0in"
+          title="Avery 5160"
+          author="Avery 5160"
+          allowSplitting="0"
+          showBoundary="0"
+          >
+          <!-- showBoundary means that we will be able to see the            -->
+          <!-- limits of frames                                              -->
+    <pageTemplate id="main">
+        <pageGraphics>
+        </pageGraphics>
+        <frame id="label01" x1="0.25in" y1="9.30in" width="2.50in" height="1.00in"/>
+        <frame id="label02" x1="0.25in" y1="8.30in" width="2.50in" height="1.00in"/>
+        <frame id="label03" x1="0.25in" y1="7.30in" width="2.50in" height="1.00in"/>
+        <frame id="label04" x1="0.25in" y1="6.30in" width="2.50in" height="1.00in"/>
+        <frame id="label05" x1="0.25in" y1="5.30in" width="2.50in" height="1.00in"/>
+        <frame id="label06" x1="0.25in" y1="4.30in" width="2.50in" height="1.00in"/>
+        <frame id="label07" x1="0.25in" y1="3.30in" width="2.50in" height="1.00in"/>
+        <frame id="label08" x1="0.25in" y1="2.30in" width="2.50in" height="1.00in"/>
+        <frame id="label09" x1="0.25in" y1="1.30in" width="2.50in" height="1.00in"/>
+        <frame id="label10" x1="0.25in" y1="0.30in" width="2.50in" height="1.00in"/>
+        <frame id="label11" x1="3.00in" y1="9.30in" width="2.50in" height="1.00in"/>
+        <frame id="label12" x1="3.00in" y1="8.30in" width="2.50in" height="1.00in"/>
+        <frame id="label13" x1="3.00in" y1="7.30in" width="2.50in" height="1.00in"/>
+        <frame id="label14" x1="3.00in" y1="6.30in" width="2.50in" height="1.00in"/>
+        <frame id="label15" x1="3.00in" y1="5.30in" width="2.50in" height="1.00in"/>
+        <frame id="label16" x1="3.00in" y1="4.30in" width="2.50in" height="1.00in"/>
+        <frame id="label17" x1="3.00in" y1="3.30in" width="2.50in" height="1.00in"/>
+        <frame id="label18" x1="3.00in" y1="2.30in" width="2.50in" height="1.00in"/>
+        <frame id="label19" x1="3.00in" y1="1.30in" width="2.50in" height="1.00in"/>
+        <frame id="label20" x1="3.00in" y1="0.30in" width="2.50in" height="1.00in"/>
+        <frame id="label21" x1="5.75in" y1="9.30in" width="2.50in" height="1.00in"/>
+        <frame id="label22" x1="5.75in" y1="8.30in" width="2.50in" height="1.00in"/>
+        <frame id="label23" x1="5.75in" y1="7.30in" width="2.50in" height="1.00in"/>
+        <frame id="label24" x1="5.75in" y1="6.30in" width="2.50in" height="1.00in"/>
+        <frame id="label25" x1="5.75in" y1="5.30in" width="2.50in" height="1.00in"/>
+        <frame id="label26" x1="5.75in" y1="4.30in" width="2.50in" height="1.00in"/>
+        <frame id="label27" x1="5.75in" y1="3.30in" width="2.50in" height="1.00in"/>
+        <frame id="label28" x1="5.75in" y1="2.30in" width="2.50in" height="1.00in"/>
+        <frame id="label29" x1="5.75in" y1="1.30in" width="2.50in" height="1.00in"/>
+        <frame id="label30" x1="5.75in" y1="0.30in" width="2.50in" height="1.00in"/>
+    </pageTemplate>
+</template>
+<stylesheet>
+    <paraStyle name="name"
+      fontName="Helvetica"
+      fontSize="9"
+      alignment="CENTER"
+    />
+    <paraStyle name="address"
+      fontName="Helvetica"
+      fontSize="9"
+      alignment="CENTER"
+    />
+</stylesheet>
+}
+	    }
+	}
+    }
+
+}
+
+ad_proc -public -callback contact::envelope -impl envelope10 {
+    {-request:required}
+    {-for ""}
+} {
+} {
+    switch $request {
+	ad_form_option {
+	    return [list "Envelope \#10 (9.5in x 4.125in)" envelope10]
+	}
+	template {
+	    if { $for == "envelope10" } {
+		return {
+<template pageSize="(9.5in, 4.125in)"
+          leftMargin="0in"
+          rightMargin="0in"
+          topMargin="0in"
+          bottomMargin="0in"
+          title="Envelope \#10"
+          author="$author"
+          allowSplitting="0"
+          showBoundary="0"
+          >
+          <!-- showBoundary means that we will be able to see the            -->
+          <!-- limits of frames                                              -->
+    <pageTemplate id="main">
+        <pageGraphics>
+        </pageGraphics>
+        <frame id="label01" x1="5.5in" y1=".5in" width="3in" height="1.5in"/>
+    </pageTemplate>
+</template>
+<stylesheet>
+    <paraStyle name="name"
+      fontName="Helvetica"
+      fontSize="12"
+      leading="15"
+      alignment="LEFT"
+    />
+    <paraStyle name="address"
+      fontName="Helvetica"
+      fontSize="12"
+      leading="15"
+      alignment="LEFT"
+    />
+</stylesheet>
+}
+	    }
+	}
+    }
+
+}
Index: openacs-4/packages/contacts/tcl/contacts-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/tcl/contacts-procs.tcl,v
diff -u -r1.59 -r1.60
--- openacs-4/packages/contacts/tcl/contacts-procs.tcl	15 Feb 2006 10:06:36 -0000	1.59
+++ openacs-4/packages/contacts/tcl/contacts-procs.tcl	20 Feb 2006 09:13:58 -0000	1.60
@@ -143,7 +143,7 @@
     return $contact_list
 }
 
- ad_proc -public contact::util::get_employees_list_of_lists {
+ad_proc -public contact::util::get_employees_list_of_lists {
     {-organization_id:required}
 } {
     get employees of an organization in a list of list suitable for inclusion in options
@@ -170,6 +170,16 @@
 } {
     Get employers of an employee
 
+    @return List of lists, each containing the ID and name of an employer, or an empty list if no employers exist.
+} {
+    return [util_memoize [list contact::util::get_employers_not_cached -employee_id $employee_id]]
+}
+
+ad_proc -private contact::util::get_employers_not_cached {
+    {-employee_id:required}
+} {
+    Get employers of an employee
+
     @author Al-Faisal El-Dajani (faisal.dajani@gmail.com)
     @param employee_id The ID of the employee whom you want to know his/her employer
     @creation-date 2005-10-17
@@ -192,6 +202,7 @@
     return $contact_list
 }
 
+
 ad_proc -public contact::salutation {
     {-party_id:required}
     {-type salutation}
@@ -305,7 +316,7 @@
     @param organization_id ID of the organization whose information should be returned <I> if </I> the employee_id is an employee at this organization. If not specified, defaults to first employer relationship found, if any.
 
 } {
-    ns_log notice "start processing"
+    # ons_log notice "start processing"
     set employer_exist_p 0
     set employee_attributes [list "first_names" "last_name" "person_title" "directphoneno" "directfaxno" "email" "jobtitle" "person_title"]
     set employer_attributes [list "name" "company_phone" "company_fax" "email" "company_name_ext"]
@@ -455,6 +466,8 @@
 } {
     util_memoize_flush "::contact::email_address_exists_p_not_cached -party_id $party_id"
     util_memoize_flush "::contact::mailing_address_exists_p_not_cached -party_id $party_id"
+    util_memoize_flush "::contact::mailing_address_not_cached -party_id $party_id -format html"
+    util_memoize_flush "::contact::mailing_address_not_cached -party_id $party_id -format text"
     util_memoize_flush "::contact::name_not_cached -party_id $party_id"
     util_memoize_flush "::contact::email_not_cached -party_id $party_id"
     util_memoize_flush_regexp "::contact::employee::get_not_cached -employee_id $party_id *"
@@ -509,34 +522,23 @@
 } {
     this returns the contact's name
 } {
-    set email [db_string get_party_email { select email from parties where party_id = :party_id } -default {}]
+    # we should use party::email here but 
+    # we need to wait for the new version of
+    # acs-subsite to be release to remove
+    # the dependence on contacts which
+    # would cause an infinit loop
+    set email [cc_email_from_party $party_id]
     if { ![exists_and_not_null email] } {
-	# we check if these is an ams_attribute_valued email address for this party
-	set attribute_id [contact::email_attribute_id]
+	# we check if there is an ams_attribute_valued email address for this party
+	set attribute_id [attribute::id -object_type "party" -attribute_name "email"]
 	set revision_id [contact::live_revision -party_id $party_id]
 	if { [exists_and_not_null revision_id] } {
-	    set email [db_string get_email { select ams_attribute_value__value(:attribute_id,value_id) from ams_attribute_values where object_id = :revision_id and attribute_id = :attribute_id } -default {}]
-	    set email [ams::widget -widget email -request value_text -value $email]
+	    set email [ams::value -object_id $revision_id -attribute_id $attribute_id]
 	}
     }
     return $email
 }
 
-ad_proc -private contact::email_attribute_id {
-} {
-    this returns the email attributes attribute_id. cached
-} {
-    return [util_memoize [list ::contact::email_attribute_id]]
-}
-
-ad_proc -private contact::email_attribute_id {
-} {
-    this returns the email attributes attribute_id
-} {
-    return [db_string get_email_attribute_id { select attribute_id from acs_attributes where object_type = 'party' and attribute_name = 'email'}]
-}
-
-
 ad_proc -public contact::link {
     {-party_id:required}
 } {
@@ -562,15 +564,6 @@
     } else {
 	return ""
     }
-#    if {[contact::user_p -party_id $party_id]} {
-#        return "user"
-#    } elseif {[person::person_p -party_id $party_id]} {
-#	return "person"
-#    } elseif {[organization::organization_p -party_id $party_id]} {
-#	return "organization"
-#    } else {
-#	return ""
-#    }
 }
 
 ad_proc -public contact::exists_p {
@@ -585,40 +578,20 @@
     } else {
 	return 0
     }
-#    if {[person::person_p -party_id $party_id]} {
-#	return 1
-#    } elseif {[organization::organization_p -party_id $party_id]} {
-#	return 1
-#    } else {
-#	return 0
-#    }
 }
 
 ad_proc -public contact::user_p {
     {-party_id:required}
 } {
     is this party a user? Cached
 } {
-#    return [util_memoize [list ::contact::user_p_not_cached -party_id $party_id]]
     if { [contact::type -party_id $party_id] == "user" } {
 	return 1
     } else {
 	return 0
     }
 }
 
-#ad_proc -public contact::user_p_not_cached {
-#    {-party_id:required}
-#} {
-#    is this party a person? Cached
-#} {
-#    if {[db_0or1row contact_user_exists_p {select '1' from users where user_id = :party_id}]} {
-#	return 1
-#    } else {
-#	return 0
-#    }
-#}
-
 ad_proc -public contact::require_visiblity {
     {-party_id:required}
     {-package_id ""}
@@ -712,6 +685,7 @@
     set username [contact::email -party_id $person_id]
     set authority_id [auth::authority::local]
 
+
     # Make sure that we do not upgrade an already existing user
     if {![contact::user_p -party_id $person_id]} {
 	db_transaction {
Index: openacs-4/packages/contacts/www/message.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/contacts/www/message.tcl,v
diff -u -r1.26 -r1.27
--- openacs-4/packages/contacts/www/message.tcl	16 Feb 2006 14:07:37 -0000	1.26
+++ openacs-4/packages/contacts/www/message.tcl	20 Feb 2006 09:13:58 -0000	1.27
@@ -24,7 +24,7 @@
     {context_id:integer ""}
 } -validate {
     valid_message_type -requires {message_type} {
-	if { [lsearch [list oo_mailing email letter label] $message_type] < 0 } {
+	if { ![db_0or1row check_for_it { select 1 from contact_message_types where message_type = :message_type and message_type not in ('header','footer') }] } {
 	    ad_complain "[_ contacts.lt_Your_provided_an_inva]"
 	}
     }
@@ -80,7 +80,7 @@
     set contact_link   [lindex $recipient 2]
     set email_p        [lindex $recipient 3]
     set letter_p       [lindex $recipient 4]
-    if { $message_type == "letter" || $message_type == "label" } {
+    if { [lsearch [list "letter" "label" "envelope"] $message_type] >= 0 } {
         if { $letter_p } {
             lappend party_ids $party_id
             lappend recipients $contact_link
@@ -205,7 +205,7 @@
     set message_options [list]
     foreach op $message_type_options {
 	set message_type [lindex $op 1]
-	if {$message_type == "letter" || $message_type == "email" || $message_type == "label" } {
+	if { [lsearch [list "header" "footer"] $message_type] < 0 } {
 	    lappend message_options [list "-- [_ contacts.New] [lindex $op 0] --" $message_type]
 	} else {
 	    set ${message_type}_options [list [list [_ contacts.--none--] ""]]