create_conf_file.py 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/env python
  2. # Copyright 2018 Espace LLC/espacenetworks.com. Written by @chris001.
  3. # This must be run from the main directory of the offlineimap project.
  4. # Typically this script will be run by Travis to create the config files needed for running the automated tests.
  5. # python ./tests/create_conf_file.py
  6. # Input: Seven shell environment variables.
  7. # Output: it writes the config settings to "filename" (./oli-travis.conf) and "additionalfilename" (./test/credentials.conf).
  8. # "filename" is used by normal run of ./offlineimap -c ./oli-travis.conf , "additionalfilename" is used by "pytest".
  9. # They are the same conf file, copie to two different locations for convenience.
  10. import os
  11. import shutil
  12. try:
  13. import ConfigParser
  14. Config = ConfigParser.ConfigParser()
  15. except ImportError:
  16. import configparser
  17. Config = configparser.ConfigParser()
  18. filename = "./oli-travis.conf"
  19. additionalfilename = "./test/credentials.conf" # for the 'pytest' which automatically finds and runs the unittests.
  20. #TODO: detect OS we running on now, and set sslcacertfile location accordingly.
  21. sslcacertfile = "/etc/pki/tls/cert.pem" # CentOS 7
  22. sslcacertfile = "" # TODO: https://gist.github.com/1stvamp/2158128 Current Mac OSX now must download the cacertfile.
  23. sslcacertfile = "/etc/ssl/certs/ca-certificates.crt" # Ubuntu Trusty 14.04 (Travis linux test container 2018.)
  24. if os.environ["TRAVIS_OS_NAME"] == "osx":
  25. sslcacertfile = os.environ["OSX_BREW_SSLCACERTFILE"]
  26. # lets create that config file.
  27. cfgfile = open(filename,'w')
  28. # add the settings to the structure of the file, and lets write it out.
  29. sect = 'general'
  30. Config.add_section(sect)
  31. Config.set(sect,'accounts','Test')
  32. Config.set(sect,'maxsyncaccounts', '1')
  33. sect = 'Account Test'
  34. Config.add_section(sect)
  35. Config.set(sect,'localrepository','IMAP') # Outlook.
  36. Config.set(sect,'remoterepository', 'Gmail')
  37. ### "Repository IMAP" is hardcoded in test/OLItest/TestRunner.py it should dynamically get the Repository names but it doesn't.
  38. sect = 'Repository IMAP' # Outlook.
  39. Config.add_section(sect)
  40. Config.set(sect,'type','IMAP')
  41. Config.set(sect,'remotehost', 'imap-mail.outlook.com')
  42. Config.set(sect,'remoteport', '993')
  43. Config.set(sect,'auth_mechanisms', os.environ["OUTLOOK_AUTH"])
  44. Config.set(sect,'ssl', 'True')
  45. #Config.set(sect,'tls_level', 'tls_compat') #Default is 'tls_compat'.
  46. #Config.set(sect,'ssl_version', 'tls1_2') # Leave this unset. Will auto select between tls1_1 and tls1_2 for tls_secure.
  47. Config.set(sect,'sslcacertfile', sslcacertfile)
  48. Config.set(sect,'remoteuser', os.environ["secure_outlook_email_address"])
  49. Config.set(sect,'remotepass', os.environ["secure_outlook_email_pw"])
  50. Config.set(sect,'createfolders', 'True')
  51. Config.set(sect,'folderfilter', 'lambda f: f not in ["Inbox", "[Gmail]/All Mail"]') #Capitalization of Inbox INBOX was causing runtime failure.
  52. #Config.set(sect,'folderfilter', 'lambda f: f not in ["[Gmail]/All Mail"]')
  53. ### "Repository Gmail" is also hardcoded into test/OLItest/TestRunner.py
  54. sect = 'Repository Gmail'
  55. Config.add_section(sect)
  56. Config.set(sect,'type', 'Gmail')
  57. Config.set(sect,'remoteport', '993')
  58. Config.set(sect,'auth_mechanisms', os.environ["GMAIL_AUTH"])
  59. Config.set(sect,'oauth2_client_id', os.environ["secure_gmail_oauth2_client_id"])
  60. Config.set(sect,'oauth2_client_secret', os.environ["secure_gmail_oauth2_client_secret"])
  61. Config.set(sect,'oauth2_refresh_token', os.environ["secure_gmail_oauth2_refresh_token"])
  62. Config.set(sect,'remoteuser', os.environ["secure_gmail_email_address"])
  63. Config.set(sect,'ssl', 'True')
  64. #Config.set(sect,'tls_level', 'tls_compat')
  65. #Config.set(sect,'ssl_version', 'tls1_2')
  66. Config.set(sect,'sslcacertfile', sslcacertfile)
  67. Config.set(sect,'createfolders', 'True')
  68. Config.set(sect,'folderfilter', 'lambda f: f not in ["INBOX", "[Gmail]/All Mail"]')
  69. Config.write(cfgfile)
  70. cfgfile.close()
  71. shutil.copy(filename, additionalfilename)