Index: modules/contact/contact.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/contact/contact.admin.inc,v
retrieving revision 1.20
diff -u -r1.20 contact.admin.inc
--- modules/contact/contact.admin.inc	3 Jan 2010 21:01:04 -0000	1.20
+++ modules/contact/contact.admin.inc	31 Jan 2010 16:10:16 -0000
@@ -112,6 +112,18 @@
 function contact_category_edit_form_validate($form, &$form_state) {
   // Validate and each e-mail recipient.
   $recipients = explode(',', $form_state['values']['recipients']);
+  
+  // When creating a new contact form, or renaming the category on an existing
+  // contact form, make sure that the given category is unique.
+  $category = $form_state['values']['category'];
+  $query = db_select('contact', 'c')->condition('c.category', $category, '=');
+  if (!empty($form_state['values']['cid'])) {
+    $query->condition('c.cid', $form_state['values']['cid'], '<>');
+  }
+  if ($query->countQuery()->execute()->fetchField()) {
+    form_set_error('category', t('A contact form with category \'@category\' already exists.', array('@category' => $category)));
+  }
+  
   foreach ($recipients as &$recipient) {
     $recipient = trim($recipient);
     if (!valid_email_address($recipient)) {
Index: modules/contact/contact.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/contact/contact.test,v
retrieving revision 1.40
diff -u -r1.40 contact.test
--- modules/contact/contact.test	9 Jan 2010 23:03:21 -0000	1.40
+++ modules/contact/contact.test	31 Jan 2010 16:10:17 -0000
@@ -93,6 +93,11 @@
 
     $this->addCategory($category = $this->randomName(16), implode(',', array($recipients[0], $recipients[1], $recipients[2])), '', FALSE);
     $this->assertRaw(t('Category %category has been saved.', array('%category' => $category)), t('Category successfully saved.'));
+    
+    // Try adding a category that already exists.
+    $this->addCategory($category, implode(',', array($recipients[0], $recipients[1], $recipients[2])), '', FALSE);
+    $this->assertNoRaw(t('Category %category has been saved.', array('%category' => $category)), t('Category not saved.'));
+    $this->assertRaw(t('A contact form with category %category already exists.', array('%category' => $category)), t('Duplicate category error found.'));    
 
     // Clear flood table in preparation for flood test and allow other checks to complete.
     db_delete('flood')->execute();
