def mail_moving(request): if request.method == "POST": action = request.POST.get('action', "") if action == "delete": id = request.POST.get('id', "") IMAPMoving.objects.filter(pk=id).delete() messages.add_message(request, messages.SUCCESS, _(u'删除成功')) if action == "receive": id = request.POST.get('id', "") add_task_to_queue("imapmail", {"imap_id": id}) messages.add_message(request, messages.SUCCESS, _(u'任务注册成功')) if action == 'deleteall': ids = request.POST.get('ids', '') ids = ids.split(',') IMAPMoving.objects.filter(id__in=ids).delete() messages.add_message(request, messages.SUCCESS, _(u'删除成功')) if action == 'disable': ids = request.POST.get('ids', '') ids = ids.split(',') IMAPMoving.objects.filter(id__in=ids).update(disabled='1') messages.add_message(request, messages.SUCCESS, _(u'禁用成功')) if action == 'enable': ids = request.POST.get('ids', '') ids = ids.split(',') IMAPMoving.objects.filter(id__in=ids).update(disabled='-1') messages.add_message(request, messages.SUCCESS, _(u'启用成功')) return HttpResponseRedirect(reverse('mail_moving')) return render(request, "maintain/mail_moving.html", context={})
def mail_moving_import(request): if request.method == "POST": import_data = request.POST.get('addresses', '') success, fail = 0, 0 fail_list = [] for line in import_data.split("\n"): line = line.replace("\r", "") if not line: continue lines = line.split("\t") length = len(lines) mailbox = lines[0] if length >= 1 else "" if not mailbox: continue o = Mailbox.objects.filter(username=mailbox).first() if not o: fail += 1 fail_list.append("'%s' --> '%s' : %s" % (line, mailbox, _(u"本地帐号不存在"))) continue mailbox_id = o.id src_mailbox = lines[1] if length >= 2 else "" src_server = lines[2] if length >= 3 else "" src_password = lines[3] if length >= 4 else "" ssl = lines[4] if length >= 5 else "0" try: ssl = int(ssl) ssl = '1' if ssl == 1 else '-1' except: ssl = '-1' form = IMAPMovingForm( True, { 'mailbox_id': mailbox_id, 'mailbox': mailbox, 'src_mailbox': src_mailbox, 'src_server': src_server, 'src_password': src_password, 'ssl': ssl, 'disabled': '-1' }) if form.is_valid(): form.save() success += 1 else: fail += 1 fail_list.append("'%s' --> '%s' : %s" % (line, mailbox, form.error_notify)) add_task_to_queue("imapmail", {}) messages.add_message( request, messages.SUCCESS, _(u'批量添加成功%(success)s个, 失败%(fail)s个') % { "success": success, "fail": fail }) for line in fail_list: messages.add_message(request, messages.ERROR, _(u'批量添加失败 : %(fail)s') % {"fail": line}) return HttpResponseRedirect(reverse('mail_moving')) return render(request, "maintain/mail_moving_badd.html", context={})
def ajax_imapRecv(request): imap_id = int(request.POST.get("id", 0)) status = "FAIL" msg = "" try: data = { "imap_id": imap_id, } add_task_to_queue("imapmail", data) status = "OK" msg = "" except Exception, err: msg = "任务注册失败: %s" % str(err)
def mail_moving_add(request): form = IMAPMovingForm(False) if request.method == "POST": form = IMAPMovingForm(False, _handle_imap_post(request.POST)) if form.is_valid(): obj2 = form.save() add_task_to_queue("imapmail", { "mailbox_id": obj2.mailbox_id, "src_mailbox": obj2.src_mailbox, }) messages.add_message(request, messages.SUCCESS, _(u'添加数据成功')) return HttpResponseRedirect(reverse('mail_moving')) return render(request, "maintain/mail_moving_add.html", context={ "form": form, 'obj': None })
def mail_moving_modify(request, move_id): obj = IMAPMoving.objects.get(id=move_id) form = IMAPMovingForm(False, instance=obj) if request.method == "POST": form = IMAPMovingForm(False, _handle_imap_post(request.POST), instance=obj) if form.is_valid(): obj2 = form.save() add_task_to_queue("imapmail", { "mailbox_id": obj2.mailbox_id, "src_mailbox": obj2.src_mailbox, }) messages.add_message(request, messages.SUCCESS, _(u'修改数据成功')) return HttpResponseRedirect(reverse('mail_moving')) return render(request, "maintain/mail_moving_add.html", context={ "form": form, 'obj': obj })