virtual_imaplib2.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Copyright (C) 2016-2016 Nicolas Sebrecht & contributors
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the Free Software
  15. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. """
  17. The virtual imaplib2 takes care to import the correct imaplib2 library. Any
  18. internal use of imaplib2 everywhere else in offlineimap must be done through
  19. this virtual_imaplib2 or we might go into troubles.
  20. """
  21. DESC = None
  22. _SUPPORTED_RELEASE = 2
  23. _SUPPORTED_REVISION = 55
  24. try:
  25. # Try any imaplib2 in PYTHONPATH first. This allows both maintainers of
  26. # distributions and developers to not work with the bundled imaplib2.
  27. from imaplib2 import *
  28. import imaplib2 as imaplib
  29. if (int(imaplib.__release__) < _SUPPORTED_RELEASE or
  30. int(imaplib.__revision__) < _SUPPORTED_REVISION):
  31. raise ImportError("The provided imaplib2 version '%s' is not supported"%
  32. imaplib.__version__)
  33. DESC = "system"
  34. except (ImportError, NameError) as e:
  35. try:
  36. from offlineimap.bundled_imaplib2 import *
  37. import offlineimap.bundled_imaplib2 as imaplib
  38. DESC = "bundled"
  39. except:
  40. print("Error while trying to import system imaplib2: %s"% e)
  41. raise
  42. # Upstream won't expose those literals to avoid erasing them with "import *" in
  43. # case they exist.
  44. __version__ = imaplib.__version__
  45. __release__ = imaplib.__release__
  46. __revision__ = imaplib.__revision__