# Path: pgp/message.py
# INCOMPLETE_CRLF = re.compile(b'(\r[^\n]|[^\r]\n)', re.M)
# class MessageSignature(BaseSignature):
# class BaseMessage(object):
# class LiteralMessage(BaseMessage):
# class TextMessage(LiteralMessage):
# class BinaryMessage(LiteralMessage):
# class EncryptedSessionKey(object):
# class SymmetricSessionKey(object):
# class PublicKeySessionKey(object):
# class DefaultSessionKey(object):
# class SymmetricallyEncryptedMessageData(object):
# class EncryptedMessageWrapper(BaseMessage):
# class SignedMessageWrapper(BaseMessage):
# class CompressedMessageWrapper(BaseMessage):
# class DetachedSignature(object):
#     def sign(self, secret_key, signature_version=4,
#              signature_type=C.SIGNATURE_OF_A_BINARY_DOCUMENT,
#              hash_algorithm=None, one_pass=True):
#     def compress(self, compression_algorithm, compression_level):
#     def public_key_encrypt(self, symmetric_algorithm, public_key=None,
#                            public_keys=None, hidden_public_keys=None,
#                            session_key=None, integrity_protect=True):
#     def symmetric_encrypt(self, symmetric_algorithm, passphrase,
#                           session_key=None, integrity_protect=True,
#                           s2k_type=None, s2k_hash_algorithm=None,
#                           s2k_symmetric_algorithm=None,
#                           s2k_salt=None, s2k_count=None):
#     def from_packet(cls, packet):
#     def __init__(self, data, filename, timestamp):
#     def to_packet(self, header_format=None):
#     def to_packets(self, header_format=None):
#     def to_signable_data(self, signature_type, signature_version=3):
#     def to_packet(self, header_format=None):
#     def __init__(self, data, filename, timestamp):
#     def to_signable_data(self, signature_type, signature_version=3):
#     def to_packet(self, header_format=None):
#     def __init__(self, data, filename, timestamp):
#     def encrypt(self, passphrase, data):
#     def decrypt(self, passphrase, data):
#     def from_packet(cls, packet):
#     def __init__(self, symmetric_algorithm, s2k_specification,
#                  passphrase=None, session_key=None, encrypted_key=None):
#     def get_algorithm_and_session_key(self, passphrase):
#     def set_session_key(self, passphrase, session_key=None):
#     def to_packet(self, header_format=None):
#     def from_packet(cls, packet):
#     def to_packet(self, header_format=None):
#     def __init__(self, version, public_key=None, symmetric_algorithm=None,
#                  session_key=None, public_key_algorithm=None, key_id=None,
#                  encrypted_key=None, hide_key_id=False):
#     def get_algorithm_and_session_key(self, secret_key):
#     def set_algorithm_and_session_key(self, public_key, sym_algorithm,
#                                       session_key):
#     def get_algorithm_and_session_key(self, passphrase):
#     def set_algorithm_and_session_key(self, *args, **kwargs):
#     def from_packet(cls, packet):
#     def __init__(self, symmetric_algorithm=None, session_key=None, data=None,
#                  encrypted_data=None, integrity_protected=False, version=None):
#     def encrypt(self, symmetric_algo, key, message):
#     def decrypt(self, symmetric_algo, key):
#     def to_packet(self, header_format=None):
#     def to_packets(self, header_format=None):
# def parse_encrypted_message_packet(packet):
# def parse_session_key_packet(packet):
#     def from_packets(cls, packets):
#     def __init__(self, session_keys, message_data_obj):
#     def get_message(self, secret_key_or_passphrase=None):
#     def to_packets(self, header_format=None):
# def parse_signature_from_packet(packet, message, one_pass=False):
#     def from_packets(cls, packets):
#     def __init__(self, signatures, message, one_pass=True):
#     def get_message(self):
#     def to_packets(self, header_format=None):
#     def from_packet(cls, packet):
#     def __init__(self, compression_algorithm, compression_level=None,
#                  message=None, compressed_data=None):
#     def get_message(self):
#     def set_message(self, message):
#     def to_packet(self, header_format=None):
#     def to_packets(self, header_format=None):
# def open_pgp_message_from_packets(pkts):
#     def from_packets(cls, packets):
#     def __init__(self, message):
#     def to_packets(self):


import re
import chardet
from pgp import message




class MessageCommand(object):

    def __init__(self, io_helper, message_filename, set_filesize,
                 escape_from_lines, for_your_eyes_only):
        self.io_helper = io_helper
        if for_your_eyes_only:
            message_filename = u'_CONSOLE'
        self.message_filename = message_filename
        # TODO: set_filesize
        self.set_filesize = set_filesize
        self.escape_from_lines = escape_from_lines

    def file_to_literal_message(self, filename, binary=True, encoding=None):
        timestamp = self.io_helper.get_timestamp(filename)
        if filename is None:
            file_ = self.io_helper.open_stdin()
        else:
            file_ = self.io_helper.open_file(filename)
        if self.message_filename:
            filename = self.message_filename
        if binary:

