Mittwoch, 6. März 2013

OTRS Erweiterung: HTML-Mails in ereignis-basierten Benachrichtigungen verwenden

OTRS 3.1.x bietet standardmäßig leider keine Option, bei Benachrichtigungen HTML-Mails zu versenden. Da dieses jedoch im Rahmen eines Projekts bei den ereignis-basierten Benachrichtigungen benötigt wurde, habe ich dafür eine Erweiterung geschrieben, welche dieses ermöglicht.

Nach Einspielen des Patches gibt es eine neue Auswahlliste, bei welcher man HTML oder Unformatiert (Standard, entspricht dem Format text/plain) auswählen kann.

Achtung, der Rich-Text Editor wurde nicht mit eingebaut, als Work-Around kann entweder der HTML-Code vorgeschrieben oder einfach aus einem anderen Modul (z.B. Signatur) der Rich-Text Editor genutzt werden.

diff -Nur /usr/src/otrs-3.1.13/Kernel/Modules/AdminNotificationEvent.pm ./AdminNotificationEvent.pm
--- /usr/src/otrs-3.1.13/Kernel/Modules/AdminNotificationEvent.pm    2012-12-06 08:30:57.000000000 +0100
+++ ./AdminNotificationEvent.pm    2013-02-22 09:44:14.534970100 +0100
@@ -106,7 +106,7 @@
             Events StateID QueueID PriorityID LockID TypeID ServiceID SLAID
             CustomerID CustomerUserID
             ArticleTypeID ArticleSubjectMatch ArticleBodyMatch ArticleAttachmentInclude
-            NotificationArticleTypeID)
+            NotificationArticleTypeID MimeType)
             )
         {
             my @Data = $Self->{ParamObject}->GetArray( Param => $Parameter );
@@ -153,9 +153,10 @@
         my $Ok = $Self->{NotificationEventObject}->NotificationUpdate(
             %GetParam,
             Charset => $Self->{LayoutObject}->{UserCharset},
-            Type    => 'text/plain',
+            Type    => $GetParam{Data}->{MimeType}[0],
             UserID  => $Self->{UserID},
         );
+
         if ($Ok) {
             $Self->_Overview();
             my $Output = $Self->{LayoutObject}->Header();
@@ -229,7 +230,7 @@
             qw(Recipients RecipientAgents RecipientRoles RecipientGroups RecipientEmail Events StateID QueueID
             PriorityID LockID TypeID ServiceID SLAID CustomerID CustomerUserID
             ArticleTypeID ArticleSubjectMatch ArticleBodyMatch ArticleAttachmentInclude
-            NotificationArticleTypeID)
+            NotificationArticleTypeID MimeType)
             )
         {
             my @Data = $Self->{ParamObject}->GetArray( Param => $Parameter );
@@ -272,11 +273,12 @@
             }
         }

         # add
         my $ID = $Self->{NotificationEventObject}->NotificationAdd(
             %GetParam,
             Charset => $Self->{LayoutObject}->{UserCharset},
-            Type    => 'text/plain',
+            Type    => $GetParam{Data}->{MimeType}[0],
             UserID  => $Self->{UserID},
         );


@@ -665,6 +668,18 @@
         SelectedID  => $Param{Data}->{NotificationArticleTypeID},
     );

+
+    $Param{MimeTypeStrg} = $Self->{LayoutObject}->BuildSelection(
+        Data => {
+            'text/html' => 'HTML',
+            'text/plain' => 'Plain',
+        },
+        Name        => 'MimeType',
+        SelectedID  => $Param{Data}->{MimeType} || $Param{Data}->{Type} || 'text/plain',
+        Translation => 1,
+        Max         => 200,
+    );
+
     # take over data fields
     for my $Key (qw(RecipientEmail CustomerID CustomerUserID ArticleSubjectMatch ArticleBodyMatch))
     {
diff -Nur /usr/src/otrs-3.1.13/Kernel/System/Ticket/Event/NotificationEvent.pm ./Ticket/Event/NotificationEvent.pm
--- /usr/src/otrs-3.1.13/Kernel/System/Ticket/Event/NotificationEvent.pm    2013-02-14 13:15:19.000000000 +0100
+++ ./Ticket/Event/NotificationEvent.pm    2013-02-28 18:19:46.526970100 +0100
@@ -120,6 +119,8 @@
             next if $Key eq 'ArticleBodyMatch';
             next if $Key eq 'ArticleAttachmentInclude';
             next if $Key eq 'NotificationArticleTypeID';
+            # notifications now have MimeType, but Tickets dont. Just don't use it.
+            next if $Key eq 'MimeType';

             # check ticket attributes
             next if !$Notification{Data}->{$Key};
@@ -743,8 +761,8 @@
             From       => $From,
             To         => $Recipient{Email},
             Subject    => $Notification{Subject},
-            MimeType   => 'text/plain',
-            Type       => 'text/plain',
+            MimeType   => $Notification{Type},
+            Type       => $Notification{Type},
             Charset    => $Notification{Charset},
             Body       => $Notification{Body},
             Loop       => 1,
@@ -787,8 +805,8 @@
             To             => $Recipient{Email},
             Subject        => $Notification{Subject},
             Body           => $Notification{Body},
-            MimeType       => 'text/plain',
-            Type           => 'text/plain',
+            MimeType       => $Notification{Type},
+            Type           => $Notification{Type},
             Charset        => $Notification{Charset},
             UserID         => $Param{UserID},
             Loop           => 1,
diff -Nur /usr/src/otrs-3.1.13/Kernel/Output/HTML/Standard/AdminNotificationEvent.dtl ./HTML/Standard/AdminNotificationEvent.dtl
--- /usr/src/otrs-3.1.13/Kernel/Output/HTML/Standard/AdminNotificationEvent.dtl 2011-12-23 15:09:31.000000000 +0100
+++ ./HTML/Standard/AdminNotificationEvent.dtl  2013-02-20 17:21:29.122970101 +0100
@@ -262,6 +262,13 @@
                         </div>
                         <div class="Clear"></div>

+                        <label for="MimeType">$Text{"Select mime type"}: </label>
+                        <div class="Field">
+                            $Data{"MimeTypeStrg"}
+                            <p class="FieldExplanation">($Text{"If using html tags, select HTML"})</p>
+                        </div>
+                        <div class="Clear"></div>
+
                         <h3>$Text{"Notification"}:</h3>
                         <div class="Clear"></div>



Der vollständige Patch kann auch direkt unter http://www.ciphron.de/download/software/ heruntergeladen werden und mittels patch -p0 < file eingespielt werden.

Keine Kommentare: