diff --git a/dropbox.info b/dropbox.info
index c3bffd5..c7d9a21 100755
--- a/dropbox.info
+++ b/dropbox.info
@@ -1,5 +1,8 @@
 ; $Id: dropbox.info,v 1.4 2009-08-02 01:11:58 deviantintegral Exp $
 name = Dropbox Integration
 description = Allows users have files sent to their Dropbox account.
-core=6.x
-dependencies[] = securepages
+core=7.x
+files[] = dropbox.module
+files[] = dropbox.install
+files[] = dropbox.pages.inc
+
diff --git a/dropbox.install b/dropbox.install
index 587b7c1..9beffa2 100755
--- a/dropbox.install
+++ b/dropbox.install
@@ -7,30 +7,9 @@
  */
 
 /**
- * Implementation of hook_install().
- */
-function dropbox_install() {
-  $ret = array();
-  $results = drupal_install_schema('dropbox');
-  $install_pass = TRUE;
-  foreach ($results as $result) {
-    if (!$result['success']) {
-      $install_pass = FALSE;
-    }
-  }
-  if ($install_pass) {
-    drupal_set_message(st('Installed the Dropbox module successfully!'));
-  }
-  else {
-    drupal_set_message(st('The installation of the Dropbox module was unsuccessful.'), 'error');
-  }
-}
-
-/**
  * Implementation of hook_uninstall().
  */
 function dropbox_uninstall() {
-  drupal_uninstall_schema('dropbox');
   db_query("DELETE FROM {variable} WHERE name LIKE 'dropbox_%'");
 }
 