# Path: pgp/message.py
# INCOMPLETE_CRLF = re.compile(b'(\r[^\n]|[^\r]\n)', re.M)
# class MessageSignature(BaseSignature):
# class BaseMessage(object):
# class LiteralMessage(BaseMessage):
# class TextMessage(LiteralMessage):
# class BinaryMessage(LiteralMessage):
# class EncryptedSessionKey(object):
# class SymmetricSessionKey(object):
# class PublicKeySessionKey(object):
# class DefaultSessionKey(object):
# class SymmetricallyEncryptedMessageData(object):
# class EncryptedMessageWrapper(BaseMessage):
# class SignedMessageWrapper(BaseMessage):
# class CompressedMessageWrapper(BaseMessage):
# class DetachedSignature(object):
#     def sign(self, secret_key, signature_version=4,
#              signature_type=C.SIGNATURE_OF_A_BINARY_DOCUMENT,
#              hash_algorithm=None, one_pass=True):
#     def compress(self, compression_algorithm, compression_level):
#     def public_key_encrypt(self, symmetric_algorithm, public_key=None,
#                            public_keys=None, hidden_public_keys=None,
#                            session_key=None, integrity_protect=True):
#     def symmetric_encrypt(self, symmetric_algorithm, passphrase,
#                           session_key=None, integrity_protect=True,
#                           s2k_type=None, s2k_hash_algorithm=None,
#                           s2k_symmetric_algorithm=None,
#                           s2k_salt=None, s2k_count=None):
#     def from_packet(cls, packet):
#     def __init__(self, data, filename, timestamp):
#     def to_packet(self, header_format=None):
#     def to_packets(self, header_format=None):
#     def to_signable_data(self, signature_type, signature_version=3):
#     def to_packet(self, header_format=None):
#     def __init__(self, data, filename, timestamp):
#     def to_signable_data(self, signature_type, signature_version=3):
#     def to_packet(self, header_format=None):
#     def __init__(self, data, filename, timestamp):
#     def encrypt(self, passphrase, data):
#     def decrypt(self, passphrase, data):
#     def from_packet(cls, packet):
#     def __init__(self, symmetric_algorithm, s2k_specification,
#                  passphrase=None, session_key=None, encrypted_key=None):
#     def get_algorithm_and_session_key(self, passphrase):
#     def set_session_key(self, passphrase, session_key=None):
#     def to_packet(self, header_format=None):
#     def from_packet(cls, packet):
#     def to_packet(self, header_format=None):
#     def __init__(self, version, public_key=None, symmetric_algorithm=None,
#                  session_key=None, public_key_algorithm=None, key_id=None,
#                  encrypted_key=None, hide_key_id=False):
#     def get_algorithm_and_session_key(self, secret_key):
#     def set_algorithm_and_session_key(self, public_key, sym_algorithm,
#                                       session_key):
#     def get_algorithm_and_session_key(self, passphrase):
#     def set_algorithm_and_session_key(self, *args, **kwargs):
#     def from_packet(cls, packet):
#     def __init__(self, symmetric_algorithm=None, session_key=None, data=None,
#                  encrypted_data=None, integrity_protected=False, version=None):
#     def encrypt(self, symmetric_algo, key, message):
#     def decrypt(self, symmetric_algo, key):
#     def to_packet(self, header_format=None):
#     def to_packets(self, header_format=None):
# def parse_encrypted_message_packet(packet):
# def parse_session_key_packet(packet):
#     def from_packets(cls, packets):
#     def __init__(self, session_keys, message_data_obj):
#     def get_message(self, secret_key_or_passphrase=None):
#     def to_packets(self, header_format=None):
# def parse_signature_from_packet(packet, message, one_pass=False):
#     def from_packets(cls, packets):
#     def __init__(self, signatures, message, one_pass=True):
#     def get_message(self):
#     def to_packets(self, header_format=None):
#     def from_packet(cls, packet):
#     def __init__(self, compression_algorithm, compression_level=None,
#                  message=None, compressed_data=None):
#     def get_message(self):
#     def set_message(self, message):
#     def to_packet(self, header_format=None):
#     def to_packets(self, header_format=None):
# def open_pgp_message_from_packets(pkts):
#     def from_packets(cls, packets):
#     def __init__(self, message):
#     def to_packets(self):


# Path: pgp/commands/gpg/message_.py
import re
import chardet
from pgp import message





class MessageCommand(object):

    def __init__(self, io_helper, message_filename, set_filesize,
                 escape_from_lines, for_your_eyes_only):
        self.io_helper = io_helper
        if for_your_eyes_only:
            message_filename = u'_CONSOLE'
        self.message_filename = message_filename
        # TODO: set_filesize
        self.set_filesize = set_filesize
        self.escape_from_lines = escape_from_lines

    def file_to_literal_message(self, filename, binary=True, encoding=None):
        timestamp = self.io_helper.get_timestamp(filename)
        if filename is None:
            file_ = self.io_helper.open_stdin()
        else:
            file_ = self.io_helper.open_file(filename)
        if self.message_filename:
            filename = self.message_filename
        if binary:

            msg = message.BinaryMessage(file_.read(), filename, timestamp)