Index: webform_rules/webform_rules.rules.inc
===================================================================
--- webform_rules/webform_rules.rules.inc	(revision 1344)
+++ webform_rules/webform_rules.rules.inc	(working copy)
@@ -158,17 +158,87 @@
 /**
  * Implements hook_rules_data_info().
  */
-function webform_rules_data_info() {
-  return array(
-    'webform_data' => array(
+function webform_rules_rules_data_info() {
+  $data_info = array(
+    'webform' => array(
       'label' => t('webform data'),
       'group' => t('Webform'),
       'token type' => 'webform',
-      'property info' => array(),
+      'wrapper class' => 'WebformRulesSubmissionWrapper',
+      'wrap' => TRUE,
+      'is wrapped' => FALSE,
+      'property info' => array(
+        'sid' => array(
+          'type' => 'integer', 
+          'label' => 'Submission ID',
+        ),
+        'submitted' => array(
+          'type' => 'date', 
+          'label' => 'Date Submitted',
+          ),
+        'remote_addr' => array(
+          'type' => 'text', 
+          'label' => 'IP Address of the submitter',
+          ),
+        'uid' => array(
+          'type' => 'integer',
+          'label' => 'User ID of the submitter',
+          ),
+        'name' => array(
+          'type' => 'text', 
+          'label' => 'Username of the submitter',
+          ),
+        'is_draft' => array(
+          'type' => 'boolean',
+          'label' => 'Whether the submission was finalized',
+        ),
+      ),
     ),
   );
+  // Expose ALL webform components
+  // @TODO: figure out how to use assertions to limit this list based on a
+  //  conditional, similar to the way "entity_has_field" works in rules core.
+  // This could become incredibly taxing on the server. If we had, say 20
+  // webforms with 20 components, we'd be loading 400 records right here. REALLY
+  // need to figure out how to limit this by a selected webform.
+
+  // Webform doesn't provide any API for loading components. We have to get them
+  // directly from the database.
+  $components = db_select('webform_component')
+        ->fields('webform_component')
+        ->orderBy('weight')
+        ->orderBy('name')
+        ->execute();
+  $data = &$data_info['webform']['property info'];
+  foreach ($components as $c) {
+    $c->extra = unserialize($c->extra);
+    $id = "{$c->nid}__{$c->cid}";
+    $data[$id] = array(
+      'label' => $c->name,
+      'description' => t('@form_key from node @nid', array('@form_key' => $c->form_key, '@nid' => $c->nid)),
+      'type' => 'list<text>',
+      'getter callback' => 'webform_rules_submission_data_get',
+      // @TODO: implement setter callback
+    );
+  }
+  return $data_info;
 }
 
+function webform_rules_submission_data_get($submission, $options, $name, $type, $context) {
+  if (is_array($submission) && array_key_exists($name, $submission)) {
+    // If we're looking for the submission component data value, and it's not a
+    // list, return the first entry of the submission component data value.
+    if ($name == 'data' && strpos($context['type'], 'list') === FALSE) {
+      return current($submission[$name]);
+    }
+    // Otherwise, just return whatever value we're looking for.
+    return $submission[$name];
+  }
+  elseif (is_object($submission) && property_exists($submission, $name)) {
+    return $submission->$name;
+  }
+}
+
 /**
  * Validation callback for actions 'webform_rules_webform_open' and
  * 'webform_rules_webform_close'.
@@ -314,3 +384,49 @@
   );
 }
 
+class WebformRulesSubmissionWrapper extends RulesIdentifiableDataWrapper {
+// @TODO: implement RulesDataWrapperSavableInterface
+  protected function setData($data) {
+    if (!is_array($data)) {
+      return;
+    }
+    $submission = current($data);
+    if (!isset($submission['sid'])) {
+      return;
+    }
+    $s = webform_get_submissions(array('sid' => $data['sid']));
+    if (empty($s) || !is_array($s)) {
+      return;
+    }
+    $s = current($s);
+    $this->id = $s->sid;
+    $this->data = $s;
+    $info = $this->info();
+    $node = node_load($s->nid);
+    // Assign each piece of submission data to our wrapper's data properties.
+    foreach ($this->data->data as $cid => $val) {
+      if (empty($node->webform['components'][$cid])) {
+        // No such component on this webform.
+        continue;
+      }
+      $id = "{$s->nid}__$cid";
+      $property_info = $info['property info'][$id];
+      $form_key = $node->webform['components'][$cid]['form_key'];
+      $component_data = $data['components'][$form_key]['value'];
+      $this->data->$id = array_values($component_data);
+    }
+  }
+
+  protected function extractIdentifier($data) {
+    return $data->sid;
+  }
+
+  public function getIdentifier() {
+    return $this->dataAvailable() && $this->value() ? $this->id : NULL;
+  }
+
+  protected function load($id) {
+    module_load_include('inc', 'webform', 'includes/webform.submissions');
+    return webform_get_submissions(array('sid' => $id));
+  }
+}
