[Spambayes-checkins] spambayes/Outlook2000/sandbox dump_props.py, 1.12, 1.13

Mark Hammond mhammond at users.sourceforge.net
Sat Dec 20 05:38:58 EST 2003


Update of /cvsroot/spambayes/spambayes/Outlook2000/sandbox
In directory sc8-pr-cvs1:/tmp/cvs-serv25896

Modified Files:
	dump_props.py 
Log Message:
Add -c option, which writes output to the Windows clipboard.  This will
hopefully be useful when the binary is out, so people can easily paste
output into mail/sourceforge.


Index: dump_props.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/sandbox/dump_props.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** dump_props.py	16 Dec 2003 05:06:33 -0000	1.12
--- dump_props.py	20 Dec 2003 10:38:56 -0000	1.13
***************
*** 4,10 ****
--- 4,12 ----
  import pythoncom
  import os, sys
+ import tempfile
  
  from win32com.mapi import mapi, mapiutil
  from win32com.mapi.mapitags import *
+ import win32clipboard
  
  import mapi_driver
***************
*** 75,79 ****
      return prop_repr
  
! def DumpItemProps(item, shorten, get_large_props):
      all_props = GetAllProperties(item)
      all_props.sort() # sort by first tuple item, which is name :)
--- 77,81 ----
      return prop_repr
  
! def DumpItemProps(item, shorten, get_large_props, stream=None):
      all_props = GetAllProperties(item)
      all_props.sort() # sort by first tuple item, which is name :)
***************
*** 85,116 ****
          prop_repr = FormatPropertyValue(prop_tag, prop_val, item,
                                          shorten, get_large_props)
!         print "%-20s: %s" % (prop_name, prop_repr)
  
! def DumpProps(driver, mapi_folder, subject, include_attach, shorten, get_large):
      hr, data = mapi_folder.GetProps( (PR_DISPLAY_NAME_A,), 0)
      name = data[0][1]
      for item in driver.GetItemsWithValue(mapi_folder, PR_SUBJECT_A, subject):
!         DumpItemProps(item, shorten, get_large)
          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, get_large)
!             print
!         print
  
  # Generic table dumper.
! def DumpTable(driver, table, name_query_ob, shorten, large_props):
      cols = table.QueryColumns(TBL_ALL_COLUMNS)
      table.SetColumns(cols, 0)
      rows = mapi.HrQueryAllRows(table, cols, None, None, 0)
!     print "Table has %d rows, each with %d columns" % (len(rows), len(cols))
      for row in rows:
!         print "-- new row --"
          for col in row:
              prop_tag, prop_val = col
--- 87,122 ----
          prop_repr = FormatPropertyValue(prop_tag, prop_val, item,
                                          shorten, get_large_props)
!         print >> stream, "%-20s: %s" % (prop_name, prop_repr)
!     print >> stream, "-- end of item properties --"
  
! def DumpProps(driver, mapi_folder, subject, include_attach, shorten,
!               get_large, stream=None):
      hr, data = mapi_folder.GetProps( (PR_DISPLAY_NAME_A,), 0)
      name = data[0][1]
      for item in driver.GetItemsWithValue(mapi_folder, PR_SUBJECT_A, subject):
!         DumpItemProps(item, shorten, get_large, stream)
          if include_attach:
!             print >> stream
              table = item.GetAttachmentTable(0)
              rows = mapi.HrQueryAllRows(table, (PR_ATTACH_NUM,), None, None, 0)
              for row in rows:
                  attach_num = row[0][1]
!                 print >> stream, \
!                       "Dumping attachment (PR_ATTACH_NUM=%d)" % (attach_num,)
                  attach = item.OpenAttach(attach_num, None,
                                           mapi.MAPI_DEFERRED_ERRORS)
!                 DumpItemProps(attach, shorten, get_large, stream)
!             print >> stream
!         print >> stream
  
  # Generic table dumper.
! def DumpTable(driver, table, name_query_ob, shorten, large_props, stream=None):
      cols = table.QueryColumns(TBL_ALL_COLUMNS)
      table.SetColumns(cols, 0)
      rows = mapi.HrQueryAllRows(table, cols, None, None, 0)
!     print >> stream, \
!           "Table has %d rows, each with %d columns" % (len(rows), len(cols))
      for row in rows:
!         print >> stream, "-- new row --"
          for col in row:
              prop_tag, prop_val = col
***************
*** 122,130 ****
              prop_repr = FormatPropertyValue(prop_tag, prop_val, name_query_ob,
                                              shorten, large_props)
