[Spambayes-checkins] spambayes/Outlook2000/sandbox dump_props.py,1.2,1.3

Mark Hammond mhammond@users.sourceforge.net
Sat Nov 2 05:26:55 2002


Update of /cvsroot/spambayes/spambayes/Outlook2000/sandbox
In directory usw-pr-cvs1:/tmp/cvs-serv4243

Modified Files:
	dump_props.py 
Log Message:
Add support for dumping attachments too


Index: dump_props.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/sandbox/dump_props.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** dump_props.py	2 Nov 2002 03:18:08 -0000	1.2
--- dump_props.py	2 Nov 2002 05:26:52 -0000	1.3
***************
*** 82,86 ****
  	return ret
  
! def DumpProps(folder_eid, subject, shorten):
      mapi_msgstore = _FindDefaultMessageStore()
      mapi_folder = mapi_msgstore.OpenEntry(folder_eid,
--- 82,93 ----
  	return ret
  
! def DumpItemProps(item, shorten):
!     for prop_name, prop_val in GetAllProperties(item):
!         prop_repr = repr(prop_val)
!         if shorten:
!             prop_repr = prop_repr[:50]
!         print "%-20s: %s" % (prop_name, prop_repr)
!     
! def DumpProps(folder_eid, subject, include_attach, shorten):
      mapi_msgstore = _FindDefaultMessageStore()
      mapi_folder = mapi_msgstore.OpenEntry(folder_eid,
***************
*** 89,93 ****
      hr, data = mapi_folder.GetProps( (PR_DISPLAY_NAME_A,), 0)
      name = data[0][1]
-     print name
      eids = _FindItemsWithValue(mapi_folder, PR_SUBJECT_A, subject)
      print "Folder '%s' has %d items matching '%s'" % (name, len(eids), subject)
--- 96,99 ----
***************
*** 97,105 ****
                                         None,
                                         mapi.MAPI_DEFERRED_ERRORS)
!         for prop_name, prop_val in GetAllProperties(item):
!             prop_repr = repr(prop_val)
!             if shorten:
!                 prop_repr = prop_repr[:50]
!             print "%-20s: %s" % (prop_name, prop_repr)
  
  def usage():
--- 103,116 ----
                                         None,
                                         mapi.MAPI_DEFERRED_ERRORS)
!         DumpItemProps(item, shorten)
!         if include_attach:
!             print
!             table = item.GetAttachmentTable(0)
!             rows = mapi.HrQueryAllRows(table, (PR_ATTACH_NUM,), None, None, 0)
!             for row in rows:
!                 attach_num = row[0][1]
!                 print "Dumping attachment (PR_ATTACH_NUM=%d)" % (attach_num,)
!                 attach = item.OpenAttach(attach_num, None, mapi.MAPI_DEFERRED_ERRORS)
!                 DumpItemProps(attach, shorten)
  
  def usage():
***************
*** 108,111 ****
--- 119,123 ----
  -f - Search for the message in the specified folder (default = Inbox)
  -s - Shorten long property values.
+ -a - Include attachments
  
  Dumps all properties for all messages that match the subject.  Subject
***************
*** 128,132 ****
      import getopt
      try:
!         opts, args = getopt.getopt(sys.argv[1:], "f:s")
      except getopt.error, e:
          print e
--- 140,144 ----
      import getopt
      try:
!         opts, args = getopt.getopt(sys.argv[1:], "af:s")
      except getopt.error, e:
          print e
***************
*** 141,144 ****
--- 153,157 ----
  
      shorten = False
+     include_attach = False
      for opt, opt_val in opts:
          if opt == "-f":
***************
*** 146,149 ****
--- 159,164 ----
          elif opt == "-s":
              shorten = True
+         elif opt == "-a":
+             include_attach = True
          else:
              print "Invalid arg"
***************
*** 157,161 ****
          print "*** Cant find folder", folder_name
          return
!     DumpProps(eid, subject, shorten)
  
  if __name__=='__main__':
--- 172,176 ----
          print "*** Cant find folder", folder_name
          return
!     DumpProps(eid, subject, include_attach, shorten)
  
  if __name__=='__main__':