@@ -43,7 +22,7 @@ function dropbox_uninstall() {
 function dropbox_schema() {
   $schema = array();
   $schema['dropbox_user'] = array(
-    'description' => t('Stores Dropbox settings for users.'),
+    'description' => 'Stores Dropbox settings for users.',
     'fields' => array(
       'uid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE),
       'mail' => array('type' => 'varchar', 'length' => 64, 'not null' => FALSE, 'default' => '', 'description' => "User's email address associated with Dropbox."),
@@ -97,7 +76,7 @@ function _dropbox_requirements_runtime() {
   }
   // Ensure that SSL is available. We can't be sure in this test, so only set a
   // warning.
-  if (!securepages_test()) {
+  if (FALSE) {
     $requirements['ssl']['description'] = t('SSL does not appear to be available for this address. For users to configure Dropbox integration, they must provide a private Host ID. Anyone with posession of this key can access the associated Dropbox account. SSL must be enabled for this domain, or you must access this site with another address which does have SSL enabled to allow users to configure Dropbox integration.');
     $requirements['ssl']['value'] = t('Not available');
     $requirements['ssl']['severity'] = REQUIREMENT_WARNING;
@@ -124,3 +103,4 @@ function dropbox_update_6001() {
   drupal_set_message(t("Dropbox no longer supports using a host_id to access an account. All users with Dropbox integration enabled will have to edit their accounts to enter their account name and password."));
   return $ret;
 }
+
diff --git a/dropbox.module b/dropbox.module
index fa704dc..fccd005 100755
--- a/dropbox.module
+++ b/dropbox.module
@@ -16,6 +16,7 @@ function dropbox_menu() {
     'access arguments' => array(1),
     'page callback' => '_dropbox_send_form',
     'page arguments' => array(1),
+    'file' => 'dropbox.pages.inc',
   );
   return $items;
 }
@@ -27,6 +28,9 @@ function dropbox_menu() {
  * flood control they don't get the old form.
  */
 function dropbox_boot() {
+  if (!isset($_REQUEST['q'])) {
+    return;
+  }
   $arg = explode('/', $_REQUEST['q']);
   if ($arg[0] == 'user' && isset($arg[1]) && is_numeric($arg[1]) && isset($arg[2]) && $arg[2] == 'dropbox') {
     $GLOBALS['conf']['cache'] = FALSE;
@@ -34,7 +38,7 @@ function dropbox_boot() {
 }
 
 /**
- * Implementation of hook_perm().
+ * Implementation of hook_permission().
  *
  * The following permissions are currently defined:
  * - Configure Dropbox Account allows users to access Dropbox functionality
@@ -45,297 +49,154 @@ function dropbox_boot() {
  * @return
  *   Array of permissions available.
  */
-function dropbox_perm() {
+function dropbox_permission() {
   return array(
-    'Configure Dropbox account',
-    'Send files to users via Dropbox',
+    'Configure Dropbox account' => array(
+      'title' => t('Configure Dropbox account'),
+      'description' => t('Enable Dropbox integration for their user account.'),
+    ),
+    'Send files to users via Dropbox' => array(
+      'title' => t('Send files to user via Dropbox'),
+      'description' => t('Send files to users who have configured their Dropbox account.'),
+    ),
   );
 }
 
 /**
- * Implementation of hook_user().
+ * Implementation of hook_user_load().
  */
-function dropbox_user($op, &$edit, &$account, $category = NULL) {
-  switch ($op) {
-    case 'register':
-      $roles = user_roles(TRUE, 'Configure Dropbox account');
-      // If authenticated users are allowed to use Dropbox, allow them to set
-      // it up on the registration form.
-      if (array_key_exists(1, $roles)) {
-        return dropbox_settings_form($edit);
-      }
-    case 'form':
-      if (user_access('Configure Dropbox account') && $category == 'account') {
-        return dropbox_settings_form($edit);
-      }
-      break;
-    case 'load':
-      $dropbox_data = db_fetch_object(db_query("SELECT mail, pass, flood, roles FROM {dropbox_user} WHERE uid = %d", $account->uid));
-      if (!empty($dropbox_data)) {
-        $dropbox_data->roles = unserialize($dropbox_data->roles);
-        $account->dropbox = $dropbox_data;
-      }
-      else {
-        unset($account->dropbox);
-      }
-      break;
-    case 'validate':
-      if (!empty($edit['dropbox']['mail']) && !valid_email_address($edit['dropbox']['mail'])) {
-        form_set_error('dropbox][mail', t('Please enter a valid email address for your Dropbox account. Leave blank to remove your account information.'));
+function dropbox_user_load($users) {
+  foreach ($users as $account) {
+    $dropbox_data = db_query("SELECT mail, pass, flood, roles FROM {dropbox_user} WHERE uid = :uid", array(':uid' => $account->uid), array('fetch' => PDO::FETCH_OBJ));
+    if (count($dropbox_data) > 0) {
+      foreach($dropbox_data as $data) {
+        $data->roles = unserialize($data->roles);
+        $account->dropbox = $data;
       }
-      // Only require a password to be set if it hasn't ever been entered.
-      if (!empty($edit['dropbox']['mail']) && empty($edit['dropbox']['pass']) && empty($account->dropbox->pass)) {
-        form_set_error('dropbox][pass', t('Please enter your Dropbox account password to enable Dropbox integration.'));
-      }
-      if (!empty($edit['dropbox']['flood']) && !is_numeric($edit['dropbox']['flood'])) {
-        form_set_error('dropbox][flood', t('Please specify the number of files an anonymous user can send per hour as a number.'));
-      }
-      elseif (empty($edit['dropbox']['flood'])) {
-        $edit['dropbox']['flood'] = variable_get('dropbox_flood_anonymous', 3);
-      }
-      if (empty($edit['dropbox']['mail'])) {
-        $enabled_roles = array_filter((empty($edit['dropbox']['roles']) ? array() : $edit['dropbox']['roles']));
-        if (!empty($enabled_roles)) {
-          form_set_error('dropbox][mail', t('You must specify a Dropbox account email address to enable roles to send you files.'));
-        }
-      }
-      break;
-    case 'insert':
-      if (!empty($edit['dropbox']['mail'])) {
-        $roles = empty($edit['dropbox']['roles']) ? array() : $edit['dropbox']['roles'];
-        db_query("INSERT INTO {dropbox_user} (uid, mail, pass, flood, roles) VALUES (%d, '%s', '%s', %d, '%s')", $account->uid, $edit['dropbox']['mail'], $edit['dropbox']['pass'], (int)$edit['dropbox']['flood'], serialize(array_filter($roles)));
-        $edit['dropbox']['mail'] = NULL;
-        $edit['dropbox']['pass'] = NULL;
-        $edit['dropbox']['flood'] = NULL;
-        $edit['dropbox']['roles'] = NULL;
-        $edit['dropbox'] = NULL;
-      }
-      break;
-    case 'update':
-      if (isset($edit['dropbox']['mail'])) {
-        $roles = empty($edit['dropbox']['roles']) ? array() : $edit['dropbox']['roles'];
-        if (empty($edit['dropbox']['pass'])) {
-          db_query("UPDATE {dropbox_user} SET mail = '%s', flood = %d, roles = '%s' WHERE uid = %d", $edit['dropbox']['mail'], $edit['dropbox']['flood'], serialize(array_filter($roles)), $account->uid);
-        }
-        else {
-          db_query("DELETE FROM {dropbox_user} WHERE uid = %d", $account->uid);
-          db_query("INSERT INTO {dropbox_user} (uid, mail, pass, flood, roles) VALUES (%d, '%s', '%s', %d, '%s')", $account->uid, $edit['dropbox']['mail'], $edit['dropbox']['pass'], $edit['dropbox']['flood'], serialize(array_filter($roles)));
-        }
-      }
-      $edit['dropbox']['mail'] = NULL;
-      $edit['dropbox']['pass'] = NULL;
-      $edit['dropbox']['flood'] = NULL;
-      $edit['dropbox']['roles'] = NULL;
-      $edit['dropbox'] = NULL;
-      break;
-    case 'delete':
-      db_query("DELETE FROM {dropbox_user} WHERE uid = %d", $account->uid);
-      break;
-  }
-}
-
-/**
- * Return a form containing a user's Dropbox account settings.
- *
- * @param $edit
- *   The $edit array from hook_user() containing the current state of the user.
- *
- * @return
- *   A Form API array containing the available Dropbox settings.
- */
-function dropbox_settings_form(&$edit) {
-  $form = array();
-  $form['dropbox'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Dropbox Account Settings'),
-    '#collapsible' => TRUE,
-    '#tree' => TRUE,
-  );
-  if (variable_get('dropbox_allow_insecure', FALSE)  || (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')) {
-    $form['dropbox']['mail'] = array(
-      '#type' => 'textfield',
-      '#title' => t('Dropbox Account Email Address'),
-      '#maxlength' => 64,
-      '#default_value' => isset($edit['dropbox']->mail) ? $edit['dropbox']->mail : '',
-      '#description' => t('Enter the email address associated with your Dropbox account.'),
-    );
-    $form['dropbox']['pass'] = array(
-      '#type' => 'password',
-      '#title' => t('Dropbox Account Password'),
-      '#maxlength' => 64,
-      '#description' => t('Enter your Dropbox account password. Your password will be stored as it is required to access your account.'),
-    );
-  }
-  else {
-    $no_ssl = t('You must connect over an SSL connection to view or change your Dropbox account settings.');
-    if (securepages_test()) {
-      $path = !empty($_REQUEST['q']) ? $_REQUEST['q'] : '';
-      $secure_version = securepages_url($path, array('secure' => TRUE));
-      $no_ssl .= ' ' . t('Try <a href="@secure">connecting securely</a> to view these settings.', array('@secure' => $secure_version));
     }
     else {
-      $no_ssl .= ' ' . t('This web server does not appear to support SSL. Please enable SSL to allow Dropbox integration.');
-    }
-    $form['dropbox']['no_ssl'] = array(
-      '#prefix' => '<p>',
-      '#suffix' => '</p>',
-      '#value' => $no_ssl,
-    );
-    return $form;
-  }
-  $roles = user_roles(FALSE, 'Send files to users via Dropbox');
-  if (!empty($roles)) {
-    $form['dropbox']['roles'] = array(
-      '#type' => 'checkboxes',
-      '#title' => t('Site roles which can send you files'),
-      '#options' => $roles,
-      '#description' => t('Check off the roles that you wish to allow to send you files. Leave all roles unchecked to only allow site administrators to send you files.'),
-    );
-    if (!empty($edit['dropbox']->roles)) {
-      $form['dropbox']['roles']['#default_value'] = $edit['dropbox']->roles;
+      unset($account->dropbox);
     }
-    $form['dropbox']['flood'] = array(
-      '#type' => 'textfield',
-      '#title' => t('Maximum number of files an anonymous user can send per hour'),
-      '#default_value' => isset($edit['dropbox']->flood) ? $edit['dropbox']->flood : '',
-      '#maxlength' => 2,
-      '#size' => 2,
-      '#description' => t('Enter the maximum number of files an anonymous user can send per hour. This helps to limit spam and other annoyances, and only applies if you allow anonymous users to send you files. Leave blank to use the site defaults.'),
-    );
-  }
-  else {
-    $form['dropbox']['access_disabled'] = array(
-      '#prefix' => '<p>',
-      '#suffix' => '</p>',
-      '#value' => t('No roles are currently allowed to send files via Dropbox. No users will be able to send files until at least one role is enabled by the site administrator.'),
-    );
   }
-  return $form;
 }
 
 /**
- * Private function to set the page title on the Send file tab.
- *
- * @param $user
- *   The user who's form is being displayed.
- *
- * @return
- *   The FAPI form array.
+ * Implementation of hook_user_insert().
  */
-function _dropbox_send_form($user) {
-  drupal_set_title(t('Send %user a file', array('%user' => $user->name)));
-  return drupal_get_form('dropbox_send_form', $user);
+function dropbox_user_insert(&$edit, $account, $category) {
+  if (!empty($edit['dropbox']['mail'])) {
+    $roles = empty($edit['dropbox']['roles']) ? array() : $edit['dropbox']['roles'];
+
+    $query = db_insert('dropbox_user')
+      ->fields(array(
+        'uid' => $account->uid,
+        'mail' => $edit['dropbox']['mail'],
+        'pass' => $edit['dropbox']['pass'],
+        'flood' => (int)$edit['dropbox']['flood'],
+        'roles' => serialize(array_filter($roles)),
+      ))
+      ->execute();
+
+    $edit['dropbox']['mail'] = NULL;
+    $edit['dropbox']['pass'] = NULL;
+    $edit['dropbox']['flood'] = NULL;
+    $edit['dropbox']['roles'] = NULL;
+    $edit['dropbox'] = NULL;
+  }
 }
 
 /**
- * Forms API callback to show the "Send file" form.
+ * Implementation of hook_user_update().
  */
-function dropbox_send_form($form_state, $destination_user) {
-  global $user;
-
-  $form = array();
-  if ($user->uid == 0 && !flood_is_allowed('dropbox_send', $destination_user->dropbox->flood)) {
-    $form['access_denied'] = array(
-      '#prefix' => '<p>',
-      '#suffix' => '</p>',
-      '#value' => t('You have sent the maximum number of files allowed within an hour to %user. Please try again later.', array('%user' => $destination_user->name)),
-    );
-    return $form;
-  }
-  $form['#attributes'] = array('enctype' => "multipart/form-data");
-  $form['name'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Name'),
-    '#default_value' => ($user->uid == 0 ? '' : $user->name),
-    '#maxlength' => 32,
-    '#description' => t('%name will receive an email notification about this upload from your name.', array('%name' => $destination_user->name)),
-  );
-  if ($user->uid == 0) {
-    $form['mail'] = array(
-      '#type' => 'textfield',
-      '#title' => t('Email address'),
-    );
+function dropbox_user_update(&$edit, $account, $category) {
+  if (isset($edit['dropbox']['mail']) && !empty($edit['dropbox']['mail'])) {
+    $roles = empty($edit['dropbox']['roles']) ? array() : $edit['dropbox']['roles'];
+    db_merge('dropbox_user')->
+      key(array('uid' => $account->uid))
+      ->fields(array(
+        'mail' => $edit['dropbox']['mail'],
+        'pass' => $edit['dropbox']['pass'],
+        'flood' => (int)$edit['dropbox']['flood'],
+        'roles' => serialize(array_filter($roles)),
+      ))
+      ->execute();
   }
   else {
-    $form['mail'] = array(
-      '#type' => 'value',
-      '#value' => $user->mail,
-    );
+    db_delete('dropbox_user')->
+      condition('uid', $account->uid)
+      ->execute();
   }
-  $form['destination_user'] = array(
-    '#type' => 'value',
-    '#value' => $destination_user,
-  );
-  $form['upload'] = array(
-    '#type' => 'file',
-    '#title' => t('Choose a file to send'),
-    '#description' => t('Choose the file you wish to send. If you have previously sent this file to this user, the recepient will have access to both copies. You may not upload a file larger than %size.', array('%size' => format_size(file_upload_max_size())))
-  );
-  $form['submit'] = array(
-    '#type' => 'submit',
-    '#value' => t('Send file'),
-  );
-  return $form;
+
+  $edit['dropbox']['mail'] = NULL;
+  $edit['dropbox']['pass'] = NULL;
+  $edit['dropbox']['flood'] = NULL;
+  $edit['dropbox']['roles'] = NULL;
+  $edit['dropbox'] = NULL;
 }
 
 /**
- * Validate the dropbox_send_form.
+ * Implementation of hook_user_delete().
  */
-function dropbox_send_form_validate($form, &$form_state) {
-  if (empty($form_state['values']['name'])) {
-    form_set_error('name', t('You must enter a name to send a file.'));
-  }
-  if (!valid_email_address($form_state['values']['mail'])) {
-    form_set_error('mail', t('You must enter a valid email address to send a file.'));
+function dropbox_user_delete($account) {
+  db_delete('dropbox_user')->
+    condition('uid', $account->uid)
+    ->execute();
+}
+
+/**
+ * Implementation of hook_form_alter().
+ */
+function dropbox_form_alter(&$form, &$form_state, $form_id) {
+  switch ($form_id) {
+    case 'user_register_form':
+      $roles = user_roles(TRUE, 'Configure Dropbox account');
+      // If authenticated users are allowed to use Dropbox, allow them to set
+      // it up on the registration form.
+      if (array_key_exists(1, $roles)) {
+        module_load_include('inc', 'dropbox', 'dropbox.pages');
+        dropbox_settings_form($form, (object)$form['#user']);
+      }
+      break;
+    case 'user_profile_form':
+      if (user_access('Configure Dropbox account')) {
+        module_load_include('inc', 'dropbox', 'dropbox.pages');
+        dropbox_settings_form($form, (object)$form['#user']);
+      }
+      break;
   }
 }
 
 /**
- * Submit the dropbox_send_form. This uploads the file to a temporary
- * directory, transfers the file to Dropbox, and sends a notification email
- * to the destination user.
+ * Private function to set the page title on the Send file tab.
  *
- * @param $form
- * @param $form_state
- * @return unknown_type
+ * @param $user
+ *   The user who's form is being displayed.
+ *
+ * @return
+ *   The FAPI form array.
  */
-function dropbox_send_form_submit($form, &$form_state) {
-  global $user;
-  $destination_user = $form_state['values']['destination_user'];
-  $file = file_save_upload('upload', array());
-  if (is_object($file)) {
-    $error = dropbox_file_put($destination_user, $file, '/' . variable_get('site_name', 'Drupal') . '/' . strtr($form_state['values']['mail'], "@", "-"));
-    if (!$error) {
-      $params = array();
-      $params['destination_user'] = $destination_user;
-      $params['name'] = $form_state['values']['name'];
-      $params['mail'] = strtr($form_state['values']['mail'], "@", "-");
-      drupal_mail('dropbox', 'send_notify', $destination_user->name . ' <' . $destination_user->mail . '>', user_preferred_language($destination_user), $params, $form_state['values']['mail']);
-      drupal_set_message(t('%filename has successfully been sent.', array('%filename' => $file->filename)));
-      watchdog('dropbox', "%from sent a file to %to's Dropbox account.", array('%from' => isset($user->name) ? $user->name : $params['name'], '%to' => $destination_user->name));
-      file_delete($file->filepath);
-    }
-    else {
-      form_set_error('upload', t('Failed to upload the file. Dropbox returned the following error: !dropbox-error', array('!dropbox-error' => $error)));
-    }
-  }
-  else {
-    form_set_error('upload', t('Failed to upload the file. Please try again.'));
-  }
+function _dropbox_send_form($user) {
+  drupal_set_title(t('Send %user a file', array('%user' => $user->name)), PASS_THROUGH);
+  return drupal_get_form('dropbox_send_form', $user);
 }
 
 /**
  * Implementation of hook_mail().
  */
 function dropbox_mail($key, &$message, $params) {
-  $language = $message['language'];
-  $variables = user_mail_tokens($params['destination_user'], $language);
-  $variables['!name'] = $params['name'];
-  $variables['!mail'] = $params['mail'];
+  $language = $message['language']->language;
+  $variables = array(
+    '!site-name' => variable_get('site_name', 'Drupal'),
+    '!uri' => $GLOBALS['base_url'],
+    '!source-name' => $params['name'],
+    '!username' => format_username($params['destination_user']),
+    '!mail' => $params['mail'],
+  );
+
   switch ($key) {
     case 'send_notify':
-      $message['subject'] = t('A user has sent you a file to your Dropbox account from !site', $variables, $language->language);
-      $message['body'] = t("Dear !username,\n\n!name has sent you a file. You can find it in your Dropbox account in the !site/!mail folder.\n\n--\n!uri", $variables, $language->language);
+      $message['subject'] = t('A user has sent you a file to your Dropbox account from !site-name', $variables, array('langcode' => $language));
+      $message['body'][] = t("Dear !username,\n\n!source-name has sent you a file. You can find it in your Dropbox account in the !site-name/!mail folder.\n\n--\n!uri", $variables, array('langcode' => $language));
       break;
   }
 
@@ -368,7 +229,7 @@ function dropbox_file_put($account, $file, $path) {
   $dropboxUploader = new DropboxUploader($account->dropbox->mail, $account->dropbox->pass);
   $dropboxUploader->setCaCertificateFile(drupal_get_path('module', 'dropbox') . '/Thawte_Premium_Server_CA.pem');
   try {
-    $dropboxUploader->upload($file->filepath, $path);
+    $dropboxUploader->upload(file_directory_path('temporary') . '/' . $file->filename, $path);
   }
   catch (Exception $e) {
     return $e->getMessage();
@@ -422,3 +283,4 @@ function _dropbox_send_enabled($destination_user) {
   }
   return FALSE;
 }
+
diff --git a/dropbox.pages.inc b/dropbox.pages.inc
new file mode 100644
index 0000000..e2aa5d6
--- /dev/null
+++ b/dropbox.pages.inc
@@ -0,0 +1,202 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Dropbox page callback for the dropbox module.
+ */
+
+/**
+ * Return a form containing a user's Dropbox account settings.
+ *
+ * @param &$form
+ *   The form to add the settings to.
+ *
+ * @param $account
+ *   The account object to create a settings form for.
+ *
+ * @return
+ *   A Form API array containing the available Dropbox settings.
+ */
+function dropbox_settings_form(&$form, $account) {
+  $form['dropbox'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Dropbox Account Settings'),
+    '#collapsible' => TRUE,
+    '#tree' => TRUE,
+  );
+  $form['dropbox']['mail'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Dropbox Account Email Address'),
+    '#maxlength' => 64,
+    '#default_value' => isset($account->dropbox->mail) ? $account->dropbox->mail : '',
+    '#description' => t('Enter the email address associated with your Dropbox account.'),
+  );
+  $form['dropbox']['pass'] = array(
+    '#type' => 'password',
+    '#title' => t('Dropbox Account Password'),
+    '#maxlength' => 64,
+    '#description' => t('Enter your Dropbox account password. Your password will be stored as it is required to access your account.'),
+  );
+  if (!variable_get('dropbox_allow_insecure', FALSE)) {
+    $form['dropbox']['mail']['#https'] = TRUE;
+    $form['dropbox']['pass']['#https'] = TRUE;
+  }
+  else {
+    drupal_set_message(t('You must connect over an SSL connection to view or change your Dropbox account settings.'));
+  }
+  $roles = user_roles(FALSE, 'Send files to users via Dropbox');
+  if (!empty($roles)) {
+    $form['dropbox']['roles'] = array(
+      '#type' => 'checkboxes',
+      '#title' => t('Site roles which can send you files'),
+      '#options' => $roles,
+      '#description' => t('Check off the roles that you wish to allow to send you files. Leave all roles unchecked to only allow site administrators to send you files.'),
+    );
+    if (!empty($account->dropbox->roles)) {
+      $form['dropbox']['roles']['#default_value'] = $account->dropbox->roles;
+    }
+    $form['dropbox']['flood'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Maximum number of files an anonymous user can send per hour'),
+      '#default_value' => isset($account->dropbox->flood) ? $account->dropbox->flood : '',
+      '#maxlength' => 2,
+      '#size' => 2,
+      '#description' => t('Enter the maximum number of files an anonymous user can send per hour. This helps to limit spam and other annoyances, and only applies if you allow anonymous users to send you files. Leave blank to use the site defaults.'),
+    );
+  }
+  else {
+    $form['dropbox']['access_disabled'] = array(
+      '#prefix' => '<p>',
+      '#suffix' => '</p>',
+      '#value' => t('No roles are currently allowed to send files via Dropbox. No users will be able to send files until at least one role is enabled by the site administrator.'),
+    );
+  }
+
+  // Add our validation and handler.
+  $form['#validate'][] = 'dropbox_settings_validate';
+}
+
+/**
+ * Forms API validation callback.
+ */
+function dropbox_settings_validate($form, &$form_state) {
+  $account = $form_state['values'];
+  if (!empty($account['dropbox']['mail']) && !valid_email_address($account['dropbox']['mail'])) {
+    form_set_error('dropbox][mail', t('Please enter a valid email address for your Dropbox account. Leave blank to remove your account information.'));
+  }
+  // Only require a password to be set if it hasn't ever been entered.
+  if (!empty($account['dropbox']['mail']) && empty($account['dropbox']['pass']) && empty($account->dropbox->pass)) {
+    form_set_error('dropbox][pass', t('Please enter your Dropbox account password to enable Dropbox integration.'));
+  }
+  if (!empty($account['dropbox']['flood']) && !is_numeric($account['dropbox']['flood'])) {
+    form_set_error('dropbox][flood', t('Please specify the number of files an anonymous user can send per hour as a number.'));
+  }
+  elseif (empty($account['dropbox']['flood'])) {
+    $account['dropbox']['flood'] = variable_get('dropbox_flood_anonymous', 3);
+  }
+  if (empty($account['dropbox']['mail'])) {
+    $enabled_roles = array_filter((empty($account['dropbox']['roles']) ? array() : $account['dropbox']['roles']));
+    if (!empty($enabled_roles)) {
+      form_set_error('dropbox][mail', t('You must specify a Dropbox account email address to enable roles to send you files.'));
+    }
+  }
+}
+
+/**
+ * Forms API callback to show the "Send file" form.
+ */
+function dropbox_send_form($form, &$form_state, $destination_user) {
+  global $user;
+
+  $form = array();
+  if ($user->uid == 0 && !flood_is_allowed('dropbox_send', $destination_user->dropbox->flood)) {
+    $form['access_denied'] = array(
+      '#prefix' => '<p>',
+      '#suffix' => '</p>',
+      '#value' => t('You have sent the maximum number of files allowed within an hour to %user. Please try again later.', array('%user' => $destination_user->name)),
+    );
+    return $form;
+  }
+  $form['#attributes'] = array('enctype' => "multipart/form-data");
+  $form['name'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Name'),
+    '#default_value' => ($user->uid == 0 ? '' : $user->name),
+    '#maxlength' => 32,
+    '#description' => t('%name will receive an email notification about this upload from your name.', array('%name' => $destination_user->name)),
+  );
+  if ($user->uid == 0) {
+    $form['mail'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Email address'),
+    );
+  }
+  else {
+    $form['mail'] = array(
+      '#type' => 'value',
+      '#value' => $user->mail,
+    );
+  }
+  $form['destination_user'] = array(
+    '#type' => 'value',
+    '#value' => $destination_user,
+  );
+  $form['upload'] = array(
+    '#type' => 'file',
+    '#title' => t('Choose a file to send'),
+    '#description' => t('Choose the file you wish to send. If you have previously sent this file to this user, the recepient will have access to both copies. You may not upload a file larger than %size.', array('%size' => format_size(file_upload_max_size())))
+  );
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Send file'),
+  );
+  return $form;
+}
+
+/**
+ * Validate the dropbox_send_form.
+ */
+function dropbox_send_form_validate($form, &$form_state) {
+  if (empty($form_state['values']['name'])) {
+    form_set_error('name', t('You must enter a name to send a file.'));
+  }
+  if (!valid_email_address($form_state['values']['mail'])) {
+    form_set_error('mail', t('You must enter a valid email address to send a file.'));
+  }
+}
+
+/**
+ * Submit the dropbox_send_form. This uploads the file to a temporary
+ * directory, transfers the file to Dropbox, and sends a notification email
+ * to the destination user.
+ *
+ * @param $form
+ * @param $form_state
+ * @return unknown_type
+ */
+function dropbox_send_form_submit($form, &$form_state) {
+  global $user;
+  $destination_user = $form_state['values']['destination_user'];
+  $file = file_save_upload('upload', array());
+  if (is_object($file)) {
+    $error = dropbox_file_put($destination_user, $file, '/' . variable_get('site_name', 'Drupal') . '/' . strtr($form_state['values']['mail'], "@", "-"));
+    if (!$error) {
+      $params = array();
+      $params['destination_user'] = $destination_user;
+      $params['name'] = $form_state['values']['name'];
+      $params['mail'] = strtr($form_state['values']['mail'], "@", "-");
+      drupal_mail('dropbox', 'send_notify', $destination_user->name . ' <' . $destination_user->mail . '>', user_preferred_language($destination_user), $params, $form_state['values']['mail']);
+      drupal_set_message(t('%filename has successfully been sent.', array('%filename' => $file->filename)));
+      watchdog('dropbox', "%from sent a file to %to's Dropbox account.", array('%from' => isset($user->name) ? $user->name : $params['name'], '%to' => $destination_user->name));
+      file_delete($file);
+    }
+    else {
+      form_set_error('upload', t('Failed to upload the file. Dropbox returned the following error: !dropbox-error', array('!dropbox-error' => $error)));
+    }
+  }
+  else {
+    form_set_error('upload', t('Failed to upload the file. Please try again.'));
+  }
+}
+
