 if match then match[1] else messageID

    flattenMailboxTree: (tree) ->
        boxes = []

        # first level is only INBOX, with no siblings
        if Object.keys(tree).length is 1 and tree['INBOX']
            root = tree['INBOX']
            delimiter = root.delimiter
            path = 'INBOX' + delimiter

            boxes.push
                label: 'INBOX'
                delimiter: delimiter
                path: 'INBOX'
                tree: ['INBOX']
                attribs: _.difference root.attribs, IGNORE_ATTRIBUTES

            flattenMailboxTreeLevel boxes, root.children, path, [], delimiter
        else
            flattenMailboxTreeLevel boxes, tree, '', [], '/'
        return boxes

    sanitizeHTML: (html, messageId, attachments) ->
        allowedTags = sanitizeHtml.defaults.allowedTags.concat [
            'img'
            'head'
           'meta'
            'title'
            'link'
            'h1'
            'h2'
            'h3'
            'h4'
        ]
        safeAttributes = [
            # general
           'style', 'class', 'background', 'bgcolor'
            # tables
            'colspan', 'rowspan', 'height', 'width', 'align', 'font-size',
            'cellpadding', 'cellspacing', 'border', 'valign'<reponame>dadyarri/audio-splitter<gh_stars>0
import ntpath
from pathlib import Path
from tkinter import *
from tkinter import filedialog
from tkinter import messagebox
from tkinter.ttk import Progressbar

from pydub import AudioSegment
from pydub.exceptions import CouldntDecodeError
from pydub.silence import split_on_silence


def report_error(exc, val, tb):
    from traceback import TracebackException

    log = Path(Path().cwd(), "as.txt")

    with open(log, "a") as log:
        log.write("Exception in Tkinter callback")
        sys.last_type = exc
        sys.last_value = val
        sys.last_traceback = tb
        for line in TracebackException(type(val), val, tb, limit=None).format(
            chain=True
        ):
            log.write(line)
        log.write("\n")


class AudioSplitter:
    def __init__(self):
        self.title = "Audio Splitter"
        self.size = ""
        self.app = Tk()

        self.app.report_callback_exception = report_error

        self.app.title(self.title)
        self.app.geometry(self.size)

        self.formats = ["wav", "mp3"]
        self.current_format = StringVar(self.app)
        self.current_format.set("wav")

        self.source_path = StringVar(self.app)
        self.dest_path = StringVar(self.app)
        self.script_path = StringVar(self.app)

        self.source_label = Label(
            self.app, text="Исходный файл дорожки", font=("Noto Sans", 13), padx=5
        )
        self.source_label.grid(row=1, column=0)

        self.source_input = Entry(
            self.app, textvariable=self.source_path, font=("Noto Sans", 13)
        )
        self.source_input.grid(row=1, column=1)

        self.source_browse = Button(
            self.app,
            text="Обзор",
            command=self.browse_source_button,
            font=("Noto Sans", 13),
            padx=5,
        )
        self.source_browse.grid(row=1, column=2)

        self.dest_label = Label(
            self.app, text="Выходная директория", font=("Noto Sans", 13), padx=5
        )
        self.dest_label.grid(row=2, column=0)

        self.dest_input = Entry(
            self.app, textvariable=self.dest_path, font=("Noto Sans", 13)
        )
        self.dest_input.grid(row=2, column=1)

        self.dest_browse = Button(
            self.app,
            text="Обзор",
            command=self.browse_dest_button,
            font=("Noto Sans", 13),
            padx=5,
        )
        self.dest_browse.grid(row=2, column=2)

        self.pause_label = Label(
            self.app,
            text="Длина паузы между фрагментами (в секундах)",
            font=("Noto Sans", 13),
            padx=5,
        )
        self.pause_label.grid(row=3, column=0)

        self.pause_input = Entry(self.app, font=("Noto Sans", 13))
        self.pause_input.grid(row=3, column=1)

        self.name_label = Label(
            self.app,
            text="Шаблон имени выходных файлов (к нему добавится порядковый номер)",
            font=("Noto Sans", 13),
            padx=5,
        )
        self.name_label.grid(row=4, column=0)

        self.name_input = Entry(self.app, font=("Noto Sans", 13))
        self.name_input.grid(row=4, column=1)

        self.format_label = Label(
            self.app, text="Формат выходных файлов", font=("Noto Sans", 13), padx=5
        )
        self.format_label.grid(row=5, column=0)

        self.format_input = OptionMenu(self.app, self.current_format, *self.formats,)
        self.format_input.grid(row=5, column=1)

        self.silence_label = Label(
            self.app,
            text="Пограничное значение тишины",
            font=("Noto Sans", 13),
            padx=5,
        )
        self.silence_label.grid(row=6, column=0)

        self.silence_input = Entry(self.app, font=("Noto Sans", 13))
        self.silence_input.grid(row=6, column=1)

        self.start = Button(
            self.app,
            text="Начать разделение",
            font=("Noto Sans", 16),
            command=self.start_splitting,
            padx=5,
        )
        self.start.grid(row=7, column=1)

        self.scan_label = Label(
            self.app, text="Путь к папке с чанками", font=("Noto Sans", 13), padx=5
        )
        self.scan_label.grid(row=8, column=0)

        self.scan_input = Entry(
            self.app, textvariable=self.dest_path, font=("Noto Sans", 13)
        )
        self.scan_input.grid(row=8, column=1)

        self.scan_browse = Button(
            self.app,
            text="Обзор",
            command=self.browse_scan_button,
            font=("Noto Sans", 13),
            padx=5,
        )
        self.scan_browse.grid(row=8, column=2)

        self.script_label = Label(
            self.app,
            text="Путь к скрипту, содержащему переменные",
            font=("Noto Sans", 13),
            padx=5,
        )
        self.script_label.grid(row=9, column=0)

        self.script_input = Entry(
            self.app, textvariable=self.script_path, font=("Noto Sans", 13)
        )
        self.script_input.grid(row=9, column=1)

        self.script_brow