Repository: tonioo/sievelib

Issue:
factory: problem while exporting exists command
When we try to export an exists command, previously parsed, through the factory module, it fails with the following stack:
```python
>>> c = fs.get_filter_conditions('[test]')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/matteo/src/webmail/be/qbservice/sievelib/factory.py", line 387, in get_filter_conditions
    args = node.args_as_tuple()
  File "/home/matteo/src/webmail/be/qbservice/sievelib/commands.py", line 802, in args_as_tuple
    if not value.startswith("["):
AttributeError: 'list' object has no attribute 'startswith'
```

Discussion:

Patch:
diff --git a/sievelib/commands.py b/sievelib/commands.py
index acb4535..fa133d5 100644
--- a/sievelib/commands.py
+++ b/sievelib/commands.py
@@ -798,7 +798,16 @@ class ExistsCommand(TestCommand):
     ]
 
     def args_as_tuple(self):
+        """FIXME: en fonction de la manière dont la commande a été générée
+        (factory ou parser), le type des arguments est différent :
+        string quand ça vient de la factory ou type normal depuis le
+        parser. Il faut uniformiser tout ça !!
+
+        """
         value = self.arguments["header-names"]
+        if isinstance(value, list):
+            value = "[{}]".format(
+                ",".join('"{}"'.format(item) for item in value))
         if not value.startswith("["):
             return ('exists', value.strip('"'))
         return ("exists", ) + tuple(tools.to_list(value))


Test patch:
diff --git a/sievelib/tests/test_factory.py b/sievelib/tests/test_factory.py
index f425363..7787e5c 100644
--- a/sievelib/tests/test_factory.py
+++ b/sievelib/tests/test_factory.py
@@ -5,6 +5,7 @@ import unittest
 import six
 
 from sievelib.factory import FiltersSet
+from .. import parser
 
 
 class FactoryTestCase(unittest.TestCase):
@@ -91,6 +92,21 @@ class FactoryTestCase(unittest.TestCase):
         conditions = self.fs.get_filter_conditions("ruleE")
         self.assertEqual(orig_conditions, conditions)
 
+    def test_get_filter_conditions_from_parser_result(self):
+        res = """require ["fileinto"];
+
+# rule:[test]
+if anyof (exists ["Subject"]) {
+    fileinto "INBOX";
+}
+"""
+        p = parser.Parser()
+        p.parse(res)
+        fs = FiltersSet("test", '# rule:')
+        fs.from_parser_result(p)
+        c = fs.get_filter_conditions('[test]')
+        self.assertEqual(c, [("exists", "Subject")])
+
     def test_get_filter_matchtype(self):
         """Test get_filter_matchtype method."""
         self.fs.addfilter(