📄 emailexecutor.java
字号:
IOException { String subject = this.subjectTemplate; Timestamp expiryTimestamp = getExpiryTimestamp(methodName); String messageId = createMessageId(msgInfo, requestId, methodName, expiryTimestamp); if (subject != null && subject.length() > 0) { // Transport messageId in subject if token "${xmlBlaster/email/messageId}" is present: // The responseQos gets it already replaced and the messageId remains same (which we must assure) subject = ReplaceVariable.replaceFirst(subject, SUBJECT_MESSAGEID_TOKEN, messageId); // and for testing as attachment, for example this.messageIdFileName="messageId.mid" } // Serialize the pay load byte[] origAttachment = msgInfo.getMsgInfoParser(getMsgInfoParserClassName(), pluginConfig).createRawMsg(msgInfo); boolean isCompressed = false; byte[] payload = origAttachment; if (isCompressZlib()) { if (origAttachment.length > getMinSizeForCompression()) { // > 0 this.compressor.reset(); this.compressor.setInput(origAttachment, 0, origAttachment.length); this.compressor.finish(); payload = new byte[origAttachment.length+64]; int compSize = compressor.deflate(payload); if (compSize <= 0) { throw new IOException("Compression exception, got 0 bytes output: " + MsgInfo.toLiteral(msgInfo.createRawMsg(getMsgInfoParserClassName()))); } if (compSize >= origAttachment.length) { // Compression didn't help payload = origAttachment; if (log.isLoggable(Level.FINE)) log.fine("No compression of attachment as size increased from " + origAttachment.length + " to " + compSize + ", we leave it uncompressed"); } else { isCompressed = true; byte[] tmp = new byte[compSize]; System.arraycopy(payload, 0, tmp, 0, compSize); payload = tmp; if (log.isLoggable(Level.FINE)) log.fine("Compressing attachment of size " + origAttachment.length + " to length " + payload.length); } } else { if (log.isLoggable(Level.FINE)) log.fine("Compressing of attachment skipped as size of " + origAttachment.length + " is smaller minSize " + getMinSizeForCompression()); } } // The real message blob, for example "xmlBlasterMessage.xbf" String payloadFileName = this.payloadFileNamePrefix + msgInfo.getMsgInfoParser(getMsgInfoParserClassName(), pluginConfig).getExtension(isCompressed); InternetAddress toAddr = this.toAddress; String to = (String)msgInfo.getBounceObject(BOUNCE_MAILTO_KEY); if (to != null) { try { // The EmailDriver has different destinations for each client toAddr = new InternetAddress(to); } catch (AddressException e) { log.warning("Illegal 'to' address '" + to + "'"); } } if (toAddr == null) { Thread.dumpStack(); throw new IllegalArgumentException("No 'toAddress' email address is given, can't send mail: " + MsgInfo.toLiteral(msgInfo.createRawMsg(getMsgInfoParserClassName()))); } EmailData emailData = new EmailData(toAddr, this.fromAddress, subject); emailData.setCc(this.cc); emailData.setBcc(this.bcc); emailData.setExpiryTime(expiryTimestamp); String payloadMimetype = msgInfo.getMsgInfoParser(getMsgInfoParserClassName(), pluginConfig).getMimetype(isCompressed); emailData.addAttachment(new AttachmentHolder(payloadFileName, payloadMimetype, payload)); emailData.addAttachment(new AttachmentHolder(this.messageIdFileName, messageId)); // Bounce all other attachments back to sender AttachmentHolder[] attachments = msgInfo.getBounceAttachments(); for (int i=0; i<attachments.length; i++) { AttachmentHolder a = attachments[i]; if (this.messageIdFileName.equals(a.getFileName())) continue; // added alread, see above emailData.addAttachment(a); } getSmtpClient().sendEmail(emailData); //this.smtpClient.sendEmail(this.fromAddress, toAddr, subject, // attachmentName, attachment, attachmentName2, messageId, // Constants.UTF8_ENCODING); if (log.isLoggable(Level.FINE)) log.fine("Sending email from=" + this.fromAddress.toString() + " to=" + toAddr.toString() + " messageId=" + messageId + " done"); if (log.isLoggable(Level.FINEST)) log.finest("MsgInfo dump: " + MsgInfo.toLiteral(msgInfo.createRawMsg(getMsgInfoParserClassName()))); } /** * The oneway variant, without return value. * * @exception XmlBlasterException * Is never from the client (oneway). */ public void sendUpdateOneway(MsgUnitRaw[] msgArr) throws XmlBlasterException { log.warning("Email sendUpdateOneway is not supported, request ignored"); } /** * Ping to check if callback server is alive. This ping checks the * availability on the application level. * * @param qos * Currently an empty string "" * @return Currently an empty string "" * @exception XmlBlasterException * If client not reachable */ public String ping(String qos) throws XmlBlasterException { log.warning("Email ping is not supported, request ignored"); return ""; } /** * This method shuts down the driver. * <p /> */ public void shutdown() { this.isShutdown = true; synchronized (this.senderLoopProtectionMap) { this.senderLoopProtectionMap.clear(); } try { getPop3Driver().deregisterForEmail(this); } catch (XmlBlasterException e) { e.printStackTrace(); } } /** I_AdminPlugin#isShutodwn */ public boolean isShutdown() { return this.isShutdown; } /** * @return true if the plugin is still alive, false otherwise */ public boolean isAlive() { return true; } /** * @return Returns the secretSessionId. */ public String getSecretSessionId() { return this.secretSessionId; } /** * @param secretSessionId * The secretSessionId to set. */ public void setSecretSessionId(String secretSessionId) { this.secretSessionId = secretSessionId; } /** * The sessionId used to register at Pop3Driver and send in subject: of email * @return Usually the clients relative login sessionName "client/joe/3", never null */ public String getEmailSessionId() { return (this.emailSessionId == null) ? "" : this.emailSessionId; } /** * Is overwritten for example by EmailDriver.java singleton. * @param msgInfo * @return */ public String getEmailSessionId(MsgInfo msgInfo) { return getEmailSessionId(); } public void setEmailSessionId(String emailSessionId) { this.emailSessionId = emailSessionId; } /** * Email protocol contract with server side CallbackEmailDriver.java and client side EmailCallbackImpl.java * We use <messageId><sessionId>joe/2</sessionId>... * to find our response again. If no positive sessionId * is given, the server generates e.g. -7 for us which we don't know * In this case we use <messageId><sessionId>joe</sessionId>... only */ protected void setEmailSessionId(SessionName sessionName) { if (sessionName == null) { log.severe("setEmailSessionId() is called with null sessionName"); return; } if (sessionName.isPubSessionIdUser()) setEmailSessionId(sessionName.getRelativeName()); else { log.warning("The current email callback implementation can handle max one connection per email account (like 'joe' on the POP3 server) if you don't supply a positive sessionId"); setEmailSessionId(sessionName.getLoginName()); } } /** * @return Returns the cc. */ public String getCc() { return this.cc; } /** * Send all emails additionally to the given CC addresses. * You can pass a comma separated list of addresses. * @param cc The copy addresses, for example "joe@localhost,jack@localhost" */ public void setCc(String cc) { this.cc = cc; } /** JMX */ public void setTo(String to) throws IllegalArgumentException { try { this.toAddress = new InternetAddress(to); } catch (AddressException e) { throw new IllegalArgumentException( ME + " Illegal 'to' address '" + to + "'"); } } /** * @return Returns the 'to' email address. */ public String getTo() { return (this.toAddress == null) ? "" : this.toAddress.toString(); } /** JMX */ public void setFrom(String from) throws IllegalArgumentException { try { this.fromAddress = new InternetAddress(from); } catch (AddressException e) { throw new IllegalArgumentException( ME + " Illegal 'from' address '" + from + "'"); } } /** * @return Returns the 'from' email address. */ public String getFrom() { return (this.fromAddress == null) ? "" : this.fromAddress.toString(); } /** * @return Returns the blind copy email addresses or null */ public String getBcc() { return this.bcc; } /** * Send all emails additionally to the given bcc. * You can pass a comma separated list of addresses. * @param bcc The blind copy addresses, for example "joe@localhost,jack@localhost" */ public void setBcc(String bcc) { this.bcc = bcc; } /** * @return a human readable usage help string */ public java.lang.String usage() { return super.usage() + "\n" + Global.getJmxUsageLinkInfo(this.getClass().getName(), null); } /** * @return A link for JMX usage */ public java.lang.String getUsageUrl() { return Global.getJavadocUrl(this.getClass().getName(), null); } /* dummy to have a copy/paste functionality in jconsole */ public void setUsageUrl(java.lang.String url) { }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -