Hello, I am new to drupal and php. I am looking for guidance on what to do with this patch I just made.

I have created a patch against contact-6.x-2.x-dev with the following changes:
-- Permissions for access to a user's personal contact form are now exposed. This allows exposing the personal contact form to anonymous users or restricting access to specific roles.
-- When an authenticated user views a user's personal contact form, the 'name' and 'from' fields are now exposed to allow the authenticated user to use a different name' and email address than what is associated with their account. The defaullt value for the 'name' field is the authenticated user's name and the default value for the 'from' field is the authenticated user's email address. Their profile url is still sent to the recipient.
-- When an anonymous user views a user's personal contact form, they are presented with a blank 'name' and a blank 'from' field. The sent email indicates that the message is from a guest account.
-- When a copy of a message is requested, it is sent with a notice at the top saying "The following is a copy of your message", the rest of the body is verbatim the same as the message sent to the recipient.

Most of this code is based on conventions used in the site wide contact form.

What's my next step? Should this become part of the core contact module? Am I supposed to open an issue?

I'm appending the patches as plain text below.

contact_pages_inc_personal_contact_permissions.patch

--- ./modules/contact/contact.pages.inc	2010-02-14 21:25:50.018436152 -0800
+++ ./modules/contact/contact.pages.inc.new	2010-02-14 21:28:00.998420188 -0800
@@ -157,10 +157,7 @@ function contact_mail_page_submit($form,
 function contact_user_page($account) {
   global $user;
 
-  if (!valid_email_address($user->mail)) {
-    $output = t('You need to provide a valid e-mail address to contact other users. Please update your <a href="@url">user information</a> and try again.', array('@url' => url("user/$user->uid/edit")));
-  }
-  else if (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 3))) {
+  if (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 3))) {
     $output = t('You cannot contact more than %number users per hour. Please try again later.', array('%number' => variable_get('contact_hourly_threshold', 3)));
   }
   else {
@@ -173,16 +170,25 @@ function contact_user_page($account) {
 
 function contact_mail_user(&$form_state, $recipient) {
   global $user;
-  $form['#token'] = $user->name . $user->mail;
+  
+  $form['#token'] = $user->uid ? $user->name . $user->mail : '';
   $form['recipient'] = array('#type' => 'value', '#value' => $recipient);
-  $form['from'] = array('#type' => 'item',
-    '#title' => t('From'),
-    '#value' => theme('username', $user) .' &lt;'. check_plain($user->mail) .'&gt;',
-  );
   $form['to'] = array('#type' => 'item',
     '#title' => t('To'),
     '#value' => theme('username', $recipient),
   );
+  $form['name'] = array('#type' => 'textfield',
+    '#title' => t('Your name'),
+    '#maxlength' => 255,
+    '#default_value' => $user->uid ? $user->name : '',
+    '#required' => TRUE,
+  );
+  $form['from'] = array('#type' => 'textfield',
+    '#title' => t('Your e-mail address'),
+    '#maxlength' => 255,
+    '#default_value' => $user->uid ? $user->mail : '',
+    '#required' => TRUE,
+  );
   $form['subject'] = array('#type' => 'textfield',
     '#title' => t('Subject'),
     '#maxlength' => 50,
@@ -203,6 +209,15 @@ function contact_mail_user(&$form_state,
 }
 
 /**
+ * Validate the personal contact page form submission.
+ */
+function contact_mail_user_validate($form, &$form_state) {
+  if (!valid_email_address($form_state['values']['from'])) {
+    form_set_error('mail', t('You must enter a valid e-mail address.'));
+  }
+}
+
+/**
  * Process the personal contact page form submission.
  */
 function contact_mail_user_submit($form, &$form_state) {
@@ -212,7 +227,7 @@ function contact_mail_user_submit($form,
 
   // Send from the current user to the requested user.
   $to = $account->mail;
-  $from = $user->mail;
+  $from = $form_state['values']['from'];
 
   // Save both users and all form values for email composition.
   $values = $form_state['values'];

contact_module_personal_contact_permissions.patch

--- ./modules/contact/contact.module	2010-02-14 21:25:50.018436152 -0800
+++ ./modules/contact/contact.module.new	2010-02-14 21:27:39.165677807 -0800
@@ -36,7 +36,7 @@ function contact_help($path, $arg) {
  * Implementation of hook_perm
  */
 function contact_perm() {
-  return array('access site-wide contact form', 'administer site-wide contact form');
+  return array('access site-wide contact form', 'administer site-wide contact form', 'access user contact forms');
 }
 /**
  * Implementation of hook_menu().
@@ -122,7 +122,7 @@ function _contact_user_tab_access($accou
   global $user;
 
   // Anonymous users cannot use or have contact forms.
-  if (!$user->uid || !$account->uid) {
+  if (!user_access('access user contact forms')) {
     return FALSE;
   }
 
@@ -186,8 +186,9 @@ function contact_user($type, &$edit, &$u
 function contact_mail($key, &$message, $params) {
   $language = $message['language'];
   switch ($key) {
-    case 'page_mail':
     case 'page_copy':
+      $message['body'][] = t("The following is a copy of your message.");
+    case 'page_mail':
       $contact = $params['contact'];
       $message['subject'] .= t('[!category] !subject', array('!category' => $contact['category'], '!subject' => $params['subject']), $language->language);
       $message['body'][] = t("!name sent a message using the contact form at !form.", array('!name' => $params['name'], '!form' => url($_GET['q'], array('absolute' => TRUE, 'language' => $language))), $language->language);
@@ -198,13 +199,14 @@ function contact_mail($key, &$message, $
       $message['subject'] .= t('[!category] !subject', array('!category' => $contact['category'], '!subject' => $params['subject']), $language->language);
       $message['body'][] = $contact['reply'];
       break;
-    case 'user_mail':
     case 'user_copy':
+      $message['body'][] = t("The following is a copy of your message.");
+    case 'user_mail':
       $user = $params['user'];
       $account = $params['account'];
       $message['subject'] .= '['. variable_get('site_name', 'Drupal') .'] '. $params['subject'];
       $message['body'][] = "$account->name,";
-      $message['body'][] = t("!name (!name-url) has sent you a message via your contact form (!form-url) at !site.", array('!name' => $user->name, '!name-url' => url("user/$user->uid", array('absolute' => TRUE, 'language' => $language)), '!form-url' => url($_GET['q'], array('absolute' => TRUE, 'language' => $language)), '!site' => variable_get('site_name', 'Drupal')), $language->language);
+      $message['body'][] = t("!name (!name-url) has sent you a message via your contact form (!form-url) at !site.", array('!name' => $params['name'], '!name-url' => $user->uid ? url("user/$user->uid", array('absolute' => TRUE, 'language' => $language)) : "guest account", '!form-url' => url($_GET['q'], array('absolute' => TRUE, 'language' => $language)), '!site' => variable_get('site_name', 'Drupal')), $language->language);
       $message['body'][] = t("If you don't want to receive such e-mails, you can change your settings at !url.", array('!url' => url("user/$account->uid", array('absolute' => TRUE, 'language' => $language))), $language->language);
       $message['body'][] = t('Message:', NULL, $language->language);
       $message['body'][] = $params['message'];

Comments

antelrope’s picture

My to do list includes the following items:
-- Add configuration option to redirect to a specific url after a message is sent succesfully.
-- Add an option to allow or dissallow an authenticated user, who is accessing the contact form of another authenticated user, the option of changing their name/email address. The options being 'can change both', 'can change neither', 'can change name only', or 'can change email only'. This is to address isssue;
Don't allow registered users to change their name or e-mail in contact forms > http://drupal.org/node/601776
-- Change the formatting of all copy messages to only include information sent by the sender. Already my patch has the functionality of keeping the recipients email address hidden from the sender.
-- Add a permissions options for allowing a user to send themselves a copy of a message sent via the personal contact form as well as a seperate permission for the site wide contact form. This will enable restricting an anonymous user or a user of any arbitrary role from sending themselves a copy.

I'm hoping to get some or all of this code into core eventually, if not, it will need to become it's own module, I think. Perhaps a veteran drupal coder can clarify what the best approach is.

andrewfn’s picture

This issue was first opened in 2006 (for Drupal 4.7!) : http://drupal.org/node/58224
It was finally fixed for Drupal 7: http://drupal.org/node/601250
And a project has been started to backport the fix to Drupal 6 using a separate module: http://drupal.org/project/contact/
I may be mistaken, but it looks like these are duplicates of what you are doing, and it might be better for you to join forces with them.