def arch_month_mbox(request, list_name, year, month_name): store = get_store(request) mlist = get_list_by_name(list_name, store, request) if mlist is None: raise Http404("No archived mailing-list by that name.") month = month_name_to_num(month_name) year = int(year) begin_date = datetime.datetime(year, month, 1) if month != 12: end_month = month + 1 else: end_month = 1 end_date = datetime.datetime(year, end_month, 1) messages = store.get_messages(mlist.name, start=begin_date, end=end_date) messages.reverse() # they are sorted recent first by default mboxfile, mboxfilepath = tempfile.mkstemp(prefix="hyperkitty-", suffix=".mbox.gz") os.close(mboxfile) mbox = mailbox.mbox(mboxfilepath) for message in messages: mbox.add(message.full) mbox.close() content = StringIO() zipped_content = gzip.GzipFile(fileobj=content) with gzip.GzipFile(fileobj=content, mode="wb") as zipped_content: with open(mboxfilepath, "rb") as mboxfile: zipped_content.write(mboxfile.read()) response = HttpResponse(content.getvalue()) content.close() response['Content-Type'] = "application/mbox+gz" response['Content-Disposition'] = 'attachment; filename=%d-%s.txt.gz' \ % (year, month_name) response['Content-Length'] = len(response.content) os.remove(mboxfilepath) return response
def arch_month(request, list_name, year, month_name, summary_type="thread"): # pylint: disable=unused-argument mlist = get_list_by_name(list_name, request.get_host()) return redirect(reverse('hk_archives_with_month', kwargs={ 'mlist_fqdn': mlist.name, 'year': year, 'month': str(month_name_to_num(month_name)).rjust(2, b"0"), }))
def arch_month(request, list_name, year, month_name, summary_type="thread"): store = get_store(request) mlist = get_list_by_name(list_name, store, request) if mlist is None: raise Http404("No archived mailing-list by that name.") url = reverse('archives_with_month', kwargs={ 'mlist_fqdn': mlist.name, 'year': year, 'month': str(month_name_to_num(month_name)).rjust(2, "0"), }) #return HttpResponse(request.build_absolute_uri(url)) return HttpResponseRedirect(url)
def arch_month_mbox(request, list_name, year, month_name): """ The messages must be rebuilt before being added to the mbox file, including headers and the textual content, making sure to escape email addresses. """ # pylint: disable=unused-argument,unreachable return HttpResponse("Not implemented yet.", content_type="text/plain", status=500) mlist = get_list_by_name(list_name, request.get_host()) month = month_name_to_num(month_name) year = int(year) begin_date = datetime.datetime(year, month, 1) if month != 12: end_month = month + 1 else: end_month = 1 end_date = datetime.datetime(year, end_month, 1) messages = Email.objects.filter(mailinglist=mlist, date__gte=begin_date, date__lte=end_date).order_by("date") mboxfile, mboxfilepath = tempfile.mkstemp(prefix="hyperkitty-", suffix=".mbox.gz") os.close(mboxfile) mbox = mailbox.mbox(mboxfilepath) for msg in messages: mbox.add(msg.full) mbox.close() content = StringIO() zipped_content = gzip.GzipFile(fileobj=content) with gzip.GzipFile(fileobj=content, mode="wb") as zipped_content: with open(mboxfilepath, "rb") as mboxfile: zipped_content.write(mboxfile.read()) response = HttpResponse(content.getvalue()) content.close() response['Content-Type'] = "application/mbox+gz" response['Content-Disposition'] = 'attachment; filename=%d-%s.txt.gz' \ % (year, month_name) response['Content-Length'] = len(response.content) os.remove(mboxfilepath) return response