Message specification
=====================

Source: Provozní řád ISDS, version 2010-11-28, Page 14
Source: Webové služby rozhranní ISDS pro manipulaci s datovými zprávami,
    version 2.16 (2011-01-26)
Source: MIME Media Types
    <http://www.iana.org/assignments/media-types/index.html>
Source: O2. Datové schránky: Informace pro dodavatele aplikací, version
    2010-04-28, Page 18
Source: Vyhláška 194/2009 Sb., o stanovení podrobností užívání a provozování
    informačního systému datových schránek, updated by 422/2010 Coll.

Message ::= Envelope, Content

Message format is defined in Appendix 1, file dmBaseTypes.xsd.

Content ::= (Document)+

Content involves one or more attachments (= Documents). Allowed Document
formats are defined in Vyhláška o stanovení podrobností užívání a provozování
ISDS, 194/2009 Coll.

Currently (2011-02-21) allowed formats are (quotation follows):

    – pdf (Portable Document Format)
    – PDF/A (Portable Document Format for the Long-term Archiving)
    – xml (Extensible Markup Language Document); must be valid against
    freely available XML Schema published by recipient
    – fo, zfo (602XML Filler Document)
    – html/htm (Hypertext Markup Language Document)
    – odt (Open Document Text)
    – ods (Open Document Spreadsheet)
    – odp (Open Document Presentation)
    – txt (plain text)
    – rtf (Rich Text Format)
    – doc, docx (MS Word Document)
    – xls, xlsx (MS Excel Spreadsheet)
    – ppt, pptx (MS PowerPoint Presentation)
    – jpg, jpeg, jfif (Joint Photographic Experts Group File Interchange
    Format)
    – png (Portable Network Graphics)
    – tif, tiff (Tagged Image File Format)
    – gif (Graphics Interchange Format)
    – mpeg1, mpeg2 (Moving Picture Experts Group Phase 1 / Phase 2)
    – wav (Waveform Audio Format)
    – mp2, mp3 (MPEG-1 Audio Layer 2 / Layer 3)
    – isdoc, isdocx (Information System Document) version 5.2 or higher
    - edi (international standard EDIFACT, standards for electotronic
    interchange of business documents [EDI] ODETTE and EANCOM)
    - dwg (AutoCAD DraWinG File Format) version 2007 or higher
    - shp, dbf, shx, prj, qix, sbn, sbx (ESRI Shapefile)
    - dgn (Bentley MicroStation Format) version V7 or V8
    - gml, gfs, xsd (Geography Markup Language Document)

Document format declaration inside Document and conformance checks change
during time. XML Schemas provide attribute for Document MIME type and Document
annotation.

Attribute dmMimeType must present, but may be empty, may contain file name
extension, or may contain official MIME type. If MIME type is declared, ISDS
checks Document content for conformance to the MIME type.

There is MIME type blacklist: application/x-zip-compressed,
application/x-msdownload.

Attribute dmFileDescr (so called annotation) must present and must contain
file name of the Document. Even if dmMimeType exists, ISDS uses THIS attribute
to detect Document format (according file name extension) and checks content
for format conformance.

List of allowed MIME types is copied (and sometimes agumented) in appendix
of Webové služby rozhranní ISDS pro manipulaci s datovými zprávami.

There is list of allowed file name extensions and MIME type mapping
(types ordered in decreasing prefference):

Extensions  MIME type               Description
-------------------------------------------------------------------------------
cer, crt, der
            application/x-x509-ca-cert  X.509 Certificate (different serialization)
doc         application/msword          Microsoft Word Document
docx        application/vnd.openxmlformats-officedocument.wordprocessingml.document
                                        Microsoft OpenXML Document
dbf, prj, qix, sbn, sbx, shp, shx
            application/octet-stream    ESRI Shapefile
dgn         application/octet-stream    Bentley Microstation Format
dwg         image/vnd.dwg               AutoCAD Drawing
edi         application/edifact         EDIFACT (ODETTE, EANCOM standards for
            application/edi-x12         inernational bussines document
            application/edi-consent     exchange)
            text/plain
            text/xml
            application/xml
fo          application/vnd.software602.filler.form+xml
            application/xml
                                        602XML form (uncompressed)
gfs, gml    application/xml             Geography Markup Language Document
            text/xml
gif         image/gif                   Graphics Interchange Format
html, htm   text/html                   Hyper Text MarkUp Language
isdoc       text/isdoc                  Information System Document
                                        (version >= 5.2)
isdocx      text/isdocx                 Information System Document
                                        (version >= 5.2)
jfif, jpeg, jpg
            image/jpeg                  JFIF/JPEG image
            image/pjpeg
mpeg, mpeg1, mpeg2, mpg
            video/mpeg                  Motion Joint Picture Expert Group
            video/mpeg1
            video/mpeg2
            video/mpg
mp2, mp3    audio/mpeg                  MPEG-1 Audio Layer II
odp         application/vnd.oasis.opendocument.presentation
                                        Open Document Format Presentation
ods         application/vnd.oasis.opendocument.spreadsheet
                                        Open Document Format Spreadsheet
odt         application/vnd.oasis.opendocument.text
                                        Open Document Format Text
pdf         application/pdf             Portable Document Format
p7b         application/pkcs7-certificates
            application/pkcs7-mime      
            application/x-pkcs7-certificates
                                        Crypto Message Syntax
p7c, p7m    application/pkcs7-mime      Crypto Message Syntax
            application/x-pkcs7-mime
