
########
MIMEBase
########


****
NAME
****


Kernel::System::Ticket::Article::Backend::MIMEBase - base class for all \ ``MIME``\  based article backends


***********
DESCRIPTION
***********


This is a base class for article data in \ ``MIME``\  format and should not be instantiated directly.
Always get real backend instead, i.e. \ ``Email``\ , \ ``Phone``\  or \ ``Internal``\ .

Basic article data is always stored in a database table, but extended data uses configured article
storage backend. For plain text representation of the message, use \ ``Body``\  field. For original
message with email headers, use `ArticlePlain()`_ method to retrieve it from storage backend.
Attachments are handled by the storage backends, and can be retrieved via `ArticleAttachment()`_.

Inherits from `Kernel::System::Ticket::Article::Backend::Base`.

See also `Kernel::System::Ticket::Article::Backend::MIMEBase::Base` and
`Kernel::System::Ticket::Article::Backend::Email`.


****************
PUBLIC INTERFACE
****************


new()
=====


Don't instantiate this class directly, get instances of the real backends instead:


.. code-block:: perl

     my $ArticleBackendObject = $Kernel::OM->Get('Kernel::System::Ticket::Article')->BackendForChannel(ChannelName => 'Email');



ArticleCreate()
===============


Create a MIME article.


.. code-block:: perl

     my $ArticleID = $ArticleBackendObject->ArticleCreate(
         TicketID             => 123,                              # (required)
         SenderTypeID         => 1,                                # (required)
                                                                   # or
         SenderType           => 'agent',                          # (required) agent|system|customer
         IsVisibleForCustomer => 1,                                # (required) Is article visible for customer?
         UserID               => 123,                              # (required)
 
         From           => 'Some Agent <email@example.com>',       # not required but useful
         To             => 'Some Customer A <customer-a@example.com>', # not required but useful
         Cc             => 'Some Customer B <customer-b@example.com>', # not required but useful
         Bcc            => 'Some Customer C <customer-c@example.com>', # not required but useful
         ReplyTo        => 'Some Customer B <customer-b@example.com>', # not required
         Subject        => 'some short description',               # not required but useful
         Body           => 'the message text',                     # not required but useful
         MessageID      => '<asdasdasd.123@example.com>',          # not required but useful
         InReplyTo      => '<asdasdasd.12@example.com>',           # not required but useful
         References     => '<asdasdasd.1@example.com> <asdasdasd.12@example.com>', # not required but useful
         ContentType    => 'text/plain; charset=ISO-8859-15',      # or optional Charset & MimeType
         HistoryType    => 'OwnerUpdate',                          # EmailCustomer|Move|AddNote|PriorityUpdate|WebRequestCustomer|...
         HistoryComment => 'Some free text!',
         Attachment => [
             {
                 Content     => $Content,
                 ContentType => $ContentType,
                 Filename    => 'lala.txt',
             },
             {
                 Content     => $Content,
                 ContentType => $ContentType,
                 Filename    => 'lala1.txt',
             },
         ],
         NoAgentNotify    => 0,                                      # if you don't want to send agent notifications
         AutoResponseType => 'auto reply',                           # auto reject|auto follow up|auto reply/new ticket|auto remove
 
         ForceNotificationToUserID   => [ 1, 43, 56 ],               # if you want to force somebody
         ExcludeNotificationToUserID => [ 43,56 ],                   # if you want full exclude somebody from notifications,
                                                                     # will also be removed in To: line of article,
                                                                     # higher prio as ForceNotificationToUserID
         ExcludeMuteNotificationToUserID => [ 43,56 ],               # the same as ExcludeNotificationToUserID but only the
                                                                     # sending gets muted, agent will still shown in To:
                                                                     # line of article
     );


Example with "Charset & MimeType" and no "ContentType".


.. code-block:: perl

     my $ArticleID = $ArticleBackendObject->ArticleCreate(
         TicketID             => 123,                                 # (required)
         SenderType           => 'agent',                             # (required) agent|system|customer
         IsVisibleForCustomer => 1,                                   # (required) Is article visible for customer?
 
         From             => 'Some Agent <email@example.com>',       # not required but useful
         To               => 'Some Customer A <customer-a@example.com>', # not required but useful
         Subject          => 'some short description',               # required
         Body             => 'the message text',                     # required
         Charset          => 'ISO-8859-15',
         MimeType         => 'text/plain',
         HistoryType      => 'OwnerUpdate',                          # EmailCustomer|Move|AddNote|PriorityUpdate|WebRequestCustomer|...
         HistoryComment   => 'Some free text!',
         UserID           => 123,
         UnlockOnAway     => 1,                                      # Unlock ticket if owner is away
     );


Events:
    ArticleCreate


ArticleGet()
============


Returns single article data.


.. code-block:: perl

     my %Article = $ArticleBackendObject->ArticleGet(
         TicketID      => 123,   # (required)
         ArticleID     => 123,   # (required)
         DynamicFields => 1,     # (optional) To include the dynamic field values for this article on the return structure.
         RealNames     => 1,     # (optional) To include the From/To/Cc/Bcc fields with real names.
     );


