summaryrefslogtreecommitdiff
path: root/pykolab/utils.py
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2014-02-11 13:30:14 (GMT)
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2014-02-11 13:30:14 (GMT)
commit14ef739a27fa305d159ad04990842e2638a832e9 (patch)
tree32104bee820ccf906c7096ad581aaddaad372521 /pykolab/utils.py
parent84133cf3535c77dac77ac1f41955c6594f357a58 (diff)
downloadpykolab-14ef739a27fa305d159ad04990842e2638a832e9.tar.gz
Add new settings to control when (under what circumstances) a Sender:, X-Sender: or even an obscured X-Authenticated-As: header is prepended to email submitted through Kolab.
Diffstat (limited to 'pykolab/utils.py')
-rw-r--r--pykolab/utils.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/pykolab/utils.py b/pykolab/utils.py
index 5cba8f9..b7ff468 100644
--- a/pykolab/utils.py
+++ b/pykolab/utils.py
@@ -17,6 +17,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
+import base64
import getpass
import grp
import os
@@ -182,6 +183,29 @@ def ask_menu(question, options={}, default=''):
return answer
+def decode(key, enc):
+ if key == None:
+ return enc
+
+ dec = []
+ enc = base64.urlsafe_b64decode(enc)
+ for i in range(len(enc)):
+ key_c = key[i % len(key)]
+ dec_c = chr((256 + ord(enc[i]) - ord(key_c)) % 256)
+ dec.append(dec_c)
+ return "".join(dec)
+
+def encode(key, clear):
+ if key == None:
+ return clear
+
+ enc = []
+ for i in range(len(clear)):
+ key_c = key[i % len(key)]
+ enc_c = chr((ord(clear[i]) + ord(key_c)) % 256)
+ enc.append(enc_c)
+ return base64.urlsafe_b64encode("".join(enc))
+
def ensure_directory(_dir, _user='root', _group='root'):
if not os.path.isdir(_dir):
os.makedirs(_dir)