[Rt-commit] rt branch, 4.2/rest-ticket-content-type, created. rt-4.0.6-335-g9d8a7e6

? sunnavy sunnavy at bestpractical.com
Tue Jun 12 18:55:17 EDT 2012


The branch, 4.2/rest-ticket-content-type has been created
        at  9d8a7e68d5184aaebbc9316d1cb7cac337fa25e1 (commit)

- Log -----------------------------------------------------------------
commit 9d8a7e68d5184aaebbc9316d1cb7cac337fa25e1
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Jun 13 06:53:52 2012 +0800

    REST: allow to set content-type for create/commenting ticket

diff --git a/bin/rt.in b/bin/rt.in
index e54a07a..19622dc 100755
--- a/bin/rt.in
+++ b/bin/rt.in
@@ -470,7 +470,7 @@ sub show {
 sub edit {
     my ($action) = @_;
     my (%data, $type, @objects);
-    my ($cl, $text, $edit, $input, $output);
+    my ($cl, $text, $edit, $input, $output, $content_type);
 
     use vars qw(%set %add %del);
     %set = %add = %del = ();
@@ -484,6 +484,7 @@ sub edit {
         if    (/^-e$/) { $edit = 1 }
         elsif (/^-i$/) { $input = 1 }
         elsif (/^-o$/) { $output = 1 }
+        elsif (/^-ct$/) { $content_type = shift @ARGV }
         elsif (/^-t$/) {
             $bad = 1, last unless defined($type = get_type_argument());
         }
@@ -658,6 +659,11 @@ sub edit {
 EDIT:
     # We'll let the user edit the form before sending it to the server,
     # unless we have enough information to submit it non-interactively.
+    if ( $type eq 'ticket' && $text !~ /^Content-Type:/m ) {
+        $content_type ||= 'text/plain';
+        $text .= "Content-Type: $content_type\n";
+    }
+
     if ($edit || (!$input && !$cl)) {
         my $newtext = vi($text);
         # We won't resubmit a bad form unless it was changed.
@@ -736,7 +742,7 @@ sub setcommand {
 
 sub comment {
     my ($action) = @_;
-    my (%data, $id, @files, @bcc, @cc, $msg, $wtime, $edit);
+    my (%data, $id, @files, @bcc, @cc, $msg, $content_type, $wtime, $edit);
     my $bad = 0;
 
     while (@ARGV) {
@@ -769,7 +775,9 @@ sub comment {
                     while (<STDIN>) { $msg .= $_ }
                 }
             }
-
+            elsif (/-ct/) {
+                $content_type = shift @ARGV;
+            }
             elsif (/-w/) { $wtime = shift @ARGV }
         }
         elsif (!$id && m|^(?:ticket/)?($idlist)$|) {
@@ -791,7 +799,7 @@ sub comment {
 
     my $form = [
         "",
-        [ "Ticket", "Action", "Cc", "Bcc", "Attachment", "TimeWorked", "Text" ],
+        [ "Ticket", "Action", "Cc", "Bcc", "Attachment", "TimeWorked", "Content-Type", "Text" ],
         {
             Ticket     => $id,
             Action     => $action,
@@ -799,6 +807,7 @@ sub comment {
             Bcc        => [ @bcc ],
             Attachment => [ @files ],
             TimeWorked => $wtime || '',
+            'Content-Type' => $content_type || 'text/plain',
             Text       => $msg || '',
             Status => ''
         }
@@ -2331,6 +2340,7 @@ Text:
     Options:
 
         -m <text>       Specify comment text.
+        -ct <content-type> Specify content-type of comment text.
         -a <file>       Attach a file to the comment. (May be used more
                         than once to attach multiple files.)
         -c <addrs>      A comma-separated list of Cc addresses.
diff --git a/share/html/REST/1.0/Forms/ticket/comment b/share/html/REST/1.0/Forms/ticket/comment
index 35b543d..1aef718 100755
--- a/share/html/REST/1.0/Forms/ticket/comment
+++ b/share/html/REST/1.0/Forms/ticket/comment
@@ -90,7 +90,10 @@ if (!$changes{Text} && @atts == 0) {
 
 my $cgi = $m->cgi_object;
 my $ent = MIME::Entity->build(Type => "multipart/mixed");
-$ent->attach(Data => $changes{Text}) if $changes{Text};
+$ent->attach(
+    'Content-Type' => $changes{'Content-Type'} || 'text/plain',
+    Data => $changes{Text},
+) if $changes{Text};
 
 my $i = 1;
 foreach my $att (@atts) {
diff --git a/share/html/REST/1.0/Forms/ticket/default b/share/html/REST/1.0/Forms/ticket/default
index fe74779..48cdd94 100755
--- a/share/html/REST/1.0/Forms/ticket/default
+++ b/share/html/REST/1.0/Forms/ticket/default
@@ -67,7 +67,7 @@ my @dates  = qw(Created Starts Started Due Resolved Told LastUpdated);
 my @people = qw(Requestors Cc AdminCc);
 my @create = qw(Queue Requestor Subject Cc AdminCc Owner Status Priority
                 InitialPriority FinalPriority TimeEstimated TimeWorked
-                TimeLeft Starts Started Due Resolved);
+                TimeLeft Starts Started Due Resolved Content-Type);
 my @simple = qw(Subject Status Priority Disabled TimeEstimated TimeWorked
                 TimeLeft InitialPriority FinalPriority);
 my %dates  = map {lc $_ => $_} @dates;
@@ -177,7 +177,8 @@ else {
                 MIME::Entity->build(
                     From => $session{CurrentUser}->EmailAddress,
                     Subject => $v{Subject},
-                    Data => $text
+                    Data => $text,
+                    'Content-Type' => $v{'Content-Type'} || 'text/plain',
                 );
         }
 
@@ -442,7 +443,7 @@ else {
                 }
             }
         }
-        elsif ($key ne 'id' && $key ne 'type' && $key ne 'creator') {
+        elsif ($key ne 'id' && $key ne 'type' && $key ne 'creator' && $key ne 'content-type' ) {
             $n = 0;
             $s = "Unknown field.";
         }

-----------------------------------------------------------------------


More information about the Rt-commit mailing list