Browse files

change struct with_index to as_json, better for user agent integration

  • Loading branch information...
1 parent 36ee206 commit 040a8e53383692055b8dad783279d1a5b3ccbb77 @nicferrier committed Oct 4, 2011
Showing with 12 additions and 14 deletions.
  1. +1 −1 setup.py
  2. +3 −3 src/md
  3. +8 −10 src/mdlib/__init__.py
View
2 setup.py
@@ -17,7 +17,7 @@
# cmdln
setup(
name = "md",
- version = "0.62",
+ version = "0.70",
description = "Maildir command line mail client and library",
long_description = """A command line tool and shell to allow use of
a maildir directly. Fully fledged MUAs should be trivial to build on top of this.""",
View
6 src/md
@@ -180,16 +180,16 @@ class MdCLI(cmdln.Cmdln):
else:
client.getrawpartid(message, partid, sys.stdout)
- @cmdln.option("-i", "--index", help="show indexes against the parts", action="store_true")
+ @cmdln.option("-j", "--json", help="show the parts in json structure", action="store_true")
def do_struct(self, subcmd, opts, message):
"""${cmd_name}: get the structure of the specified message
${cmd_usage}
${cmd_option_list}
"""
client = MdClient(self.maildir)
- indexes = getattr(opts, "index", False)
- client.getstruct(message, with_index=indexes, stream=sys.stdout)
+ as_json = getattr(opts, "json", False)
+ client.getstruct(message, as_json=as_json, stream=sys.stdout)
def do_file(self, subcmd, opts, message):
"""${cmd_name}: download the whole file of the message.
View
18 src/mdlib/__init__.py
@@ -231,19 +231,17 @@ def getraw(self, msgid, stream=sys.stdout):
msg = folder[msgkey]
print msg.content
- def getstruct(self, msgid, with_index=False, stream=sys.stdout):
+ def getstruct(self, msgid, as_json=False, stream=sys.stdout):
"""Get and print the whole message.
- with_index indicates whether to print the index of the part or not.
+ as_json indicates whether to print the part list as JSON or not.
"""
- parts = [msgpartpair for msgpartpair in self._get(msgid)]
- index = 0
- for hdr,part in parts:
- if with_index:
- print >>stream, "%d %s" % (index, part.get_content_type())
- else:
- print >>stream, part.get_content_type()
- index += 1
+ parts = [part.get_content_type() for hdr, part in self._get(msgid)]
+ if as_json:
+ print >>stream, json.dumps(parts)
+ else:
+ for c in parts:
+ print >>stream, c
def get(self, msgid, stream=sys.stdout):
foldername, msgkey = msgid.split(SEPERATOR)

0 comments on commit 040a8e5

Please sign in to comment.