1
2
3
4
5
6
7 package org.mule.example.geomail.components;
8
9 import java.util.regex.Matcher;
10 import java.util.regex.Pattern;
11
12
13
14
15 public class ReceivedHeader
16 {
17 private String id;
18 private String from;
19 private String by;
20 private String via;
21 private String with;
22 private String _for;
23 private String timestamp;
24
25 public static ReceivedHeader getInstance(String receivedHeader)
26 {
27 String fromPattern = "(?:from (.*?))?";
28 String byPattern = "(?:by (.*?))?";
29 String viaPattern = "(?:via (.*?))?";
30 String withPattern = "(?:with (.*?))?";
31 String idPattern = "(?:id (.*?))?";
32 String forPattern = "(?:for (.*?))?";
33 String timePattern = ";(.*)";
34
35 String pattern = fromPattern + byPattern + viaPattern + withPattern + idPattern + forPattern
36 + timePattern;
37
38 Matcher matcher = Pattern.compile(pattern, Pattern.DOTALL).matcher(receivedHeader);
39
40 ReceivedHeader result = null;
41 if (matcher.find())
42 {
43 result = new ReceivedHeader();
44 result.setFrom(matcher.group(1));
45 result.setBy(matcher.group(2));
46 result.setVia(matcher.group(3));
47 result.setWith(matcher.group(4));
48 result.setId(matcher.group(5));
49 result.setFor(matcher.group(6));
50 result.setTimestamp(matcher.group(7));
51 }
52
53 return result;
54 }
55
56 public String getId()
57 {
58 return id;
59 }
60
61 private void setId(String id)
62 {
63 this.id = (id != null ? id.trim() : null);
64 }
65
66 public String getFrom()
67 {
68 return from;
69 }
70
71 private void setFrom(String from)
72 {
73 this.from = (from != null ? from.trim() : null);
74 }
75
76 public String getBy()
77 {
78 return by;
79 }
80
81 private void setBy(String by)
82 {
83 this.by = (by != null ? by.trim() : null);
84 }
85
86 public String getVia()
87 {
88 return via;
89 }
90
91 private void setVia(String via)
92 {
93 this.via = (via != null ? via.trim() : null);
94 }
95
96 public String getWith()
97 {
98 return with;
99 }
100
101 private void setWith(String with)
102 {
103 this.with = (with != null ? with.trim() : null);
104 }
105
106 public String getFor()
107 {
108 return _for;
109 }
110
111 public void setFor(String _for)
112 {
113 this._for = (_for != null ? _for.trim() : null);
114 }
115
116 public String getTimestamp()
117 {
118 return timestamp;
119 }
120
121 private void setTimestamp(String timestamp)
122 {
123 this.timestamp = timestamp.trim();
124 }
125
126 @Override
127 public String toString()
128 {
129 return "Received {\n " + (getId() != null ? "id: " + getId() + "\n " : "")
130 + (getFrom() != null ? "from: " + getFrom() + "\n " : "")
131 + (getBy() != null ? "by: " + getBy() + "\n " : "")
132 + (getVia() != null ? "via: " + getVia() + "\n " : "")
133 + (getWith() != null ? "with: " + getWith() + "\n " : "")
134 + (getFor() != null ? "for: " + getFor() + "\n " : "") + "date-time: " + getTimestamp()
135 + "\n " + "}";
136 }
137 }