# Path: imap_tools/consts.py
# SHORT_MONTH_NAMES = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')
# 
# Path: imap_tools/utils.py
# def clean_uids(uid_set: Union[str, Iterable[str]]) -> str:
#     """
#     Prepare set of uid for use in IMAP commands
#     uid RE patterns are not strict and allow invalid combinations, but simple. Example: 2,4:7,9,12:*
#     :param uid_set:
#         str, that is comma separated uids
#         Iterable, that contains str uids
#     :return: str - uids, concatenated by a comma
#     """
#     # str
#     if type(uid_set) is str:
#         if re.search(r'^([\d*:]+,)*[\d*:]+$', uid_set):  # *optimization for already good str
#             return uid_set
#         uid_set = uid_set.split(',')
#     # check uid types
#     for uid in uid_set:
#         if type(uid) is not str:
#             raise TypeError('uid "{}" is not string'.format(str(uid)))
#         if not re.match(r'^[\d*:]+$', uid.strip()):
#             raise TypeError('Wrong uid: "{}"'.format(uid))
#     return ','.join(i.strip() for i in uid_set)
# 
# def quote(value: AnyStr) -> AnyStr:
#     if isinstance(value, str):
#         return '"' + value.replace('\\', '\\\\').replace('"', '\\"') + '"'
#     else:
#         return b'"' + value.replace(b'\\', b'\\\\').replace(b'"', b'\\"') + b'"'


import datetime
import itertools
import functools
from collections import UserString
from typing import Iterable, Optional, Dict, Any, List, Union
from .consts import SHORT_MONTH_NAMES
from .utils import clean_uids, quote
"""IMAP Query builder"""



class Header:
    __slots__ = ('name', 'value')

    def __init__(self, name: str, value: str):
        if not isinstance(name, str):
            raise TypeError('Header-name expected str value, "{}" received'.format(type(name)))
        self.name = quote(name)
        if not isinstance(value, str):
            raise TypeError('Header-value expected str value, "{}" received'.format(type(value)))

# Path: imap_tools/consts.py
# SHORT_MONTH_NAMES = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')
# 
# Path: imap_tools/utils.py
# def clean_uids(uid_set: Union[str, Iterable[str]]) -> str:
#     """
#     Prepare set of uid for use in IMAP commands
#     uid RE patterns are not strict and allow invalid combinations, but simple. Example: 2,4:7,9,12:*
#     :param uid_set:
#         str, that is comma separated uids
#         Iterable, that contains str uids
#     :return: str - uids, concatenated by a comma
#     """
#     # str
#     if type(uid_set) is str:
#         if re.search(r'^([\d*:]+,)*[\d*:]+$', uid_set):  # *optimization for already good str
#             return uid_set
#         uid_set = uid_set.split(',')
#     # check uid types
#     for uid in uid_set:
#         if type(uid) is not str:
#             raise TypeError('uid "{}" is not string'.format(str(uid)))
#         if not re.match(r'^[\d*:]+$', uid.strip()):
#             raise TypeError('Wrong uid: "{}"'.format(uid))
#     return ','.join(i.strip() for i in uid_set)
# 
# def quote(value: AnyStr) -> AnyStr:
#     if isinstance(value, str):
#         return '"' + value.replace('\\', '\\\\').replace('"', '\\"') + '"'
#     else:
#         return b'"' + value.replace(b'\\', b'\\\\').replace(b'"', b'\\"') + b'"'


# Path: imap_tools/query.py
import datetime
import itertools
import functools
from collections import UserString
from typing import Iterable, Optional, Dict, Any, List, Union
from .consts import SHORT_MONTH_NAMES
from .utils import clean_uids, quote

"""IMAP Query builder"""



class Header:
    __slots__ = ('name', 'value')

    def __init__(self, name: str, value: str):
        if not isinstance(name, str):
            raise TypeError('Header-name expected str value, "{}" received'.format(type(name)))
        self.name = quote(name)
        if not isinstance(value, str):
            raise TypeError('Header-value expected str value, "{}" received'.format(type(value)))

        self.value = quote(value)