def run_messages(threads, args): "builds the message files" with open(path.join(args.output, "messages.json"), "wb") as out: out.write(json.dumps(threads, ensure_ascii=False).encode("utf-8")) partials = {} if args.partials.isdir(): partials = PartialManager(args.partials) message_template = load_template(args.message_template, more_formatters=partials) back = None for index in range(len(threads)): if index > 0: back = paging_info(threads[index - 1][1][0]) try: forward = paging_info(threads[index + 1][1][0]) except IndexError: forward = None for message in threads[index][1]: filename = message.headers.message_id_hash + ".html" with open(path.join(args.output, filename), mode="w", encoding="utf-8") as out: out.write( message_template.expand( list_address=args.list_address, title=args.page_title, top_level=args.page_link, web_root=args.web_root, template=message_template, message=message, next_thread=forward, previous_thread=back, author_index=args.author_index, date_index=args.date_index, subject_index=args.subject_index, thread_index=args.thread_index, ) )
def tie_threads(threads): 'stores a messages "previous" and "next" as part of the message data' threads = iter(threads) peek = previous = None try: queue = deque([next(threads)]) except StopIteration: return while queue: thread = queue.popleft() # process the children before siblings, but in their original order queue.extendleft(reversed(thread.children)) if 'payload' not in thread.message: continue # make sure we can always peek at a message if there are messages left if len(queue) < 1: try: queue.append(next(threads)) except StopIteration: pass try: peek = paging_info(first_message(queue[0])) except IndexError: peek = None thread.message.next = peek thread.message.previous = previous previous = paging_info(first_message(thread))