Returns:


.. code-block:: perl

     %Article = (
         TicketID               => 123,
         ArticleID              => 123,
         From                   => 'Some Agent <email@example.com>',
         To                     => 'Some Customer A <customer-a@example.com>',
         Cc                     => 'Some Customer B <customer-b@example.com>',
         Bcc                    => 'Some Customer C <customer-c@example.com>',
         ReplyTo                => 'Some Customer B <customer-b@example.com>',
         Subject                => 'some short description',
         MessageID              => '<asdasdasd.123@example.com>',
         InReplyTo              => '<asdasdasd.12@example.com>',
         References             => '<asdasdasd.1@example.com> <asdasdasd.12@example.com>',
         ContentType            => 'text/plain; charset=ISO-8859-15',
         Body                   => 'the message text',
         SenderTypeID           => 1,
         SenderType             => 'agent',
         CommunicationChannelID => 3,
         CommunicationChannel   => 'Internal',
         IsVisibleForCustomer   => 1,
         IncomingTime           => 1490690026,
         CreateBy               => 1,
         CreateTime             => '2017-03-28 08:33:47',
         Charset                => 'ISO-8859-15',
         MimeType               => 'text/plain',
 
         # If DynamicFields => 1 was passed, you'll get an entry like this for each dynamic field:
         DynamicField_X => 'value_x',
 
         # If RealNames => 1 was passed, you'll get fields with contact real names too:
         FromRealname => 'Some Agent',
         ToRealname   => 'Some Customer A',
         CcRealname   => 'Some Customer B',
         BccRealname  => 'Some Customer C',
     );



ArticleUpdate()
===============


Update article data.

Note: Keys \ ``Body``\ , \ ``Subject``\ , \ ``From``\ , \ ``To``\ , \ ``Cc``\ , \ ``Bcc``\ , \ ``ReplyTo``\ , \ ``SenderType``\ , \ ``SenderTypeID``\ 
and \ ``IsVisibleForCustomer``\  are implemented.


.. code-block:: perl

     my $Success = $ArticleBackendObject->ArticleUpdate(
         TicketID  => 123,
         ArticleID => 123,
         Key       => 'Body',
         Value     => 'New Body',
         UserID    => 123,
     );
 
     my $Success = $ArticleBackendObject->ArticleUpdate(
         TicketID  => 123,
         ArticleID => 123,
         Key       => 'SenderType',
         Value     => 'agent',
         UserID    => 123,
     );


Events:
    ArticleUpdate


ArticleDelete()
===============


Delete article data, its plain message, and all attachments.


.. code-block:: perl

     my $Success = $ArticleBackendObject->ArticleDelete(
         TicketID  => 123,
         ArticleID => 123,
         UserID    => 123,
     );




********************************
STORAGE BACKEND DELEGATE METHODS
********************************


ArticleWritePlain()
===================


Write a plain email to storage. This is a delegate method from active backend.


.. code-block:: perl

     my $Success = $ArticleBackendObject->ArticleWritePlain(
         ArticleID => 123,
         Email     => $EmailAsString,
         UserID    => 123,
     );



ArticlePlain()
==============


Get plain article/email from storage. This is a delegate method from active backend.


.. code-block:: perl

     my $PlainMessage = $ArticleBackendObject->ArticlePlain(
         ArticleID => 123,
         UserID    => 123,
     );


Returns:


.. code-block:: perl

     $PlainMessage = '
         From: OTRS Feedback <marketing@otrs.com>
         To: Your OTRS System <otrs@localhost>
         Subject: Welcome to OTRS!
         Content-Type: text/plain; charset=utf-8
         Content-Transfer-Encoding: 8bit
 
         Welcome to OTRS!
         # ...
     ';



ArticleDeletePlain()
====================


Delete a plain article from storage. This is a delegate method from active backend.


.. code-block:: perl

     my $Success = $ArticleBackendObject->ArticleDeletePlain(
         ArticleID => 123,
         UserID    => 123,
     );



ArticleWriteAttachment()
========================


Write an article attachment to storage. This is a delegate method from active backend.


.. code-block:: perl

     my $Success = $ArticleBackendObject->ArticleWriteAttachment(
         Content            => $ContentAsString,
         ContentType        => 'text/html; charset="iso-8859-15"',
         Filename           => 'lala.html',
         ContentID          => 'cid-1234',   # optional
         ContentAlternative => 0,            # optional, alternative content to shown as body
         Disposition        => 'attachment', # or 'inline'
         ArticleID          => 123,
         UserID             => 123,
     );



ArticleAttachment()
===================


Get article attachment from storage. This is a delegate method from active backend.


.. code-block:: perl

     my %Attachment = $ArticleBackendObject->ArticleAttachment(
         ArticleID => 123,
         FileID    => 1,   # as returned by ArticleAttachmentIndex
     );


Returns:


