1 /*
2 * Copyright (c) 2005-2007 Creative Sphere Limited.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 *
10 * Creative Sphere - initial API and implementation
11 *
12 */
13 package org.abstracthorizon.mercury.maildir.util;
14
15 import java.io.IOException;
16 import java.io.InputStream;
17 import java.io.OutputStream;
18 import java.util.Date;
19 import java.util.Enumeration;
20 import javax.activation.DataHandler;
21 import javax.mail.Address;
22 import javax.mail.Folder;
23 import javax.mail.IllegalWriteException;
24 import javax.mail.Message;
25 import javax.mail.MessagingException;
26 import javax.mail.Multipart;
27 import javax.mail.Session;
28 import javax.mail.internet.MimeMessage;
29 import javax.mail.search.SearchTerm;
30
31
32 /**
33 * Read only wrapper around message
34 *
35 * @author Daniel Sendula
36 */
37 public class ReadOnlyMessageWrapper extends MessageWrapper {
38
39 /**
40 * Constructor
41 * @param folder folder
42 * @param message wrapped message
43 * @param msgnum message number
44 * @throws MessagingException
45 */
46 protected ReadOnlyMessageWrapper(Folder folder, MimeMessage message, int msgnum) throws MessagingException {
47 super(folder, message, msgnum);
48 }
49
50 /**
51 * Constructor
52 * @param session session
53 * @param message wrapped message
54 * @throws MessagingException
55 */
56 public ReadOnlyMessageWrapper(Session session, MimeMessage message) throws MessagingException {
57 super(session, message);
58 }
59
60 /**
61 * Constructor
62 * @param session session
63 * @throws MessagingException
64 */
65 protected ReadOnlyMessageWrapper(Session session) throws MessagingException {
66 super(session);
67 }
68
69 // ----------------------------------------------------------------------------------
70
71 /**
72 * Adds from address
73 * @param addresses array of addresses
74 * @throws MessagingException
75 * @throws IllegalWriteException always
76 */
77 public void addFrom(Address[] addresses) throws MessagingException {
78 throw new IllegalWriteException("Read only message");
79 }
80
81 /**
82 * Adds new header
83 * @param name header name
84 * @param value value
85 * @throws MessagingException
86 * @throws IllegalWriteException always
87 */
88 public void addHeader(String name, String value) throws MessagingException {
89 throw new IllegalWriteException("Read only message");
90 }
91
92 /**
93 * Adds header line
94 * @param line header line
95 * @throws MessagingException
96 * @throws IllegalWriteException always
97 */
98 public void addHeaderLine(String line) throws MessagingException {
99 throw new IllegalWriteException("Read only message");
100 }
101
102 /**
103 * Adds recipients
104 * @param type recipient type (see {@link javax.mail.Message.RecipientType})
105 * @param addresses addresses
106 * @throws MessagingException
107 * @throws IllegalWriteException always
108 */
109 public void addRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException {
110 throw new IllegalWriteException("Read only message");
111 }
112
113 /**
114 * Adds recipients
115 * @param type recipient type (see {@link javax.mail.Message.RecipientType})
116 * @param addresses addresses
117 * @throws MessagingException
118 * @throws IllegalWriteException always
119 */
120 public void addRecipients(Message.RecipientType type, String addresses) throws MessagingException {
121 throw new IllegalWriteException("Read only message");
122 }
123
124 /**
125 * Returns header lines
126 * @return enumeration
127 * @throws MessagingException
128 */
129 public Enumeration<?> getAllHeaderLines() throws MessagingException {
130 return message.getAllHeaderLines();
131 }
132
133 /**
134 * Returns headers
135 * @return enumeration
136 * @throws MessagingException
137 */
138 public Enumeration<?> getAllHeaders() throws MessagingException {
139 return message.getAllHeaders();
140 }
141
142 /**
143 * Returns all recipients
144 * @return array of addresses
145 * @throws MessagingException
146 */
147 public Address[] getAllRecipients() throws MessagingException {
148 return message.getAllRecipients();
149 }
150
151 /**
152 * Returns content
153 * @return content
154 * @throws IOException
155 * @throws MessagingException
156 */
157 public Object getContent() throws IOException, MessagingException {
158 return message.getContent();
159 }
160
161 /**
162 * Returns content id
163 * @return content id
164 * @throws MessagingException
165 */
166 public String getContentID() throws MessagingException {
167 return message.getContentID();
168 }
169
170 /**
171 * Returns content language
172 * @return content language
173 * @throws MessagingException
174 */
175 public String[] getContentLanguage() throws MessagingException {
176 return message.getContentLanguage();
177 }
178
179 /**
180 * Returns content md3
181 * @return content md
182 * @throws MessagingException
183 */
184 public String getContentMD5() throws MessagingException {
185 return message.getContentMD5();
186 }
187 //
188 // /**
189 // * Returns content stream
190 // * @return content stream
191 // * @throws MessagingException
192 // */
193 // protected InputStream getContentStream() throws MessagingException {
194 // return null;
195 // }
196
197 /**
198 * Returns content type
199 * @return content type
200 * @throws MessagingException
201 */
202 public String getContentType() throws MessagingException {
203 return message.getContentType();
204 }
205
206 /**
207 * Returns data handler
208 * @return data handler
209 * @throws MessagingException
210 */
211 public DataHandler getDataHandler() throws MessagingException {
212 return message.getDataHandler();
213 }
214
215 /**
216 * Returns description
217 * @return description
218 * @throws MessagingException
219 */
220 public String getDescription() throws MessagingException {
221 return message.getDescription();
222 }
223
224 /**
225 * Returns disposition
226 * @return disposition
227 * @throws MessagingException
228 */
229 public String getDisposition() throws MessagingException {
230 return message.getDisposition();
231 }
232
233 /**
234 * Returns encoding
235 * @return encoding
236 * @throws MessagingException
237 */
238 public String getEncoding() throws MessagingException {
239 return message.getEncoding();
240 }
241
242 /**
243 * Returns file name
244 * @return file name
245 * @throws MessagingException
246 */
247 public String getFileName() throws MessagingException {
248 return message.getFileName();
249 }
250
251 /**
252 * Returns from
253 * @return array of from addresses
254 * @throws MessagingException
255 */
256 public Address[] getFrom() throws MessagingException {
257 return message.getFrom();
258 }
259
260 /**
261 * Returns header
262 * @param name name of header
263 * @return array of header values
264 * @throws MessagingException
265 */
266 public String[] getHeader(String name) throws MessagingException {
267 return message.getHeader(name);
268 }
269
270 /**
271 * Returns header
272 * @param name name
273 * @param delimiter delimiter
274 * @return header
275 * @throws MessagingException
276 */
277 public String getHeader(String name, String delimiter) throws MessagingException {
278 return message.getHeader(name, delimiter);
279 }
280
281 /**
282 * Returns input stream
283 * @return input stream
284 * @throws IOException
285 * @throws MessagingException
286 */
287 public InputStream getInputStream() throws IOException, MessagingException {
288 return message.getInputStream();
289 }
290
291 /**
292 * Returns line count
293 * @return line count
294 * @throws MessagingException
295 */
296 public int getLineCount() throws MessagingException {
297 return message.getLineCount();
298 }
299
300 /**
301 * Returns matching header lines
302 * @param names array of names
303 * @return enumeration
304 * @throws MessagingException
305 */
306 public Enumeration<?> getMatchingHeaderLines(String[] names) throws MessagingException {
307 return message.getMatchingHeaderLines(names);
308 }
309
310 /**
311 * Returns matching headers
312 * @param names header names
313 * @return enumeration
314 * @throws MessagingException
315 */
316 public Enumeration<?> getMatchingHeaders(String[] names) throws MessagingException {
317 return message.getMatchingHeaders(names);
318 }
319
320 /**
321 * Returns message id
322 * @return message id
323 * @throws MessagingException
324 */
325 public String getMessageID() throws MessagingException {
326 return message.getMessageID();
327 }
328
329 /**
330 * Returns non matching header lines
331 * @param names array of names
332 * @return enumeration
333 * @throws MessagingException
334 */
335 public Enumeration<?> getNonMatchingHeaderLines(String[] names) throws MessagingException {
336 return message.getNonMatchingHeaderLines(names);
337 }
338
339 /**
340 * Returns non matching headers
341 * @param names header names
342 * @return enumeration
343 * @throws MessagingException
344 */
345 public Enumeration<?> getNonMatchingHeaders(String[] names) throws MessagingException {
346 return message.getNonMatchingHeaders(names);
347 }
348
349 /**
350 * Returns raw input stream
351 * @return raw input stream
352 * @throws MessagingException
353 */
354 public InputStream getRawInputStream() throws MessagingException {
355 return message.getRawInputStream();
356 }
357
358 /**
359 * Returns recipients
360 * @param type recipitents' type
361 * @return array of recipients
362 * @throws MessagingException
363 */
364 public Address[] getRecipients(Message.RecipientType type) throws MessagingException {
365 return message.getRecipients(type);
366 }
367
368 /**
369 * Returns reply to
370 * @return array of recipients
371 * @throws MessagingException
372 */
373 public Address[] getReplyTo() throws MessagingException {
374 return message.getReplyTo();
375 }
376
377 /**
378 * Returns sender
379 * @return sender
380 * @throws MessagingException
381 */
382 public Address getSender() throws MessagingException {
383 return message.getSender();
384 }
385
386 /**
387 * Returns sent date
388 * @return sent date
389 * @throws MessagingException
390 */
391 public Date getSentDate() throws MessagingException {
392 return message.getSentDate();
393 }
394
395 /**
396 * Returns size
397 * @return size
398 * @throws MessagingException
399 */
400 public int getSize() throws MessagingException {
401 return message.getSize();
402 }
403
404 /**
405 * Returns subject
406 * @return subject
407 * @throws MessagingException
408 */
409 public String getSubject() throws MessagingException {
410 return message.getSubject();
411 }
412
413 /**
414 * Returns <code>true</code> if is of supplied mime type
415 * @param mimeType mime type to be checked
416 * @return <code>true</code> if is of supplied mime type
417 * @throws MessagingException
418 */
419 public boolean isMimeType(String mimeType) throws MessagingException {
420 return message.isMimeType(mimeType);
421 }
422
423 /**
424 * Removes header
425 * @param name header's name
426 * @throws MessagingException
427 * @throws IllegalWriteException always
428 */
429 public void removeHeader(String name) throws MessagingException {
430 throw new IllegalWriteException("Read only message");
431 }
432
433 /**
434 * Makes reply message
435 * @param replyToAll should it reply to all
436 * @return new message
437 * @throws MessagingException
438 */
439 public Message reply(boolean replyToAll) throws MessagingException {
440 return message.reply(replyToAll);
441 }
442
443 /**
444 * Saves changes in message
445 * @throws MessagingException
446 * @throws IllegalWriteException always
447 */
448 public void saveChanges() throws MessagingException {
449 throw new IllegalWriteException("Read only message");
450 }
451
452 /**
453 * Sets contnet as multipart
454 * @param mp multipart content
455 * @throws MessagingException
456 * @throws IllegalWriteException always
457 */
458 public void setContent(Multipart mp) throws MessagingException {
459 throw new IllegalWriteException("Read only message");
460 }
461
462 /**
463 * Sets content
464 * @param o content object
465 * @param type mime type
466 * @throws MessagingException
467 * @throws IllegalWriteException always
468 */
469 public void setContent(Object o, String type) throws MessagingException {
470 throw new IllegalWriteException("Read only message");
471 }
472
473 /**
474 * Sets content id
475 * @param cid content id
476 * @throws MessagingException
477 * @throws IllegalWriteException always
478 */
479 public void setContentID(String cid) throws MessagingException {
480 throw new IllegalWriteException("Read only message");
481 }
482
483 /**
484 * Sets languages
485 * @param languages array of language strings
486 * @throws MessagingException
487 * @throws IllegalWriteException always
488 */
489 public void setContentLanguage(String[] languages) throws MessagingException {
490 throw new IllegalWriteException("Read only message");
491 }
492
493 /**
494 * Sets content md5
495 * @param md5 content md5
496 * @throws MessagingException
497 * @throws IllegalWriteException always
498 */
499 public void setContentMD5(String md5) throws MessagingException {
500 throw new IllegalWriteException("Read only message");
501 }
502
503 /**
504 * Sets data handler
505 * @param dh data handler
506 * @throws MessagingException
507 * @throws IllegalWriteException always
508 */
509 public void setDataHandler(DataHandler dh) throws MessagingException {
510 throw new IllegalWriteException("Read only message");
511 }
512
513 /**
514 * Sets description
515 * @param description description
516 * @throws MessagingException
517 * @throws IllegalWriteException always
518 */
519 public void setDescription(String description) throws MessagingException {
520 throw new IllegalWriteException("Read only message");
521 }
522
523 /**
524 * Sets description
525 * @param description description
526 * @param charset character set
527 * @throws MessagingException
528 * @throws IllegalWriteException always
529 */
530 public void setDescription(String description, String charset) throws MessagingException {
531 throw new IllegalWriteException("Read only message");
532 }
533
534 /**
535 * Sets disposition
536 * @param disposition content disposition
537 * @throws MessagingException
538 * @throws IllegalWriteException always
539 */
540 public void setDisposition(String disposition) throws MessagingException {
541 throw new IllegalWriteException("Read only message");
542 }
543
544 /**
545 * Sets file name
546 * @param filename file name
547 * @throws MessagingException
548 * @throws IllegalWriteException always
549 */
550 public void setFileName(String filename) throws MessagingException {
551 throw new IllegalWriteException("Read only message");
552 }
553
554 /**
555 * Sets from
556 * @throws MessagingException
557 * @throws IllegalWriteException always
558 */
559 public void setFrom() throws MessagingException {
560 throw new IllegalWriteException("Read only message");
561 }
562
563 /**
564 * Sets from
565 * @param address from address
566 * @throws MessagingException
567 * @throws IllegalWriteException always
568 */
569 public void setFrom(Address address) throws MessagingException {
570 throw new IllegalWriteException("Read only message");
571 }
572
573 /**
574 * Set header
575 * @param name header name
576 * @param value header value
577 * @throws MessagingException
578 * @throws IllegalWriteException always
579 */
580 public void setHeader(String name, String value) throws MessagingException {
581 throw new IllegalWriteException("Read only message");
582 }
583
584 /**
585 * Sets recipients
586 * @param type recipients' type
587 * @param addresses addresses
588 * @throws MessagingException
589 * @throws IllegalWriteException always
590 */
591 public void setRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException {
592 throw new IllegalWriteException("Read only message");
593 }
594
595 /**
596 * Sets recipients
597 * @param type recipients' type
598 * @param addresses addresses
599 * @throws MessagingException
600 * @throws IllegalWriteException always
601 */
602 public void setRecipients(Message.RecipientType type, String addresses) throws MessagingException {
603 throw new IllegalWriteException("Read only message");
604 }
605
606 /**
607 * Sets reply to address
608 * @param addresses addresses
609 * @throws MessagingException
610 * @throws IllegalWriteException always
611 */
612 public void setReplyTo(Address[] addresses) throws MessagingException {
613 throw new IllegalWriteException("Read only message");
614 }
615
616 /**
617 * Sets sender's address
618 * @param address sender's address
619 * @throws MessagingException
620 * @throws IllegalWriteException always
621 */
622 public void setSender(Address address) throws MessagingException {
623 throw new IllegalWriteException("Read only message");
624 }
625
626 /**
627 * Sets sent date
628 * @param d date
629 * @throws MessagingException
630 * @throws IllegalWriteException always
631 */
632 public void setSentDate(Date d) throws MessagingException {
633 throw new IllegalWriteException("Read only message");
634 }
635
636 /**
637 * Sets subject
638 * @param subject subject
639 * @throws MessagingException
640 * @throws IllegalWriteException always
641 */
642 public void setSubject(String subject) throws MessagingException {
643 throw new IllegalWriteException("Read only message");
644 }
645
646 /**
647 * Sets subject
648 * @param subject subject
649 * @param charset character set
650 * @throws MessagingException
651 * @throws IllegalWriteException always
652 */
653 public void setSubject(String subject, String charset) throws MessagingException {
654 throw new IllegalWriteException("Read only message");
655 }
656
657 /**
658 * Sets body as text
659 * @param text body text
660 * @throws MessagingException
661 * @throws IllegalWriteException always
662 */
663 public void setText(String text) throws MessagingException {
664 throw new IllegalWriteException("Read only message");
665 }
666
667 /**
668 * Sets body as text
669 * @param text body text
670 * @param charset character set
671 * @throws MessagingException
672 * @throws IllegalWriteException always
673 */
674 public void setText(String text, String charset) throws MessagingException {
675 throw new IllegalWriteException("Read only message");
676 }
677
678 /**
679 * Updates headers
680 * @throws MessagingException
681 * @throws IllegalWriteException always
682 */
683 protected void updateHeaders() throws MessagingException {
684 throw new IllegalWriteException("Read only message");
685 }
686
687 /**
688 * Writes content of the message to output stream
689 * @param os output stream
690 * @throws IOException
691 * @throws MessagingException
692 */
693 public void writeTo(OutputStream os) throws IOException, MessagingException {
694 message.writeTo(os);
695 }
696
697 /**
698 * Writes content of the message to output stream ignoring supplied headers
699 * @param os output stream
700 * @param ignoreList array of headers to be ignored
701 * @throws IOException
702 * @throws MessagingException
703 */
704 public void writeTo(OutputStream os, String[] ignoreList) throws IOException, MessagingException {
705 message.writeTo(os, ignoreList);
706 }
707
708 /**
709 * Adds new recipient to the message
710 * @param type recipient type
711 * @param address address
712 * @throws MessagingException
713 * @throws IllegalWriteException always
714 */
715 public void addRecipient(Message.RecipientType type, Address address) throws MessagingException {
716 throw new IllegalWriteException("Read only message");
717 }
718
719 /**
720 * Matches message
721 * @param term term to be used for matching
722 * @return <code>true</code> if matched
723 * @throws MessagingException
724 */
725 public boolean match(SearchTerm term) throws MessagingException {
726 return message.match(term);
727 }
728
729 /**
730 * Sets recipient to the message
731 * @param type recipient type
732 * @param address address
733 * @throws MessagingException
734 * @throws IllegalWriteException always
735 */
736 public void setRecipient(Message.RecipientType type, Address address) throws MessagingException {
737 throw new IllegalWriteException("Read only message");
738 }
739
740 }