1 25 26 package net.killingar.forum.actions.area; 27 28 import net.killingar.Utils; 29 import net.killingar.forum.internal.Message; 30 import net.killingar.forum.internal.managers.AreaManager; 31 import net.killingar.forum.internal.managers.ForumManager; 32 import webwork.action.ServletActionContext; 33 34 import javax.imageio.ImageIO ; 35 import java.awt.geom.AffineTransform ; 36 import java.awt.image.AffineTransformOp ; 37 import java.awt.image.BufferedImage ; 38 import java.io.File ; 39 import java.util.Properties ; 40 41 public class EmailPostMessage extends net.killingar.actions.email.List 42 { 43 45 String storePath; 47 long areaID = -1; 48 ForumManager manager; 49 java.text.SimpleDateFormat dateFormat = new java.text.SimpleDateFormat ("yyyy-MM-dd HH:mm:ss"); 50 51 53 public void setStorePath(String in) { storePath = in; } 55 public void setManager(ForumManager in) { manager = in; } 56 public void setAreaID(long in) { areaID = in; } 57 58 public String doExecute() 60 { 61 try 62 { 63 System.err.println("executing EmailPostMessage"); 64 65 if (ServletActionContext.getServletContext() == null) 66 { 67 Properties prop = Utils.getProperties(); 68 69 manager = new ForumManager(); 70 manager.login((String )prop.get("net.killingar.forum.username"), (String )prop.get("net.killingar.forum.password")); 71 } 72 73 if (super.doExecute() == ERROR) 74 return ERROR; 75 76 AreaManager areamgr = (AreaManager)manager.getManager(AreaManager.class.getName()); 77 78 File dir = new File (storePath); 79 80 for (int j = 0; j != getMessages().size(); j++) 81 { 82 Message message = new Message(); 83 message.body = ""; 84 85 javax.mail.Message m = ((net.killingar.actions.email.Mail)getMessages().get(j)).getMessage(); 86 87 if (m.getContent() instanceof String && m.getContent() != null) 88 message.body += "body:\n"+m.getContent()+"\n"; 89 if (m.getSubject() != null) 90 message.body += "subject:\n"+m.getSubject()+"\n"; 91 92 if (m.getContent() instanceof javax.mail.internet.MimeMultipart ) 93 { 94 javax.mail.internet.MimeMultipart foo = (javax.mail.internet.MimeMultipart )m.getContent(); 95 for (int i = 0; i != foo.getCount(); i++) 96 { 97 javax.mail.Part part = foo.getBodyPart(i); 98 99 if (part.isMimeType("image/jpeg") || part.isMimeType("image/gif") || part.isMimeType("image/png")) { 101 String name = part.getFileName(); 102 String extension = ""; 103 try 104 { 105 extension = name.substring(name.lastIndexOf('.')); 106 name = name.substring(0, name.lastIndexOf('.')); 107 } 108 catch (IndexOutOfBoundsException e){} 109 110 java.io.File file = new java.io.File (dir, part.getFileName()); 112 if (file.exists()) 113 { 114 file = java.io.File.createTempFile(name+"-", extension, dir); 115 } 116 else 117 file.createNewFile(); 118 119 if (name.charAt(name.length()-1) == 'l') 121 { 122 BufferedImage bimage = ImageIO.read(part.getInputStream()); 123 124 BufferedImage rotatedImage = new BufferedImage (bimage.getHeight(), bimage.getWidth(), bimage.getType()); 125 126 AffineTransform transform = AffineTransform.getRotateInstance(-Math.PI/2); 127 transform.translate(-bimage.getWidth(), 0); 128 129 AffineTransformOp op = 130 new AffineTransformOp ( 131 transform, 132 AffineTransformOp.TYPE_BILINEAR); 133 134 op.filter(bimage, rotatedImage); 135 bimage.flush(); 136 137 ImageIO.write(rotatedImage, "jpg", file); 138 } 139 else 140 { 141 java.io.OutputStream out = new java.io.FileOutputStream (file); 143 Utils.writeStreamToStream(part.getInputStream(), out); 144 out.close(); 145 } 146 147 message.body += "image:\n"+file.getName()+"\n"; 148 } 149 else if (part.isMimeType("text/plain") && part.getFileName() != null) { 151 message.body += part.getFileName()+":\n"+SignGuestbook.escape(part.getContent().toString())+"\n"; 152 } 153 else if (part.isMimeType("text/plain") && part.getDescription() != null) { 155 message.body += part.getDescription()+":\n"+SignGuestbook.escape(part.getContent().toString())+"\n"; 156 } 157 } 158 } 159 else 160 { 161 message.body = m.getContent().toString(); 162 } 163 164 message.subject = dateFormat.format(m.getSentDate()); 165 message.areaID = areaID; 166 167 areamgr.addMessage(message); 169 170 m.setFlag(javax.mail.Flags.Flag.DELETED, true); 172 } 173 174 try 175 { 176 System.err.println("net.killingar.forum.actions.area.EmailPostMessage: deleted "+getFolder().expunge().length+" messages"); 177 } 178 catch (javax.mail.MethodNotSupportedException e){} } 180 catch (Exception e) 181 { 182 e.printStackTrace(); 183 return ERROR; 184 } 185 186 return SUCCESS; 187 } 188 } 189 | Popular Tags |