.. code-block:: perl

     %Attachment = (
         Content            => 'xxxx',     # actual attachment contents
         ContentAlternative => '',
         ContentID          => '',
         ContentType        => 'application/pdf',
         Filename           => 'StdAttachment-Test1.pdf',
         FilesizeRaw        => 4722,
         Disposition        => 'attachment',
     );



ArticleDeleteAttachment()
=========================


Delete all attachments of an article from storage. This is a delegate method from active backend.


.. code-block:: perl

     my $Success = $ArticleBackendObject->ArticleDeleteAttachment(
         ArticleID => 123,
         UserID    => 123,
     );



ArticleAttachmentIndex()
========================


Get article attachment index as hash.


.. code-block:: perl

     my %Index = $ArticleBackendObject->ArticleAttachmentIndex(
         ArticleID        => 123,
         ExcludePlainText => 1,       # (optional) Exclude plain text attachment
         ExcludeHTMLBody  => 1,       # (optional) Exclude HTML body attachment
         ExcludeInline    => 1,       # (optional) Exclude inline attachments
     );


Returns:


.. code-block:: perl

     my %Index = {
         '1' => {                                                # Attachment ID
             ContentAlternative => '',                           # (optional)
             ContentID          => '',                           # (optional)
             Filesize           => '4.6 KB',
             ContentType        => 'application/pdf',
             FilesizeRaw        => 4722,
             Disposition        => 'attachment',
         },
         '2' => {
             ContentAlternative => '',
             ContentID          => '',
             Filesize           => '183 B',
             ContentType        => 'text/html; charset="utf-8"',
             FilesizeRaw        => 183,
             Disposition        => 'attachment',
         },
         # ...
     };



BackendSearchableFieldsGet()
============================


Get the definition of the searchable fields as a hash.


.. code-block:: perl

     my %SearchableFields = $ArticleBackendObject->BackendSearchableFieldsGet();


Returns:


.. code-block:: perl

     my %SearchableFields = (
         'MIMEBase_From' => {
             Label      => 'From',
             Key        => 'MIMEBase_From',
             Type       => 'Text',
             Filterable => 0,
         },
         'MIMEBase_To' => {
             Label      => 'To',
             Key        => 'MIMEBase_To',
             Type       => 'Text',
             Filterable => 0,
         },
         'MIMEBase_Cc' => {
             Label      => 'Cc',
             Key        => 'MIMEBase_Cc',
             Type       => 'Text',
             Filterable => 0,
         },
         'MIMEBase_Bcc' => {
             Label      => 'Bcc',
             Key        => 'MIMEBase_Bcc',
             Type       => 'Text',
             Filterable => 0,
         },
         'MIMEBase_Subject' => {
             Label      => 'Subject',
             Key        => 'MIMEBase_Subject',
             Type       => 'Text',
             Filterable => 1,
         },
         'MIMEBase_Body' => {
             Label      => 'Body',
             Key        => 'MIMEBase_Body',
             Type       => 'Text',
             Filterable => 1,
         },
         'MIMEBase_AttachmentName' => {
             Label      => 'Attachment Name',
             Key        => 'MIMEBase_AttachmentName',
             Type       => 'Text',
             Filterable => 0,
         },
     );



ArticleSearchableContentGet()
=============================


Get article attachment index as hash.


.. code-block:: perl

     my %Index = $ArticleBackendObject->ArticleSearchableContentGet(
         TicketID       => 123,   # (required)
         ArticleID      => 123,   # (required)
         DynamicFields  => 1,     # (optional) To include the dynamic field values for this article on the return structure.
         RealNames      => 1,     # (optional) To include the From/To/Cc/Bcc fields with real names.
         UserID         => 123,   # (required)
     );


Returns:


.. code-block:: perl

     my %ArticleSearchData = {
         'From'    => {
             String     => 'Test User1 <testuser1@example.com>',
             Key        => 'From',
             Type       => 'Text',
             Filterable => 0,
         },
         'To'    => {
             String     => 'Test User2 <testuser2@example.com>',
             Key        => 'To',
             Type       => 'Text',
             Filterable => 0,
         },
         'Cc'    => {
             String     => 'Test User3 <testuser3@example.com>',
             Key        => 'Cc',
             Type       => 'Text',
             Filterable => 0,
         },
         'Bcc'    => {
             String     => 'Test User4 <testuser4@example.com>',
             Key        => 'Bcc',
             Type       => 'Text',
             Filterable => 0,
         },
         'Subject'    => {
             String     => 'This is a test subject!',
             Key        => 'Subject',
             Type       => 'Text',
             Filterable => 1,
         },
         'Body'    => {
             String     => 'This is a body text!',
             Key        => 'Body',
             Type       => 'Text',
             Filterable => 1,
         }
     };



ArticleHasHTMLContent()
=======================


Returns 1 if article has HTML content.


.. code-block:: perl

     my $ArticleHasHTMLContent = $ArticleBackendObject->ArticleHasHTMLContent(
         TicketID  => 1,
         ArticleID => 2,
         UserID    => 1,
     );


Result:


.. code-block:: perl

     $ArticleHasHTMLContent = 1;     # or 0





