Changeset View
Changeset View
Standalone View
Standalone View
pykolab/cli/cmd_remove_user_subscription.py
Show All 11 Lines | |||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
# GNU General Public License for more details. | # GNU General Public License for more details. | ||||
# You should have received a copy of the GNU General Public License | # You should have received a copy of the GNU General Public License | ||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
# | # | ||||
from __future__ import print_function | |||||
import sys | import sys | ||||
import commands | import commands | ||||
import pykolab | import pykolab | ||||
from pykolab.imap import IMAP | from pykolab.imap import IMAP | ||||
from pykolab.translate import _ | from pykolab.translate import _ | ||||
Show All 40 Lines | if backend == None: | ||||
backend = conf.get('kolab', 'imap_backend') | backend = conf.get('kolab', 'imap_backend') | ||||
admin_login = conf.get(backend, 'admin_login') | admin_login = conf.get(backend, 'admin_login') | ||||
admin_password = conf.get(backend, 'admin_password') | admin_password = conf.get(backend, 'admin_password') | ||||
imap.login_plain(admin_login, admin_password, user) | imap.login_plain(admin_login, admin_password, user) | ||||
if not imap.has_folder(folder_pattern): | if not imap.has_folder(folder_pattern): | ||||
print >> sys.stderr, \ | print(_("Cannot subscribe user to folder %r:") % (folder_pattern), \ | ||||
_("Cannot subscribe user to folder %r:") % (folder_pattern), \ | _("No such folder"), \ | ||||
_("No such folder") | file=sys.stderr) | ||||
sys.exit(1) | sys.exit(1) | ||||
_folders = imap.lm(folder_pattern) | _folders = imap.lm(folder_pattern) | ||||
_subscribed_folders = imap.lsub() | _subscribed_folders = imap.lsub() | ||||
unsubscribed_folders = [] | unsubscribed_folders = [] | ||||
for _folder in _folders: | for _folder in _folders: | ||||
if _folder in _subscribed_folders: | if _folder in _subscribed_folders: | ||||
imap.unsubscribe(_folder) | imap.unsubscribe(_folder) | ||||
unsubscribed_folders.append(_folder) | unsubscribed_folders.append(_folder) | ||||
if len(unsubscribed_folders) > 0: | if len(unsubscribed_folders) > 0: | ||||
print _("Successfully unsubscribed user %s from the following folders:") % ( | print(_("Successfully unsubscribed user %s from the following folders:") % ( | ||||
user | user | ||||
) | )) | ||||
print "\n".join(unsubscribed_folders) | print("\n".join(unsubscribed_folders)) | ||||
else: | else: | ||||
print >> sys.stderr, _("User %s was not unsubscribed from any folders.") % ( | print(_("User %s was not unsubscribed from any folders.") % ( | ||||
user | user | ||||
) | ), file=sys.stderr) | ||||
sys.exit(1) | sys.exit(1) |