Index: webform_rules/webform_rules.rules.inc
===================================================================
--- webform_rules/webform_rules.rules.inc	(revision 1344)
+++ webform_rules/webform_rules.rules.inc	(working copy)
@@ -81,6 +81,27 @@
       'group' => t('Webform'),
       'base' => 'webform_rules_condition_node_is_webform',
     ),
+    'data_nid' => array(
+      'label' => t('Submission to a particular webform'),
+      'parameter' => array(
+        'webform' => array(
+          'type' => 'webform',
+          'label' => t('Submission'),
+          'description' => t('Specifiy the submission to check.'),
+          'restriction' => 'selector',
+        ),
+        'nid' => array(
+          'type' => 'list<integer>',
+          'label' => t('Webforms'),
+          'description' => t('The form id of the submitted form'),
+          'options list' => 'webform_rules_get_webforms_as_options',
+          'restriction' => 'input',
+        ),
+      ),
+      'help' => t('Use this condition to expose webform components for a particular webform.'),
+      'group' => t('Webform'),
+      'base' => 'webform_rules_condition_data_nid',
+    ),
   );
 }
 
@@ -158,18 +179,98 @@
 /**
  * Implements hook_rules_data_info().
  */
-function webform_rules_data_info() {
+function webform_rules_rules_data_info() {
   return array(
-    'webform_data' => 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',
+        ),
+      ),
     ),
   );
 }
 
 /**
+ * Use an assertion to expose webform component submission data.
+ * @see rules_condition_entity_has_field_assertions()
+ */
+function webform_rules_condition_data_nid_assertions($element) {
+  // Expose webform components if we're given a particular webform condition.
+  if ($wrapper = $element->applyDataSelector($element->settings['webform:select'])) {
+    $assertion = array('property info' => array());
+    $nids = str_replace('webform-client-form-', '', $element->settings['nid']);
+    foreach ($nids as $nid) {
+      $webform = node_load($nid);
+      // Get webform components and check whether we have one for this webform.
+      foreach ($webform->webform['components'] as $cid => $component) {
+        // A unique selector, using $nid, is important so that our rule will
+        // fail validation if the selected webform changes.
+        $id = "{$nid}__{$cid}";
+        // Provide property info, as in hook_rules_data_info().
+        $assertion['property info'][$id] = array(
+          'label' => $component['name'],
+          'description' => t('@form_key from node @nid', array('@form_key' => $component['form_key'], '@nid' => $component['nid'])),
+          // All submission data is stored in arrays, whether its multiple or
+          // not. Hence, to simplify, we expose all data as list.
+          'type' => 'list<text>',
+          'getter callback' => 'webform_rules_submission_data_get',
+          // @TODO: implement setter callback
+        );
+      }
+    }
+    if (!empty($assertion['property info'])) {
+      return array($element->settings['webform:select'] => $assertion);
+    }
+  }
+}
+
+/**
+ * Getter callback for webform submission data.
+ */
+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 +415,52 @@
   );
 }
 
+/**
+ * Provide entity-like access to webform submission data.
+ */
+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));
+  }
+}