!             print "%-20s: %s" % (prop_name, prop_repr)
  
  # This dumps the raw binary data of the property Outlook uses to store
  # user defined fields.
! def FindAndDumpTableUserProps(driver, table, folder, shorten, get_large_props):
      restriction = (mapi.RES_PROPERTY,
                    (mapi.RELOP_EQ,
--- 128,137 ----
              prop_repr = FormatPropertyValue(prop_tag, prop_val, name_query_ob,
                                              shorten, large_props)
!             print >> stream, "%-20s: %s" % (prop_name, prop_repr)
  
  # This dumps the raw binary data of the property Outlook uses to store
  # user defined fields.
! def FindAndDumpTableUserProps(driver, table, folder, shorten,
!                               get_large_props, stream=None):
      restriction = (mapi.RES_PROPERTY,
                    (mapi.RELOP_EQ,
***************
*** 139,143 ****
      prop_repr = FormatPropertyValue(tag, val, folder,
                                      shorten, get_large_props)
!     print "%-20s: %s" % (prop_name, prop_repr)
  
  def usage(driver, extra = None):
--- 146,150 ----
      prop_repr = FormatPropertyValue(tag, val, folder,
                                      shorten, get_large_props)
!     print >> stream, "%-20s: %s" % (prop_name, prop_repr)
  
  def usage(driver, extra = None):
***************
*** 152,155 ****
--- 159,163 ----
  matching is substring and ignore-case.
  
+ -c - Write output to the clipboard, ready for pasting into an email
  -f - Search for the message in the specified folder (default = Inbox)
  -s - Shorten long property values.
***************
*** 175,179 ****
      import getopt
      try:
!         opts, args = getopt.getopt(sys.argv[1:], "af:snl",
                                     ["dump-folder",
                                      "dump-folder-assoc-contents",
--- 183,187 ----
      import getopt
      try:
!         opts, args = getopt.getopt(sys.argv[1:], "caf:snl",
                                     ["dump-folder",
                                      "dump-folder-assoc-contents",
***************
*** 187,194 ****
--- 195,205 ----
      get_large_props = False
      include_attach = False
+     write_clipboard = False
      dump_folder = dump_folder_assoc_contents = dump_folder_user_props = False
      for opt, opt_val in opts:
          if opt == "-f":
              folder_name = opt_val
+         elif opt == "-c":
+             write_clipboard = True
          elif opt == "--dump-folder":
              dump_folder = True
***************
*** 209,212 ****
--- 220,228 ----
              usage(driver, "Unknown arg '%s'" % opt)
  
+     stream = None
+     if write_clipboard:
+         stream_name = tempfile.mktemp("spambayes")
+         stream = open(stream_name, "w")
+         
      if not folder_name:
          folder_name = "Inbox" # Assume this exists!
***************
*** 229,243 ****
      if is_table_dump:
          if dump_folder:
!             DumpItemProps(folder, shorten, get_large_props)
          if dump_folder_assoc_contents:
              table = folder.GetContentsTable(mapi.MAPI_ASSOCIATED)
!             DumpTable(driver, table, folder, shorten, get_large_props)
          if dump_folder_user_props:
              table = folder.GetContentsTable(mapi.MAPI_ASSOCIATED)
              FindAndDumpTableUserProps(driver, table, folder,
!                                       shorten, get_large_props)
      else:
          DumpProps(driver, folder, subject, include_attach,
!                   shorten, get_large_props)
  
  if __name__=='__main__':
--- 245,268 ----
      if is_table_dump:
          if dump_folder:
!             DumpItemProps(folder, shorten, get_large_props, stream)
          if dump_folder_assoc_contents:
              table = folder.GetContentsTable(mapi.MAPI_ASSOCIATED)
!             DumpTable(driver, table, folder, shorten, get_large_props, stream)
          if dump_folder_user_props:
              table = folder.GetContentsTable(mapi.MAPI_ASSOCIATED)
              FindAndDumpTableUserProps(driver, table, folder,
!                                       shorten, get_large_props, stream)
      else:
          DumpProps(driver, folder, subject, include_attach,
!                   shorten, get_large_props, stream)
!     if write_clipboard:
!         stream.close()
!         stream = open(stream_name, "r")
!         win32clipboard.OpenClipboard()
!         win32clipboard.EmptyClipboard()
!         win32clipboard.SetClipboardText(stream.read())
!         stream.close()
!         os.unlink(stream_name)
!         print "Output successfuly written to the Windows clipboard"
  
  if __name__=='__main__':





More information about the Spambayes-checkins mailing list