Index: irc.c
===================================================================
--- irc.c	(revision 5f4eedefd2a444c213f65283a3d942d6287e6ea2)
+++ irc.c	(revision e2b15bb7ebd347dd044167575068ef87ffd9301c)
@@ -119,4 +119,5 @@
 	set_add( &irc->set, "op_root", "true", set_eval_op_root, irc );
 	set_add( &irc->set, "op_user", "true", set_eval_op_user, irc );
+	set_add( &irc->set, "otr_policy", "opportunistic", set_eval_otr_policy, irc );
 	set_add( &irc->set, "password", NULL, passchange, irc );
 	set_add( &irc->set, "private", "true", set_eval_bool, irc );
Index: otr.c
===================================================================
--- otr.c	(revision 5f4eedefd2a444c213f65283a3d942d6287e6ea2)
+++ otr.c	(revision e2b15bb7ebd347dd044167575068ef87ffd9301c)
@@ -1,2 +1,39 @@
+  /********************************************************************\
+  * BitlBee -- An IRC to other IM-networks gateway                     *
+  *                                                                    *
+  * Copyright 2002-2008 Wilmer van der Gaast and others                *
+  \********************************************************************/
+
+/*
+  OTR support (cf. http://www.cypherpunks.ca/otr/)
+  2008, Sven Moritz Hallberg <pesco@khjk.org>
+    
+  files used to store OTR data:
+    <configdir>/<nick>.otr_keys
+    <configdir>/<nick>.otr_fprints
+    
+  top-level todos: (search for TODO for more ;-))
+    integrate otr_load/otr_save with existing storage backends
+    per-account policy settings
+    per-user policy settings
+*/
+
+/*
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License with
+  the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
+  if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+  Suite 330, Boston, MA  02111-1307  USA
+*/
+
 #include "bitlbee.h"
 #ifdef WITH_OTR
@@ -5,10 +42,4 @@
 #include <sys/types.h>
 #include <unistd.h>
-
-/**
-files used to store OTR data:
-  $configdir/$nick.otr_keys
-  $configdir/$nick.otr_fprints
- **/
 
 
@@ -345,5 +376,6 @@
 		otrl_message_free(otrmsg);
 	} else {
-		/* yeah, well, some const casts as usual... ;-) */
+		/* note: otrl_message_sending handles policy, so that if REQUIRE_ENCRYPTION is set,
+		   this case does not occur */
 		st = ic->acc->prpl->buddy_msg( ic, (char *)handle, (char *)msg, flags );
 	}
@@ -388,5 +420,17 @@
 OtrlPolicy op_policy(void *opdata, ConnContext *context)
 {
-	/* TODO: OTR policy configurable */
+	struct im_connection *ic = check_imc(opdata, context->accountname, context->protocol);
+	const char *p;
+
+	p = set_getstr(&ic->irc->set, "otr_policy");
+	if(!strcmp(p, "never"))
+		return OTRL_POLICY_NEVER;
+	if(!strcmp(p, "opportunistic"))
+		return OTRL_POLICY_OPPORTUNISTIC;
+	if(!strcmp(p, "manual"))
+		return OTRL_POLICY_MANUAL;
+	if(!strcmp(p, "always"))
+		return OTRL_POLICY_ALWAYS;
+	
 	return OTRL_POLICY_OPPORTUNISTIC;
 }
@@ -858,4 +902,5 @@
 		}
 		
+		/* TODO: allow context specs ("user/proto/account") in 'otr forget fingerprint'? */
 		u = user_find(irc, args[2]);
 		if(!u || !u->ic) {
@@ -893,4 +938,5 @@
 		char *s;
 		
+		/* TODO: allow context specs ("user/proto/account") in 'otr forget contex'? */
 		u = user_find(irc, args[2]);
 		if(!u || !u->ic) {
Index: otr.h
===================================================================
--- otr.h	(revision 5f4eedefd2a444c213f65283a3d942d6287e6ea2)
+++ otr.h	(revision e2b15bb7ebd347dd044167575068ef87ffd9301c)
@@ -1,2 +1,30 @@
+  /********************************************************************\
+  * BitlBee -- An IRC to other IM-networks gateway                     *
+  *                                                                    *
+  * Copyright 2002-2008 Wilmer van der Gaast and others                *
+  \********************************************************************/
+
+/*
+  OTR support (cf. http://www.cypherpunks.ca/otr/)
+  2008, Sven Moritz Hallberg <pesco@khjk.org>
+*/
+
+/*
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License with
+  the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
+  if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+  Suite 330, Boston, MA  02111-1307  USA
+*/
+
 #ifndef BITLBEE_PROTOCOLS_OTR_H
 #define BITLBEE_PROTOCOLS_OTR_H
Index: set.c
===================================================================
--- set.c	(revision 5f4eedefd2a444c213f65283a3d942d6287e6ea2)
+++ set.c	(revision e2b15bb7ebd347dd044167575068ef87ffd9301c)
@@ -369,2 +369,16 @@
 	return value;
 }
+
+/* possible values: never, opportunistic, manual, always */
+char *set_eval_otr_policy( set_t *set, char *value )
+{
+	if ( !strcmp(value, "never") )
+		return value;
+	if ( !strcmp(value, "opportunistic") )
+		return value;
+	if ( !strcmp(value, "manual") )
+		return value;
+	if ( !strcmp(value, "always") )
+		return value;
+	return NULL;
+}
Index: set.h
===================================================================
--- set.h	(revision 5f4eedefd2a444c213f65283a3d942d6287e6ea2)
+++ set.h	(revision e2b15bb7ebd347dd044167575068ef87ffd9301c)
@@ -102,4 +102,5 @@
 char *set_eval_voice_buddies( set_t *set, char *value );
 char *set_eval_charset( set_t *set, char *value );
+char *set_eval_otr_policy( set_t *set, char *value );
 
 #endif /* __SET_H__ */
