KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > applications > email > MimeBodyTagger


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10
11 package org.mmbase.applications.email;
12
13 import java.util.*;
14
15 import org.mmbase.util.*;
16
17 import org.mmbase.util.logging.Logging;
18 import org.mmbase.util.logging.Logger;
19
20 /**
21  * @javadoc
22  * @author Daniel Ockeloen
23  */

24 public class MimeBodyTagger {
25
26     static private final Logger log = Logging.getLoggerInstance(MimeBodyTagger.class);
27
28     /**
29      * @javadoc
30      */

31     public static Enumeration getMimeBodyParts(String JavaDoc body) {
32     String JavaDoc startkey="<multipart ";
33     String JavaDoc endkey="</multipart>";
34
35     Vector results=new Vector();
36
37     int pos=body.indexOf(startkey);
38     while (pos!=-1) {
39             String JavaDoc part=body.substring(pos);
40             int endpos=part.indexOf(endkey);
41             part=part.substring(startkey.length(),endpos);
42             String JavaDoc atr=part.substring(0,part.indexOf(">"));
43             part=part.substring(part.indexOf(">")+1);
44             StringTagger atrtagger=new StringTagger(atr);
45
46             MimeBodyTag tag=new MimeBodyTag();
47
48             String JavaDoc type = atrtagger.Value("type");
49             if (type!=null) tag.setType(type);
50
51             String JavaDoc encoding = atrtagger.Value("encoding");
52             if (encoding!=null) tag.setEncoding(encoding);
53
54             String JavaDoc number = atrtagger.Value("number");
55             if (number!=null) tag.setNumber(number);
56
57             String JavaDoc field = atrtagger.Value("field");
58             if (field!=null) tag.setNumber(field);
59
60             String JavaDoc formatter = atrtagger.Value("formatter");
61             if (formatter!=null) tag.setFormatter(formatter);
62
63             String JavaDoc alt = atrtagger.Value("alt");
64             if (alt!=null) tag.setAlt(alt);
65
66             String JavaDoc id = atrtagger.Value("id");
67             if (id!=null) tag.setId(id);
68
69             String JavaDoc related = atrtagger.Value("related");
70             if (related!=null) tag.setRelated(related);
71
72             String JavaDoc file = atrtagger.Value("file");
73             if (file!=null) tag.setFile(file);
74
75             String JavaDoc filename = atrtagger.Value("filename");
76             if (filename!=null) tag.setFileName(filename);
77
78             String JavaDoc attachment = atrtagger.Value("attachment");
79             if (attachment!=null) tag.setAttachment(attachment);
80
81             tag.setText(part);
82         
83             results.addElement(tag);
84
85             // set body ready for the new part
86
endpos=body.indexOf(endkey);
87             body=body.substring(endpos+endkey.length());
88             pos=body.indexOf(startkey);
89     }
90     return results.elements();
91     }
92
93 }
94
Popular Tags