From b434785c98ae4ce779473617dad0d4c759a93370 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Guido=20G=C3=BCnther?= <agx@sigxcpu.org>
Date: Sun, 1 Mar 2009 13:41:53 +0100
Subject: [PATCH] acquire tgt via dbus if possible

---
 offlineimap/imapserver.py |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/offlineimap/imapserver.py b/offlineimap/imapserver.py
index 4c89cca..fb1ca9a 100644
--- a/offlineimap/imapserver.py
+++ b/offlineimap/imapserver.py
@@ -32,6 +32,12 @@ try:
 except ImportError:
     pass
 
+try:
+    import dbus
+    have_dbus = True
+except ImportError:
+    have_dbus = False
+
 class UsefulIMAPMixIn:
     def getstate(self):
         return self.state
@@ -151,6 +157,17 @@ class IMAPServer:
                                    'Attempting plain authentication')
         imapobj.login(self.username, self.getpassword())
 
+    def _acquire_tgt(self):
+        if not have_dbus:
+            return
+        try:
+            bus = dbus.SessionBus()
+            ka = bus.get_object('org.gnome.KrbAuthDialog',
+                                '/org/gnome/KrbAuthDialog')
+            ka.acquireTgt("", dbus_interface='org.gnome.KrbAuthDialog')
+        except Exception, e:
+            UIBase.getglobalui().debug('imap', "DBus: Cannot acquire tgt" + str(e))
+
     def gssauth(self, response):
         data = base64.b64encode(response)
         try:
@@ -230,6 +247,8 @@ class IMAPServer:
 
             if not self.tunnel:
                 try:
+                    # Check for TGT:
+                    self._acquire_tgt()
                     # Try GSSAPI and continue if it fails
                     if 'AUTH=GSSAPI' in imapobj.capabilities and have_gss:
                         UIBase.getglobalui().debug('imap',
-- 
1.6.2.rc0

