2 |
import gzz.*; |
import gzz.*; |
3 |
import gzz.media.*; |
import gzz.media.*; |
4 |
import gzz.zzutil.*; |
import gzz.zzutil.*; |
5 |
|
import java.util.*; |
6 |
|
|
7 |
public class EmailCellMaker { |
public class EmailCellMaker { |
8 |
|
|
9 |
public void makeCells(EmailInStorm mail,Space space) { |
static Comparator |
10 |
Cell home = space.getHomeCell(); |
stringCmp = new StringCmp(), |
11 |
|
dateCmp = new DateCmp(); |
12 |
Cell subjectList = space.getCell(Ids.c_email_subject); |
|
13 |
Cell fromList = space.getCell(Ids.c_email_from); |
public void makeCells(EmailInStorm mail,Space space) { |
14 |
Cell toList = space.getCell(Ids.c_email_to); |
Cell home = space.getHomeCell(); |
15 |
Cell dateList = space.getCell(Ids.c_email_date); |
|
16 |
Cell bodyList = space.getCell(Ids.c_email_body); |
Cell subjectList = space.getCell(Ids.c_email_subject); |
17 |
|
Cell fromList = space.getCell(Ids.c_email_from); |
18 |
Dim d_email =space.getDim(Ids.d_email); |
Cell toList = space.getCell(Ids.c_email_to); |
19 |
Dim d_2 = space.getDim(Ids.d_2); |
Cell dateList = space.getCell(Ids.c_email_date); |
20 |
Dim d_contain = space.getDim(Ids.d_contain); |
Cell bodyList = space.getCell(Ids.c_email_body); |
21 |
Dim d_contain_list = space.getDim(Ids.d_contain_list); |
|
22 |
|
Dim d_email =space.getDim(Ids.d_email); |
23 |
Cell c = home.N(d_email,1); |
//Dim d_2 = space.getDim(Ids.d_2); |
24 |
|
Dim d_contain = space.getDim(Ids.d_contain); |
25 |
Cell subCell = c.N(d_contain,1); |
Dim d_contain_list = space.getDim(Ids.d_contain_list); |
26 |
Enfilade1D subText = mail.getSubject(); |
|
27 |
((VStreamCellTexter)space.getCellTexter()).setEnfilade(subCell, subText); |
Cell c = home.N(d_email,1); |
28 |
subCell.insertText(0, "Subject: "); |
|
29 |
subCell.insertText(subCell.t().length(),"\n"); |
Cell subCell = c.N(d_contain,1); |
30 |
sortCell(d_2, subCell, subjectList); |
Enfilade1D subText = mail.getSubject(); |
31 |
|
((VStreamCellTexter)space.getCellTexter()).setEnfilade(subCell, subText); |
32 |
Cell fromCell = subCell.N(d_contain_list,1); |
subCell.insertText(0, "Subject: "); |
33 |
Enfilade1D fromText = mail.getFrom(); |
subCell.insertText(subCell.t().length(),"\n"); |
34 |
((VStreamCellTexter)space.getCellTexter()).setEnfilade(fromCell, fromText); |
sortCell(d_email, subCell, subjectList, stringCmp); |
35 |
fromCell.insertText(0, "From: "); |
|
36 |
fromCell.insertText(fromCell.t().length(), "\n"); |
Cell fromCell = subCell.N(d_contain_list,1); |
37 |
sortCell(d_2, fromCell, fromList); |
Enfilade1D fromText = mail.getFrom(); |
38 |
|
((VStreamCellTexter)space.getCellTexter()).setEnfilade(fromCell, fromText); |
39 |
Cell toCell = fromCell.N(d_contain_list,1); |
fromCell.insertText(0, "From: "); |
40 |
Enfilade1D toText = mail.getTo(); |
fromCell.insertText(fromCell.t().length(), "\n"); |
41 |
((VStreamCellTexter)space.getCellTexter()).setEnfilade(toCell, toText); |
sortCell(d_email, fromCell, fromList, stringCmp); |
42 |
toCell.insertText(0, "To: "); |
|
43 |
toCell.insertText(toCell.t().length(), "\n"); |
Cell toCell = fromCell.N(d_contain_list,1); |
44 |
sortCell(d_2, toCell, toList); |
Enfilade1D toText = mail.getTo(); |
45 |
|
((VStreamCellTexter)space.getCellTexter()).setEnfilade(toCell, toText); |
46 |
Cell dateCell = toCell.N(d_contain_list,1); |
toCell.insertText(0, "To: "); |
47 |
Enfilade1D dateText = mail.getDate(); |
toCell.insertText(toCell.t().length(), "\n"); |
48 |
((VStreamCellTexter)space.getCellTexter()).setEnfilade(dateCell, dateText); |
sortCell(d_email, toCell, toList, stringCmp); |
49 |
dateCell.insertText(0, "Date: "); |
|
50 |
dateCell.insertText(dateCell.t().length(), "\n\n"); |
Cell dateCell = toCell.N(d_contain_list,1); |
51 |
sortCell(d_2, dateCell, dateList); |
Enfilade1D dateText = mail.getDate(); |
52 |
|
((VStreamCellTexter)space.getCellTexter()).setEnfilade(dateCell, dateText); |
53 |
Cell bodyCell = dateCell.N(d_contain_list,1); |
dateCell.insertText(0, "Date: "); |
54 |
Enfilade1D bodyText = mail.getBody(); |
dateCell.insertText(dateCell.t().length(), "\n\n"); |
55 |
((VStreamCellTexter)space.getCellTexter()).setEnfilade(bodyCell, bodyText); |
sortCell(d_email, dateCell, dateList, dateCmp); |
56 |
sortCell(d_2, bodyCell, bodyList); |
|
57 |
} |
Cell bodyCell = dateCell.N(d_contain_list,1); |
58 |
|
Enfilade1D bodyText = mail.getBody(); |
59 |
public void sortCell(Dim d_2, Cell start, Cell list){ |
((VStreamCellTexter)space.getCellTexter()).setEnfilade(bodyCell, bodyText); |
60 |
String s1 = start.t().toLowerCase(); |
bodyList.insert(d_email, 1, bodyCell); |
61 |
Cell d = list.s(d_2,1); |
} |
62 |
if(d==null){ |
|
63 |
start.connect(d_2,-1,list); |
public void sortCell(Dim d_email, Cell start, Cell list, Comparator cmp) { |
64 |
|
Cell d = list.s(d_email,1); |
65 |
|
if(d==null){ |
66 |
|
start.connect(d_email,-1,list); |
67 |
|
} |
68 |
|
else{ |
69 |
|
while(d != null){ |
70 |
|
int j = cmp.compare(start, d); |
71 |
|
if(j<=0){ |
72 |
|
d.insert(d_email,-1,start); |
73 |
|
break; |
74 |
} |
} |
75 |
else{ |
else{ |
76 |
while(d != null){ |
if(d.s(d_email,1)==null){ |
77 |
String s2 = d.t().toLowerCase(); |
start.connect(d_email,-1,d); |
78 |
int j = s1.compareTo(s2); |
break; |
79 |
if(j<=0){ |
} |
80 |
d.insert(d_2,-1,start); |
else{ |
81 |
d = null; |
d = d.s(d_email,1); |
82 |
} |
} |
|
else{ |
|
|
if(d.s(d_2,1)==null){ |
|
|
start.connect(d_2,-1,d); |
|
|
d = null; |
|
|
} |
|
|
else{ |
|
|
d = d.s(d_2,1); |
|
|
} |
|
|
} |
|
|
} |
|
83 |
} |
} |
84 |
|
} |
85 |
|
} |
86 |
|
} |
87 |
|
|
88 |
|
protected static class StringCmp implements Comparator { |
89 |
|
public int compare(Object o1, Object o2) { |
90 |
|
Cell c1 = (Cell)o1, c2 = (Cell)o2; |
91 |
|
String |
92 |
|
s1 = c1.t().toLowerCase(), |
93 |
|
s2 = c2.t().toLowerCase(); |
94 |
|
|
95 |
|
if(s1.startsWith("re: ")) s1 = s1.substring(4); |
96 |
|
if(s2.startsWith("re: ")) s1 = s1.substring(4); |
97 |
|
|
98 |
|
/*if(s1.indexOf('<') > 0 && s1.indexOf('@') > 0) |
99 |
|
s1 = s1.substring(s1.indexOf('<')+1); |
100 |
|
if(s2.indexOf('<') > 0 && s2.indexOf('@') > 0) |
101 |
|
s2 = s2.substring(s1.indexOf('<')+1);*/ |
102 |
|
|
103 |
|
return s1.compareTo(s2); |
104 |
|
} |
105 |
|
} |
106 |
|
|
107 |
|
protected static class DateCmp implements Comparator { |
108 |
|
public int compare(Object o1, Object o2) { |
109 |
|
Cell c1 = (Cell)o1, c2 = (Cell)o2; |
110 |
|
|
111 |
|
String |
112 |
|
s1 = c1.t().toLowerCase().substring(6).trim(), |
113 |
|
s2 = c2.t().toLowerCase().substring(6).trim(); |
114 |
|
|
115 |
|
//System.out.println(s1+" ------- "+s2); |
116 |
|
|
117 |
|
Date d1, d2; |
118 |
|
try { |
119 |
|
d1 = new Date(s1); |
120 |
|
} catch(IllegalArgumentException _) { |
121 |
|
d1 = null; |
122 |
|
} |
123 |
|
|
124 |
|
try { |
125 |
|
d2 = new Date(s2); |
126 |
|
} catch(IllegalArgumentException _) { |
127 |
|
d2 = null; |
128 |
|
} |
129 |
|
|
130 |
|
if(d1 == null && d2 == null) return 0; |
131 |
|
else if(d1 == null) return 1; |
132 |
|
else if(d2 == null) return -1; |
133 |
|
|
134 |
|
return d1.compareTo(d2); |
135 |
} |
} |
136 |
|
} |
137 |
} |
} |