PageRenderTime 32ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/MvcMailTiein/src/request_filters/bugzilla.php

https://github.com/Yannix/zetacomponents
PHP | 101 lines | 53 code | 3 blank | 45 comment | 11 complexity | 7b2c2205cb6912613bc081a683b0d3a5 MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one
  5. * or more contributor license agreements. See the NOTICE file
  6. * distributed with this work for additional information
  7. * regarding copyright ownership. The ASF licenses this file
  8. * to you under the Apache License, Version 2.0 (the
  9. * "License"); you may not use this file except in compliance
  10. * with the License. You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing,
  15. * software distributed under the License is distributed on an
  16. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17. * KIND, either express or implied. See the License for the
  18. * specific language governing permissions and limitations
  19. * under the License.
  20. *
  21. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  22. * @version //autogentag//
  23. * @filesource
  24. * @package MvcTools
  25. */
  26. /**
  27. * Request filter that ...
  28. *
  29. * @package MvcTools
  30. * @version //autogentag//
  31. * @mainclass
  32. */
  33. class ezcMvcMailBugzillaRequestFilter implements ezcMvcRequestFilter
  34. {
  35. /**
  36. * This function
  37. *
  38. * @param ezcMvcRequest $request
  39. */
  40. public function filterRequest( ezcMvcRequest $request )
  41. {
  42. // set the short_desc from the subject variable and init description
  43. $request->variables['short_desc'] = $request->variables['subject'];
  44. $request->variables['description'] = '';
  45. $lastTag = '';
  46. $inHeader = true;
  47. $lines = explode( "\n", $request->body );
  48. foreach ( $lines as $line )
  49. {
  50. $line = trim( $line );
  51. // check if we have a tag
  52. if ( $inHeader && preg_match( '/^@([a-z_]+)\s*=\s*(.*)$/', $line, $matches ) )
  53. {
  54. if ( in_array( $matches[1], array( 'product', 'component',
  55. 'version', 'short_desc', 'rep_platform',
  56. 'bug_severity', 'priority', 'op_sys',
  57. 'assigned_to', 'bug_file_loc',
  58. 'status_whiteboard', 'target_milestone',
  59. 'group_set', 'qa_contact' ) ) )
  60. {
  61. $lastTag = $matches[1];
  62. $request->variables[$lastTag] = $matches[2];
  63. }
  64. }
  65. else if ( $inHeader && !empty( $line ) )
  66. {
  67. $request->variables[$lastTag] .= ' ' . $line;
  68. }
  69. else if ( $inHeader && empty( $line ) )
  70. {
  71. $inHeader = false;
  72. }
  73. else
  74. {
  75. if ( !empty( $line ) )
  76. {
  77. $request->variables['description'] .= ' ' . $line;
  78. }
  79. }
  80. }
  81. $request->variables['description'] = trim( $request->variables['description'] );
  82. }
  83. /**
  84. * Should not be called with any options, as this filter doesn't support any.
  85. *
  86. * @throws ezcMvcFilterHasNoOptionsException if the $options array is not
  87. * empty.
  88. * @param array $options
  89. */
  90. public function setOptions( array $options )
  91. {
  92. if ( count( $options ) )
  93. {
  94. throw new ezcMvcFilterHasNoOptionsException( __CLASS__ );
  95. }
  96. }
  97. }
  98. ?>