[ Index ]
 

Code source de dotProject 2.1 RC1

Accédez au Source d'autres logiciels libres | Soutenez Angelica Josefina !

title

Body

[fermer]

/includes/ -> gateway.pl (source)

   1  #!c:\programme\perl\bin\perl.exe -w
   2  # You may have to edit the above line to reflect your system
   3  # E.g. the typical UNIX/Linux system will require #!/usr/bin/perl
   4  
   5  # $Id: gateway.pl,v 1.21.10.1 2006/04/09 11:24:16 cyberhorse Exp $ #
   6  
   7  # send email report upon receipt (1 = yes, 0 = no)
   8  $send_email_report = 1;
   9  
  10  # Send aknowlegment back to lodger (1 = yes, 0 = no)
  11  $send_acknowledge = 1;
  12  
  13  # Save attachments as files in project 0 (1 = yes, 0 = no, just mark them as removed)
  14  $save_attachments = 0;
  15  
  16  # Skip non-MIME component of MIME emails (usually a warning about non-MIME compliant readers)
  17  # Deprecated - leave at 0 unless you know what you are doing!
  18  $skip_mime_preface = 0; 
  19  
  20  # NOTE:  Email addresses should escape the @ symbol as it is
  21  # a PERL array identifier and will cause this script to break.
  22  # Alternatively change the double quotes to single quotes, which
  23  # also escapes the string.
  24  
  25  # NOTE 2: If your dotProject PHP environment is correctly set up
  26  # you don't need to add the @ and domain, it will get it from
  27  # dPconfig[site_domain] key.
  28  
  29  # address to send report to
  30  $report_to_address = 'admin';
  31  
  32  # report from address
  33  $report_from_address = 'support';
  34  
  35  # location of sendmail
  36  $mailprog = "/usr/sbin/sendmail";
  37  
  38  # location of mimencode, some systems call this mmencode
  39  $mime_encoder = "/usr/bin/mimencode";
  40  
  41  # debugging - if set it will report what it finds, but will not add anything
  42  # to the database
  43  $debug = 0;
  44  
  45  ######################## </CONFIGURATION SECTION> ##############################
  46  
  47  ## First phase, check to see we can configure ourselves based upon
  48  ## the PHP environment.
  49  die ("Gateway.pl requires the full path to the dotproject config.php file as its only argument") if ($#ARGV != 0);
  50  %config = ();
  51  &check_config($ARGV[0]);
  52  
  53  # Shortcuts for the email code
  54  $app_root = $config{'base_url'};
  55  $dp_root = $config{'root_dir'};
  56  
  57  # Check that the relevant files exist
  58  @sendmail_st = stat($mailprog);
  59  if (! @sendmail_st) {
  60    if ( $send_email_report || $send_acknowledge ) {
  61      die("You have requested email functions, but your mailer does not exist");
  62    } else {
  63      print "No mailer defined, or mailer not found - will not be able to email error reports\n";
  64      print "Continuing anyway\n";
  65    }
  66  }
  67  
  68  @mmstat = stat($mime_encoder);
  69  if (! @mmstat) {
  70    if ($save_attachments) {
  71      print "You have requested to save attachments, but the mime encoder could not be found\n";
  72      print "Continuing, but not saving attachments\n";
  73      $save_attachments = 0;
  74    }
  75  }
  76  
  77  # If no domain portion, add the domain from the configuration file.
  78  if ( $report_to_address !~ /\@/ ) {
  79    $report_to_address .= '@' . $config{'site_domain'};
  80  }
  81  if ( $report_from_address !~ /\@/ ) {
  82    $report_from_address .= '@' . $config{'site_domain'};
  83  }
  84  
  85  # database bindings
  86  use DBI;
  87  
  88  # read in message
  89  while (<STDIN>) {
  90      push @message, $_;
  91  }
  92  
  93  # main program
  94  &get_headers();
  95  $attach_count = 0;
  96  $mime_alternative = 0;
  97  &check_attachments($attachment_info, $first_message_line, $#message);
  98  &get_body();
  99  &insert_message();
 100  &insert_attachments() if ($save_attachments);
 101  &mail_report() if ($send_email_report);
 102  &mail_acknowledgement() if ($send_acknowledge);
 103  
 104  exit();
 105  
 106  ################################################################################
 107  
 108  sub check_config() {
 109    $dp_conf = $_[0];
 110    open (PHPCONFIG, "<$dp_conf")
 111      or die ("Cannot find dotProject configuration file!");
 112    while (<PHPCONFIG>) {
 113      if (/^\s*\$dpconfig\[/i) {
 114        s/\s*;.*$//;
 115        # Now split the conf line up.
 116        @confs = split /\s*=\s*/;
 117        # First part is the name
 118        $confs[0] =~ s/^.*\[['"](.*)['"]\]/$1/;
 119        $confs[1] =~ s/['"\r\n]//g;
 120        # add to the config array
 121        $config{$confs[0]} = $confs[1];
 122      }
 123    }
 124  }
 125  
 126  sub get_headers {
 127  
 128      # read in headers
 129      # First pass, fix up split headers.
 130      $first_message_line = 0;
 131      foreach (@message) {
 132          last if (/^\s$/ || /^$/);
 133          if (/^[\s\t]+/) {
 134              $last_hdr = pop @headers;
 135              $last_hdr =~ s/[\s\t]*$//;
 136              s/[\s\t]*//;
 137              $last_hdr .= " " . $_;
 138              push @headers, $last_hdr;
 139          } else {
 140              push @headers, $_;
 141          }
 142          $first_message_line++;
 143      }
 144      # Second pass, split out the required headers
 145      $attachment = 0;
 146      foreach (@headers) {
 147          if (/content-type:\s+multipart/i) {
 148          $attachment_info = $_;
 149          if ($save_attachments) {
 150          $attachment = 2;
 151          } else {
 152          $attachment = 1;
 153          }
 154      }
 155      $_ =~ s/:\s/:/g;
 156          if (/:/) {
 157              @vars = split(':', $_, 2);
 158          if (@vars) {
 159          chop($header{$vars[0]} = $vars[1]);
 160          }
 161          }
 162      }
 163  
 164      # strip out Re:'s in subject
 165      $header{'Subject'} =~ s/\s*Re:\s*//gi;
 166  
 167      # put a nice Re: back in
 168      $header{'Subject'} =~ s/(\[\#\d+\])(.*)/$1 Re: $2/;
 169  
 170      # initialize Cc: header
 171      $header{'Cc'} = "" if (!$header{'Cc'});
 172  
 173      # Allow the use of Reply-To to insert tickets on behalf of another
 174      if ($header{'Reply-To'}) {
 175      $header{'From'} = $header{'Reply-To'};
 176      }
 177  
 178      # fix quoting in email headers
 179      $header{'From'} =~ s/"/\"/g;
 180      $header{'Cc'} =~ s/"/\"/g;
 181  
 182      # determine ticket number
 183      $parent = $header{'Subject'};
 184      if ($parent =~ /\[\#(\d+)\]/) {
 185          $parent =~ s/.*\[\#(\d+)\].*/$1/;
 186          $ticket = $parent;
 187      }
 188      else {
 189          $parent = 0;
 190      }
 191  
 192      if ($debug) {
 193      print "parent=$parent\n";
 194      print "attachments=$attachment\n";
 195      print "\nHeaders:\n";
 196      while (($key, $val) = each(%header)) {
 197          print "$key: $val\n";
 198      }
 199      }
 200  }
 201  
 202  sub mail_error() {
 203    my $msg = $_[0];
 204    open(MAIL, "|$mailprog -t");
 205    print MAIL "From: $report_from_address\n";
 206    print MAIL "To: $report_to_address\n";
 207    print MAIL "Subject: Error in processing ticket mail\n\n";
 208    print MAIL "An error occurred in processing a ticket mail.\n";
 209    print MAIL "The error message was:\n";
 210    print MAIL "$msg\n";
 211    print MAIL "\nMessage Headers:\n";
 212    while (($key, $val) = each(%header)) {
 213      print MAIL "   $key: $val\n";
 214    }
 215    close(MAIL);
 216    die($msg);
 217  }
 218  
 219  ################################################################################
 220  
 221  sub check_attachments($) {
 222  
 223      my $att = $_[0];
 224      my $offset = $_[1];
 225      my $end = $_[2];
 226      my $ctype = "";
 227      my $boundary = "";
 228      my $subtype = "";
 229      my %option = ();
 230      my $i;
 231  
 232      # check for attachment
 233      return if (!$att);
 234  
 235      # determine attachment delimiter
 236      ($ctype, $subtype, $options) = ($att =~ m/content-type:\s*([_a-z0-9]+)\/([_a-z0-9]+);?\s(.*)$/i);
 237  
 238      # split the options out
 239      while ($options =~ m/([_a-z0-9]+)=["']?([^;"']+)["';]?/g) {
 240      $name = $1;
 241      $name =~ tr/A-Z/a-z/;
 242      $option{$name} = $2;
 243      if ($debug) {
 244        print "option[$name] = $2\n";
 245      }
 246      }
 247      $boundary = $option{'boundary'};
 248      if ($debug) {
 249      print "\nAttachment Info\n";
 250      print "Original MIME content header is $att\n";
 251      print "Content type is $ctype\n";
 252      print "Subtype is $subtype\n";
 253      print "Boundary is $boundary\n";
 254      print "Option list is $options\n";
 255      print "Checking from $offset to $end\n";
 256      }
 257  
 258      # The subtype should let us know if we are 
 259      return if (!$boundary);
 260      if ($subtype =~ /alternative/i) {
 261      $mime_alternative = 1;
 262      }
 263      # pull out attachments
 264      my $in_attach_hdrs = 0;
 265      for ($i = $offset; $i <= $end; $i++) {
 266      if ($message[$i] =~ /--$boundary/) {
 267          if ($debug) {
 268          print "$attach_count attachment boundary $boundary found at line $i\n";
 269          }
 270          $in_attach_hdrs = 1;
 271          $boundary_lines[$attach_count] = $i;
 272          $attach_disposition[$attach_count] = "";
 273          $attach_type[$attach_count] = "text/plain";
 274          $attach_encoding[$attach_count] = "7bit";
 275          $attach_realname[$attach_count] = "";
 276          $attach_content_header[$attach_count] = "content-type: text/plain";
 277          if ($attach_count > 0 && ! $boundary_end[$attach_count]) {
 278          $boundary_end[$attach_count] = $i-1;
 279          }
 280          $attach_count += 1;
 281      } else {
 282          if ($in_attach_hdrs) {
 283          if ($message[$i] =~ /^\s*$/) {
 284              $boundary_lines[$attach_count-1] = $i;
 285              # push @boundary_end, $last;
 286              $in_attach_hdrs = 0;
 287          } else {
 288              #  In the header section, find the details
 289              @attach_hdr = split(/[:;]/, $message[$i]);
 290              if ($attach_hdr[0] =~ m/content-disposition/i) {
 291              $attach_disposition[$attach_count-1] = $attach_hdr[1];
 292              }
 293              if ($attach_hdr[0] =~ m/content-type/i) {
 294              $attach_type[$attach_count-1] = $attach_hdr[1];
 295              $attach_content_header[$attach_count-1] = $message[$i];
 296              }
 297              if ($attach_hdr[0] =~ m/boundary/i) {
 298              $attach_content_header[$attach_count-1] .= "; " . $attach_hdr[0];
 299              }
 300              if ($attach_hdr[0] =~ m/content-transfer-encoding/i) {
 301              $attach_encoding[$attach_count-1] = $attach_hdr[1];
 302              }
 303              if ($message[$i] =~ m/name=/i) {
 304              ($x, $f) = split(/"/, $message[$i]);
 305              $x = "";
 306              $attach_realname[$attach_count-1] = $f;
 307              }
 308          }
 309          }
 310      }
 311      }
 312      $boundary_end[$attach_count] = $end;
 313      # push @boundary_end, $end;
 314  }
 315  
 316  ################################################################################
 317  
 318  sub get_body {
 319  
 320      my $i;
 321      my $body_lines = 0;
 322  
 323      if ($debug) {
 324      print "Attachcount=$attach_count\n";
 325      }
 326      # read in message body
 327      if (!$attachment_info) {
 328      for ($i = $first_message_line + 1; $i <= $#message; $i++) {
 329          $body .= $message[$i];
 330          $body_lines += 1;
 331      }
 332      }
 333      else {
 334      # Check that the attachments are not in themselves multipart
 335      for ($i = 0; $i < $attach_count; $i++) {
 336          if ($attach_type[$i] =~ /multipart\//i) {
 337          &check_attachments($attach_content_header[$i], $boundary_lines[$i], $boundary_end[$i+1]);
 338          }
 339      }
 340      #$boundary_end[$attach_count] = $#message;
 341      # Look for the attachment that doesn't have a disposition
 342      if ($skip_mime_preface) {
 343          $i = 1;
 344      } else {
 345          $i = 0;
 346      }
 347      for (; $i < $attach_count; $i++) {
 348          if ($debug) {
 349          print "$i: mimealt=$mime_alternative, type=$attach_type[$i], disp=$attach_disposition[$i] name=$attach_realname[$i] start=$boundary_lines[$i], end=$boundary_end[$i+1]\n";
 350          }
 351          if ( ($mime_alternative == 1 && $attach_type[$i] =~ /text\/plain/i) || ($mime_alternative == 0 && $attach_type[$i] =~ /text\//i && $attach_disposition[$i] =~ /^$/ )) {
 352          if ($debug) {
 353              print "Found suitable body text in attachment $i\n";
 354          }
 355          for ($j = $boundary_lines[$i] + 1; $j < $boundary_end[$i+1]; $j++) {
 356              $body .= $message[$j];
 357              $body_lines += 1;
 358          }
 359          # Fix for RFC2046 compliance.
 360          if (($i+1) < $attach_count && $message[$j] !~ /^\s*$/) {
 361            $body .= $message[$j];
 362            $body_lines += 1;
 363          }
 364          }
 365      }
 366      }
 367      if (! $body_lines) {
 368        &mail_error("No suituable body text found in email");
 369      }
 370      $body =~ s/^\n//;
 371      $body =~ s/\r\n$/\n/;
 372      if ($debug) {
 373      print "\nBody:\n";
 374      print $body;
 375      }
 376  }
 377  
 378  ################################################################################
 379  
 380  sub insert_message {
 381  
 382      if ($debug) {
 383      print "insert_message not run, parent = $parent\n";
 384      print "author=" . $header{'From'} . "\n";
 385      print "subject=" . $header{'Subject'} . "\n";
 386      print "cc=" . $header{'Cc'} . "\n";
 387      $author = $header{'From'};
 388      $subject = $header{'Subject'};
 389      $cc = $header{'Cc'};
 390      return;
 391      }
 392      # connect to database
 393      $dbh = DBI->connect("DBI:mysql:$config{'dbname'}:$config{'dbhost'}", $config{'dbuser'}, $config{'dbpass'});
 394  
 395      # update parent activity
 396      if ($parent) {
 397          $activity_query = "UPDATE tickets SET type = 'Open', activity = UNIX_TIMESTAMP() WHERE ticket = '$parent'";
 398          $sth = $dbh->prepare($activity_query);
 399          $sth->execute();
 400          $sth->finish();
 401          $type = "Client Followup";
 402          $assignment = "9999";
 403      }
 404      else {
 405          $type = "Open";
 406          $assignment = "0";
 407      }
 408  
 409      # quote all fields
 410      $db_parent = $dbh->quote($parent);
 411      $attachment = $dbh->quote($attachment);
 412      $author = $dbh->quote($header{'From'});
 413      $subject = $dbh->quote($header{'Subject'});
 414      $body = $dbh->quote($body);
 415      $type = $dbh->quote($type);
 416      $cc = $dbh->quote($header{'Cc'});
 417      $assignment = $dbh->quote($assignment);
 418  
 419      # do insertion
 420      $insert_query = "INSERT INTO tickets (parent, attachment, timestamp, author, subject, body, type, cc, assignment) ";
 421      $insert_query .= "VALUES ($db_parent, $attachment, UNIX_TIMESTAMP(), $author, $subject, $body, $type, $cc, $assignment)";
 422      $sth = $dbh->prepare($insert_query);
 423      $sth->execute();
 424      if (not $parent)
 425         {
 426         $ticket = $sth->{'mysql_insertid'};
 427         }
 428      $sth->finish();
 429      $dbh->disconnect();
 430  
 431  }
 432  
 433  sub insert_attachments {
 434      return if (!$attachment_info);
 435  
 436      if (!$debug) {
 437        $dbh = DBI->connect("DBI:mysql:$config{'dbname'}:$config{'dbhost'}", $config{'dbuser'}, $config{'dbpass'});
 438      }
 439      if ($skip_mime_preface) {
 440          $i = 1;
 441      } else {
 442          $i = 0;
 443      }
 444      for ($i = 0; $i < $attach_count; $i++) {
 445          if ( ( $mime_alternative == 0 && $attach_disposition[$i] !~ /^$/) || ($mime_alternative == 1 && $attach_type[$i] !~ /text\/plain/i && $attach_type[$i] !~ /multipart/i) ) {
 446              if ($debug) {
 447                insert_attachment($i, 0);
 448              } else {
 449                insert_attachment($i, $dbh);
 450              }
 451          }
 452      }
 453      if (! $debug) {
 454        $dbh->disconnect();
 455      }
 456  }
 457  
 458  sub insert_attachment($) {
 459  
 460      $att = $_[0];
 461      $dbh = $_[1];
 462  
 463      if ($debug) {
 464          print "insert_attachment called with att=$att\n";
 465      }
 466  
 467      # Check that we can write to the required directory and that we know who the
 468      # web owner is.
 469      if (! $debug) {
 470      $files_dir = $dp_root . "/files";
 471      $file_repository = $files_dir . "/0";
 472  
 473      @st = stat $files_dir
 474          or    die ("Cannot find file repository");
 475      $web_owner = $st[4];
 476  
 477      # If the repository doesn't exist, create it.
 478      if (! stat $file_repository) {
 479          mkdir $file_repository, 0777;
 480          # If a umask is set, the mkdir will not correctly set
 481          # the modes on the file repository.
 482          chmod 0777, $file_repository;
 483      }
 484  
 485      # Extract the file using mimencode if necessary.
 486      $fid = sprintf("%x_%d", time(), $att);
 487      # If content encoding is not 7bit, try and determine what it is
 488      $fname = $file_repository . "/" . $fid;
 489      $freal = ">";
 490      $freal = "| " . $mime_encoder . " -u -o " if ($attach_encoding[$att] =~ m/base64/i);
 491      $freal = "| " . $mime_encoder . " -u -q -o " if ($attach_encoding[$att] =~ m/quoted/i);
 492      $fout = $freal . $fname;
 493      open(FH, $fout)
 494       or &mail_error("Attached file " . $attach_realname[$att] . " could not be saved!\nThis was probably due to a system error in running the command:\n\t'" . $fout . "'" );
 495      }
 496      for ($j = $boundary_lines[$att] + 1; $j < $boundary_end[$att+1]; $j++) {
 497          if ($debug) {
 498            print $message[$j];
 499          } else {
 500            print FH $message[$j];
 501          }
 502      }
 503      if ($debug) {
 504        return;
 505      } else {
 506        close(FH);
 507      }
 508  
 509      # Determine the files size
 510      open(FH, $fname) or &mail_error("File " . $attach_realname[$att] . " was not created correctly\nThis may be due to permissions errors");
 511      seek FH, 0, 2;
 512      $filesize = tell FH;
 513      close(FH);
 514      if ($filesize <= 0) {
 515        &mail_error("Attached file " . $attach_realname[$att] . " has length " . $filesize );
 516      }
 517  
 518      # Change ownership to the web server owner - assumes the files directory is correctly owned
 519      chown  $fname, $web_owner 
 520       or chmod 0666, $fname;
 521  
 522      # Grab last file version id, and update it.
 523      $sql_stmt = "SELECT file_version_id FROM files ORDER BY file_version_id DESC LIMIT 1";
 524      @file_version = $dbh->selectrow_array($sql_stmt)
 525        or @file_version = (0);
 526  
 527      $file_version_id = $file_version[0] + 1;
 528      
 529  
 530      # insert the file as user Admin (id=1), Project = 0
 531      $sql_stmt = "INSERT into files (file_real_filename, file_name, file_type, file_size, file_date, file_description, file_task, file_version, file_version_id)  values (";
 532      $sql_stmt .= " '" . $fid . "',";
 533      $sql_stmt .= " '" . $attach_realname[$att] . "',";
 534      $sql_stmt .= " '" . $attach_type[$att] . "', ";
 535      $sql_stmt .= sprintf("%d", $filesize);
 536      $sql_stmt .= ", NOW() , ";
 537      $desc = "File attachment from: " . $header{'From'} . "\nTicket #" . $ticket . "\nSubject: " . $header{'Subject'};
 538      $sql_stmt .= $dbh->quote($desc);
 539      $sql_stmt .= ", ";
 540      $sql_stmt .= $ticket;
 541      $sql_stmt .= ", '1', '";
 542      $sql_stmt .= $file_version_id;
 543      $sql_stmt .= "' )";
 544      $sth = $dbh->prepare($sql_stmt);
 545      $sth->execute() or &mail_error("Failed to insert message in database - error was:\n" . $sth->errstr);
 546      $sth->finish();
 547  }
 548  
 549  
 550  ################################################################################
 551  
 552  sub mail_report {
 553  
 554      # unquote necessary fields
 555      $author =~ s/^\'(.*)\'$/$1/;
 556      $author =~ s/\\\'/'/g;
 557          $subject =~ s/^\'(.*)\'$/$1/;
 558      $subject =~ s/\\\'/'/g;
 559  
 560      # try to strip off \r
 561      $author =~ s/\\r//g;
 562      $subject =~ s/\\r//g;
 563  
 564      # remove ticket number
 565      $subject =~ s/\[\#\d+\](.*)/$1/;
 566      $boundary = "_lkqwkASDHASK89271893712893"; 
 567  
 568      # check for possible mail loops
 569      if ( $report_to_address eq $report_from_address
 570      || $author eq $report_from_address ) {
 571        print("Mail loop detected, not sending report\n");
 572        return;
 573      }
 574      # mail the report
 575      if ($debug) {
 576      print "\nReport Mail:\n";
 577      return;
 578      # open(MAIL, "|cat");
 579      } else {
 580      open(MAIL, "|$mailprog -t");
 581      }
 582      print MAIL "To: $report_to_address\n";
 583      print MAIL "From: $report_from_address\n";
 584      if ($parent) {
 585          print MAIL "Subject: Client followup to trouble ticket #$ticket\n";
 586      } else {
 587          print MAIL "Subject: New support ticket #$ticket\n";
 588      }
 589      print MAIL "Content-type: multipart/alternative; boundary=\"$boundary\"\n";
 590      print MAIL "Mime-Version: 1.0\n\n";
 591      print MAIL "--$boundary\n";
 592      print MAIL "Content-disposition: inline\n";
 593      print MAIL "Content-type: text/plain\n\n";
 594      if ($parent) {
 595        print MAIL "Followup Trouble ticket to ticket #$ticket\n\n";
 596      } else {
 597        print MAIL "New Trouble Ticket\n\n";
 598      }
 599      print MAIL "Ticket ID: $ticket\n";
 600      print MAIL "Author   : $author\n";
 601      print MAIL "Subject  : $subject\n";
 602      print MAIL "View     : $app_root/index.php?m=ticketsmith&a=view&ticket=$ticket\n";
 603      print MAIL "\n--$boundary\n";
 604      print MAIL "Content-disposition: inline\n";
 605      print MAIL "Content-type: text/html\n\n";
 606      print MAIL "<html>\n";
 607      print MAIL "<head>\n";
 608      print MAIL "<style>\n";
 609      print MAIL ".title {\n";
 610      print MAIL "    FONT-SIZE: 18pt; SIZE: 18pt;\n";
 611      print MAIL "}\n";
 612      print MAIL ".td {\n";
 613          print MAIL "    font: 9pt arial, san-serif;\n";
 614          print MAIL "}\n";
 615      print MAIL "</style>\n";
 616      if ($parent) {
 617          print MAIL "<title>Followup Trouble ticket to ticket #$ticket</title>\n";
 618      } else {
 619          print MAIL "<title>New Trouble ticket</title>\n";
 620      }
 621      print MAIL "</head>\n";
 622      print MAIL "<body>\n";
 623      print MAIL "\n";
 624      print MAIL "<TABLE border=0 cellpadding=4 cellspacing=1>\n";
 625      print MAIL "    <TR>\n";
 626      print MAIL "        <TD nowrap><span class=title>Trouble Ticket Management</span></td>\n";
 627      print MAIL "        <TD valign=top align=right width=100%>&nbsp;</td>\n";
 628      print MAIL "    </tr>\n";
 629      print MAIL "</TABLE>\n";
 630      print MAIL "<TABLE width=600 border=0 cellpadding=4 cellspacing=1 bgcolor=#878676>\n";
 631      print MAIL "    <TR>\n";
 632      if ($parent) {
 633          print MAIL "        <TD colspan=2><font face=arial,san-serif size=2 color=white>Followup Ticket Entered</font></TD>\n";
 634      } else {
 635          print MAIL "        <TD colspan=2><font face=arial,san-serif size=2 color=white>New Ticket Entered</font></TD>\n";
 636      }
 637      print MAIL "    </tr>\n";
 638      print MAIL "    <TR>\n";
 639      print MAIL "        <TD bgcolor=white nowrap class=td>Ticket ID:</TD>\n";
 640      print MAIL "        <TD bgcolor=white nowrap class=td>$ticket</TD>\n";
 641      print MAIL "    </tr>\n";
 642      print MAIL "    <TR>\n";
 643      print MAIL "        <TD bgcolor=white class=td>Author:</TD>\n";
 644      print MAIL "        <TD bgcolor=white class=td>$author</TD>\n";
 645      print MAIL "    </tr>\n";
 646      print MAIL "    <TR>\n";
 647      print MAIL "        <TD bgcolor=white class=td>Subject:</TD>\n";
 648      print MAIL "        <TD bgcolor=white><font face=arial,san-serif size=2>$subject</font></TD>";
 649      print MAIL "    </tr>\n";
 650      print MAIL "    <TR>\n";
 651      print MAIL "        <TD bgcolor=white nowrap class=td>View:</TD>\n";
 652      print MAIL "        <TD bgcolor=white nowrap class=td><a href=$app_root/index.php?m=ticketsmith&a=view&ticket=$ticket>$app_root/index.php?m=ticketsmith&a=view&ticket=$ticket</a></TD>\n";
 653      print MAIL "    </tr>\n";
 654      print MAIL "</TABLE>\n";
 655      print MAIL "</body>\n";
 656      print MAIL "</html>\n";
 657      print MAIL "\n--$boundary--\n";
 658      close(MAIL);
 659  
 660  }
 661  
 662  ################################################################################
 663  
 664  sub mail_acknowledgement {
 665  
 666      # unquote necessary fields
 667      $author =~ s/^\'(.*)\'$/$1/;
 668      $author =~ s/\\\'/'/g;
 669      $subject =~ s/^\'(.*)\'$/$1/;
 670      $subject =~ s/\\\'/'/g;
 671  
 672      # remove ticket number
 673      $subject =~ s/\[\#\d+\](.*)/$1/;
 674      $boundary = "_lkqwkASDHASK89271893712893"; 
 675  
 676      # Check for mail loops.
 677      if ( $author eq $report_to_address || $author eq $report_from_address) {
 678        print("Detected mail loop, not sending acknowledgment\n");
 679        return;
 680      }
 681  
 682      # mail the report
 683      if ($debug) {
 684      print "\nAcknowledge Mail:\n";
 685      return;
 686      # open(MAIL, "|cat");
 687      }
 688      else {
 689      open(MAIL, "|$mailprog -t");
 690      }
 691      print MAIL "To: $author\n";
 692      print MAIL "From: $report_from_address\n";
 693      if ($parent)
 694         {
 695         print MAIL "Subject: [#$ticket] Response to Ticket $ticket received\n";
 696         }
 697      else
 698          {
 699          print MAIL "Subject: [#$ticket] Your Support Request\n";
 700          }
 701      print MAIL "Content-type: multipart/alternative; boundary=\"$boundary\"\n";
 702      print MAIL "Mime-Version: 1.0\n\n";
 703      print MAIL "--$boundary\n";
 704      print MAIL "Content-disposition: inline\n";
 705      print MAIL "Content-type: text/plain\n\n";
 706      if ($parent)
 707         {
 708         print MAIL "This is an acknowledgement that your response to\n";
 709         print MAIL "Ticket ID $ticket has been received\n";
 710         }
 711       else
 712           {
 713            print MAIL "This is an acknowledgement that your support request has been logged\n";
 714            print MAIL "by an automated support tracking system. It will be assigned to a\n";
 715            print MAIL "support representative who will be in touch in due course.\n\n";
 716           }
 717      print MAIL "Details of support request:\n";
 718      print MAIL "Ticket ID: $ticket\n";
 719      print MAIL "Author   : $author\n";
 720      print MAIL "Subject  : $subject\n";
 721      print MAIL "\n--$boundary\n";
 722      print MAIL "Content-disposition: inline\n";
 723      print MAIL "Content-type: text/html\n\n";
 724      print MAIL "<html>\n";
 725      print MAIL "<head>\n";
 726      print MAIL "<style>\n";
 727      print MAIL ".title {\n";
 728      print MAIL "    FONT-SIZE: 18pt; SIZE: 18pt;\n";
 729      print MAIL "}\n";
 730      print MAIL ".td {\n";
 731          print MAIL "    font: 9pt arial, san-serif;\n";
 732          print MAIL "}\n";
 733      print MAIL "</style>\n";
 734      print MAIL "<title>Your Support Request</title>\n";
 735      print MAIL "</head>\n";
 736      print MAIL "<body>\n";
 737      print MAIL "\n";
 738      print MAIL "<TABLE border=0 cellpadding=4 cellspacing=1>\n";
 739      print MAIL "    <TR>\n";
 740      print MAIL "        <TD nowrap><span class=title>Trouble Ticket Management</span></td>\n";
 741      print MAIL "        <TD valign=top align=right width=100%>&nbsp;</td>\n";
 742      print MAIL "    </tr>\n";
 743      print MAIL "</TABLE>\n";
 744      print MAIL "<TABLE width=600 border=0 cellpadding=4 cellspacing=1 bgcolor=#878676>\n";
 745      print MAIL "    <TR>\n";
 746      if ($parent)
 747         {
 748             print MAIL "                <TD colspan=2><font face=arial,san-serif size=2 color=white>Response received</font></TD>\n";
 749             }
 750      else
 751         {
 752          print MAIL "        <TD colspan=2><font face=arial,san-serif size=2 color=white>New Ticket Entered</font></TD>\n";
 753          }
 754      print MAIL "    </tr>\n";
 755      print MAIL "    <TR>\n";
 756      print MAIL "        <TD bgcolor=white nowrap class=td>Ticket ID:</TD>\n";
 757      print MAIL "        <TD bgcolor=white nowrap class=td>$ticket</TD>\n";
 758      print MAIL "    </tr>\n";
 759      print MAIL "    <TR>\n";
 760      print MAIL "        <TD bgcolor=white class=td>Author:</TD>\n";
 761      print MAIL "        <TD bgcolor=white class=td>$author</TD>\n";
 762      print MAIL "    </tr>\n";
 763      print MAIL "    <TR>\n";
 764      print MAIL "        <TD bgcolor=white class=td>Subject:</TD>\n";
 765      print MAIL "        <TD bgcolor=white class=td>$subject</TD>\n";
 766      print MAIL "    </tr>\n";
 767      print MAIL "    <TR>\n";
 768      print MAIL "        <TD bgcolor=white nowrap class=td>&nbsp;</TD>\n";
 769      print MAIL "        <TD bgcolor=white nowrap class=td>\n";
 770      if ($parent)
 771         {
 772             print MAIL "This is an acknowledgement that your response to\n";
 773             print MAIL "Ticket ID $ticket has been received\n";
 774         }
 775      else
 776          {
 777           print MAIL "This is an acknowledgement that your support request has been logged<br />\n";
 778           print MAIL "by an automated support tracking system. It will be assigned to a<br />\n";
 779           print MAIL "support representative who will be in touch in due course.\n";
 780              }
 781          print MAIL "            </font></TD>\n";
 782      print MAIL "    </tr>\n";
 783      print MAIL "</TABLE>\n";
 784      print MAIL "</body>\n";
 785      print MAIL "</html>\n";
 786      print MAIL "\n--$boundary--\n";
 787      close(MAIL);
 788  
 789  }
 790  
 791  


Généré le : Sun Feb 18 19:46:52 2007 par Balluche grâce à PHPXref 0.7