-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCommentExtractor.php
More file actions
85 lines (63 loc) · 1.43 KB
/
CommentExtractor.php
File metadata and controls
85 lines (63 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* check if String start with some string
* @param unknown $Haystack
* @param unknown $Needle
* @return boolean
*/
function startsWith($Haystack, $Needle) {
// Recommended version, using strpos
return strpos ( $Haystack, $Needle ) === 0;
}
/**
* extrace comment from text email boday
* @param unknown $str
* @return string
*/
function extractCommmentFromTextEmailBody($str) {
$str_result = "";
$tok = strtok ( $str, "\n" );
$str_lines = array ();
while ( $tok !== false ) {
$l="$tok\n";
array_push ($str_lines,$l);
$tok = strtok ( "\n" );
}
$array_len = count ( $str_lines );
for($x = 0; $x < $array_len; $x ++) {
$line = $str_lines [$x];
/*
if (startsWith ( $line, "From:" )) {
if ((($x + 1) < $array_len) && startsWith ( $str_lines [$x + 1], "Sent:" )) {
break;
}
}*/
if (preg_match("^[-]+$", $line)){
break;
}
$str_result = $str_result . $line;
}
return $str_result;
}
/**
* get task id from email subject
* @param unknown $subject
*/
function extractTaskIdFromEmailSubject($str){
$tok = strtok ( $str, " \t\n" );
$str_lines = array ();
while ( $tok !== false ) {
$l="$tok\n";
array_push ($str_lines,$l);
$tok = strtok ( " \t\n" );
}
$array_len = count ( $str_lines );
for($x = 0; $x < $array_len; $x ++) {
$line = $str_lines [$x];
if (startsWith ( $line, "TK-" )) {
echo "task id-->$line";
return $line;
}
}
return NIL;
}