p7f         application/pkcs7-signature
                                        Crypto Message Syntax
p7s         application/pkcs7-signature      
            application/x-pkcs7-signature      
                                        Crypto Message Syntax
pk7         application/pkcs7-mime      Crypto Message Syntax signatures
            application/x-pkcs7-mime
png         image/png                   Portable Network Graphics
            image/x-png
ppt         application/vnd.ms-powerpoint
                                        Microsoft PowerPoint Document
pptx        application/vnd.openxmlformats-officedocument.presentationml.presentation
                                        Microsoft OpenXML Presentation
rtf         application/msword          Rich Text Format
            text/rtf
            application/rtf
tif, tiff   image/tiff                  Tag Image File Format
tsr, tst    application/timestamp-reply 
                                        Time Stamp Token (RFC 3161)
txt         text/plain                  Plain text
                                        (no charset nor encoding signalled)
wav         audio/wav                   RIFF Waveform Audio File Format
            audio/wave
            audio/x-wav
xls         application/vnd.ms-excel    Microsoft Excel Document
xlsx        application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
                                        Microsoft OpenXML WorkBook
xml         application/xml             Extensible MarkUp Language
            text/xml
xsd         application/xml             XML Schema
            text/xml
zfo         application/vnd.software602.filler.form-xml-zip
                                        602XML form (zipped XML form with
                                        XSL-FO styles) or data box message

Document ::= Binary_Document | XML_Document

Document is Base64 encoded binary format or XML.

There exist special Document type, ESS format, that can exist in Content only
once.

Note: ESS format is special XML language designed as interface between
Electronic Document Systems (ESS). It's defined in Appendix 4 of Provozní řád
ISDS.

Message with `malicious code' will be refused by ISDS.

Maximal total size of Documents in a Message is 10 MB. Binary document size is
size before encoding into Base64, XML document size is size in bytes as is
serialized inside SOAP request.

A Message can be addressed to 50 recipients at maximum.

Life time of Message:

    – 90 days for delivered message, 100 days for system message
    – unlimited for delivered through fiction messages, however they can be
    moved to off-line storage after 90 days. User can request to move the
    Message back into his box (off-line only currently).

Deleted messages are stored off-line as Envelope only without Content. Since
2010-06-01, some services has access to off-line stored envelopes
(Get(Signed)DeliveryInfo, MessageEnvelopeDownload, VerifyMessage,
AuthenticateMessage).

Note: Delivery through fiction is currently defined as new unread for more
than 10 days after delivery.


Digital Signatures
==================

Embedded digital signatures are PKCS#7 to avoid expensive XML canonicalization.


Message hash
============

Message checksum is a hashed bit stream of part of a message. Exact message
part to hash must preserve physical XML serialization. The hash value is
carried inside a message, it's stored in ISDS and it's used as a input form
digital time stamp.

Currently SHA-1 and SHA-256 algortihms are defined. They are identified by
dmHash/@algorithm attribute. Algorithm name in attribute value contains hyphen
character.


System messages
===============

There exists special message type initiated by ISDS (i.e. from system, not from
other box). Such message has reserved from-box `aaaaaaa' (7 × `a') value and
sender type `0' and it contains always document of type HTML. There are
following cases defined:

1   Outgoing message contained malicious code
2   You, administrator, deleted other user
3   Outgoing message could not been delivered because recipient box had been
    made inaccessible retrospectively.
4   Outgoing commercial message has not been accepted by recipient
5   User has been added to your box
6   User permissions has been changed
7   Box has been made temporary inaccessible on court desicion (e.g. user has
    been found eligable unresponsible)
8   Box has been made temporary inaccessible on box owner or administrator
    request
9   Box has been made permanently inaccessible because organization does not
    exist anymore
10  Box has been made temporary (??? specification says temporary, not
    permanently) inaccessible because person has died


Commercial messages
===================

Users can allow commercial message receiving explicitly. Commercial message
are not considered as accepted by recipient automatically (in opposite to
standard messages), recipient must call ConfirmDelivery to move message from
state Delivered (4) to state Received (6).

User can request to assign permission to send commercial messages. Permission
can be assigned by Czech Post. Commercial recipient can not be searched. Sender
must know exact box ID.

Incomming commercial message can be recognised by @dmType="K" in message
envelope. If @dmType is "V" or attribute is missing, message is so called
public (i.e. standard noncommercial with acceptance time outs etc.).

How does ISDS determine (non-)commercial status of outgoing message?
The decision is based on sender and recipient box type, commercial
sending/receiving permission and OVM message flag:

All messages are public except following combinations when message is
considered as commercial:

        Sender                         Recipient
Gross type  Commercial sending  Gross type  Commercial receiving    OVM flag
----------------------------------------------------------------------------
non-OVM     allowed             non-OVM     allowed                 any
any         any                 non-OVM     allowed                 false


Message states
==============

Value   Meaning
1       Message has been put into ISDS
2       Message stamped by TSA
3       Message included viruses, infected document has been removed
4       Message delivered (dmDeliveryTime stored)
5       Message delivered through fiction (dmAcceptanceTime stored)
6       Message delivered by user log-in or user explicit request (in case of
        commercial message) (dmAcceptanceTime stored)
7       Message has been read by user
8       Message could not been delivered (e.g. recipient box has been made
        inaccessible meantime)
9       Message content deleted (thus can not be obtained on-line)
10      Message stored into data safe (this is optional commercial service)
