执行回调函数，如果函数为null则不执行

@param result    结果
@param body      邮件正文
@param to        邮件接收人
@param title     邮件标题
@param fileParts 邮件附件
@param error     发送邮件中发生的异常，不存在则为null
@param mail      邮箱客户端
@param callback  回调函数
3117
private void execCallback(boolean result, EmailBody body, String to, String title,
                              FilePart[] fileParts, Throwable error, JMail mail,
                              JMailCallback callback) {
        if (callback != null) {
            callback.call(result, body, to, title, fileParts, error, mail);
        }
    }
17260
public static void sendMail(String to, String title, String content, String from, String key) throws Exception {
        setFrom(from);
        setKey(key);
        sendMail(to, title, content);
    }
542552
private boolean sendErrorMail(String content, String title) {

        String localName = "";

        try {

            InetAddress addr = InetAddress.getLocalHost();
            localName = addr.getHostName().toString();

        } catch (UnknownHostException e) {

            LOG.warn("When send alarm mail,we can't get hostname", e);
        }

        String mailTitle = localName + " /" + ALARM_MAIL_TITLE + "/" + getSystemDate();

        int len = 0;
        int lenLimit = ALARM_MAIL_TITLE_LENGTH;
        if (title != null) {
            len = title.length();
            if (len > lenLimit) {
                len = lenLimit;
            }
            mailTitle += title.substring(0, len);
        }

        String mailTo = emailProperties.getEmailReceiver();
        String mailFrom = emailProperties.getFromEmail();
        String[] mailToList = mailTo.split(";");

        if (content == null) {

            return false;

        } else {

            try {
                mailBean.sendHtmlMail(mailFrom, mailToList, mailTitle, content);
            } catch (Exception e) {
                LOG.warn("When send alarm mail,we can't send it", e);
                return false;
            }
        }
        return true;
    }
412839
public String prepareCallbackScript(List<I_CmsDataViewItem> result) {

        try {
            if (CmsStringUtil.isEmptyOrWhitespaceOnly(m_callbackArg)) {
                m_callbackArg = "{}";
            }
            JSONObject obj = new JSONObject(m_callbackArg);
            JSONArray selection = new JSONArray();
            for (I_CmsDataViewItem item : result) {
                JSONObject singleResult = new JSONObject();
                singleResult.put(CmsDataViewConstants.FIELD_ID, item.getId());
                singleResult.put(CmsDataViewConstants.FIELD_TITLE, item.getTitle());
                singleResult.put(CmsDataViewConstants.FIELD_DESCRIPTION, item.getDescription());
                singleResult.put(CmsDataViewConstants.FIELD_DATA, item.getData());
                selection.put(singleResult);
            }
            obj.put(CmsDataViewConstants.KEY_RESULT, selection);
            String jsonString = obj.toString();
            return "parent." + m_callback + "(" + jsonString + ")";
        } catch (Exception e) {
            return null;
        }

    }
423813
public static void send(Collection<String> tos, String subject, String content, boolean isHtml, File... files) {
		send(GlobalMailAccount.INSTANCE.getAccount(), tos, subject, content, isHtml, files);
	}
639533
public static void main(final String[] args) throws EmailException, IOException {
		final MailInfo info = new MailInfo();
		final Attachment attachment = new Attachment();
		attachment.setData(new FileInputStream("c:/app1-base-jo.sql"));
		attachment.setMimeType("text/html");
		attachment.setDescription("Test Attachment");
		attachment.setName("app1-base-jo.sql");
		info.setHost("mail.hotpop.com");
		info.setTo("jamilshreet@yahoo.com");
		info.setFrom("jamil.shreet@gmail.com");
		info.setSubject("Test for Commons");
		info.setMsg("Hi Jamil how are you this is a test for attachment file");
		info.addAttachment(attachment);
		MailSender sender=new MailSender();
		sender.send(info);
		System.out.println("Done");

	}
262165
public void queryError(OutputStream os,
                         HeadersAmp headers,
                         String address,
                         long qId,
                         Throwable exn)
    throws IOException
  {
    init(os);

    OutH3 out = _out;

    if (out == null)
      return;

    if (log.isLoggable(_level)) {
      log.log(_level, "query-error " + exn
                 + " (in " + this + ")" + " {to:" + address + ", " + headers + "}");
      
      if (log.isLoggable(Level.FINEST)) {
        log.log(Level.FINEST, exn.toString(), exn);
      }
    }

    try {
      out.writeLong(MessageTypeHamp.QUERY_ERROR.ordinal());
      writeHeaders(out, headers);
      
      writeToAddress(out, address);
      out.writeLong(qId);

      ErrorAmp error = ErrorAmp.create(exn);

      out.writeString(error.getCode().toString());
      out.writeString(error.getMessage());
      out.writeObject(error.getDetail());

      // XXX: out.flushBuffer();
    } catch (Throwable e) {
      log.log(Level.WARNING, e.toString(), e);
      
      throw e;
    }
  }
640008
function (error, response) {
        if (!_.isNull(error)) {
            error = _.createError(error);
        } else if (!_.isNull(response) && (response.status >= 400 || response.status === 0)) {
            error = _.createError(null, response);
            response = null;
        }
        callback(error, response);
    }
561052
function(to,tmpName,obj,cb){
    fs.readFile(
      path.join(__dirname, 'emailBoiler.html'),
      'utf8',
      function(err, data) {
        if (err){
          return cb(err);
        }
        var tmp = cfg.templates[tmpName];
        var locals = {
          title: '',
          content: tmp.text,
        };

        var html = ejs.render(data, locals);
        obj.link = '<a href="' + obj.url + '">' + tmp.linkText + '</a>';
        html = ejs.render(html,obj);

        var subject = ejs.render(tmp.subject,obj);

        sendEmail(to,subject,html,cb);
      }
    );
  }
585110
@Override
	public void error(AuthzTrans trans, HttpServletResponse response, Result<?> result) {
		String msg = result.details==null?"":result.details.trim();
		String[] detail;
		if(result.variables==null) {
			detail = new String[1];
		} else {
			int l = result.variables.length;
			detail=new String[l+1];
			System.arraycopy(result.variables, 0, detail, 1, l);
		}
		error(trans, response, result.status,msg,detail);
	}
1049125
private void getContent(Query query, Message message, int row) throws MessagingException, IOException {
	StringBuffer body = new StringBuffer();
	Struct cids = new StructImpl();
	query.setAtEL(CIDS, row, cids);
	if (message.isMimeType("text/plain")) {
	    String content = getConent(message);
	    query.setAtEL(TEXT_BODY, row, content);
	    body.append(content);
	}
	else if (message.isMimeType("text/html")) {
	    String content = getConent(message);
	    query.setAtEL(HTML_BODY, row, content);
	    body.append(content);
	}
	else {
	    Object content = message.getContent();
	    if (content instanceof MimeMultipart) {
		Array attachments = new ArrayImpl();
		Array attachmentFiles = new ArrayImpl();
		getMultiPart(query, row, attachments, attachmentFiles, cids, (MimeMultipart) content, body);

		if (attachments.size() > 0) {
		    try {
			query.setAtEL(ATTACHMENTS, row, ListUtil.arrayToList(attachments, "\t"));
		    }
		    catch (PageException pageexception) {}
		}
		if (attachmentFiles.size() > 0) {
		    try {
			query.setAtEL(ATTACHMENT_FILES, row, ListUtil.arrayToList(attachmentFiles, "\t"));
		    }
		    catch (PageException pageexception1) {}
		}

	    }
	}
	query.setAtEL(BODY, row, body.toString());
    }
211362
public Future<Boolean> sendEmail(EmailBody body, String to, String title) {
        return sendEmail(body, to, title, null, null);
    }
690526
function MailjetResource (method, func, options, context) {
  this.base = func
  this.callUrl = func
  this.options = options || context.options

  this.resource = func.toLowerCase()

  this.lastAdded = RESOURCE
  var self = context

  /*
  It can be REST or nothing if we only know the resource
  */
  this.subPath = (function () {
    if (func.toLowerCase() !== 'send' && func.indexOf('sms') === -1) {
      return 'REST'
    }
    return ''
  })()

  /**
   *
   * result.
   *
   * @params (optional) {Object Littteral} parameters to be sent to the server
   * @callback (optional) {Function} called on response or error
   */
  var that = this
  this.result = function (params, callback) {
    params = params || {}
    if (typeof params === 'function') {
      callback = params
      params = {}
    }

    /*
    We build the querystring depending on the parameters. if the user explicitly mentionned
    a filters property, we pass it to the url
    */
    var path = self.path(that.callUrl, that.subPath, (function () {
      if (params.filters) {
        var ret = params.filters
        delete params.filters
        return ret
      } else if (method === 'get') {
        return params
      } else {
        return {}
      }
    })(), that.options)
    
    var secured = null
    if (that.options && 'secured' in that.options) {
      secured = that.options.secured
    } else {
      secured = self.config.secured
    }
    var perform_api_call = null
    if (that.options && 'perform_api_call' in that.options) {
      perform_api_call = that.options.perform_api_call
    } else {
      perform_api_call = self.config.perform_api_call
    }

    that.callUrl = that.base
    self.lastAdded = RESOURCE
    return self.httpRequest(method, (secured ? 'https' : 'http') + '://' + path, params, callback, perform_api_call)
  }
}
1086075
@Override
    public void onConnectionFailed(ConnectionResult result) {
        timeoutHandler.removeMessages(APICLIENT_TIMEOUT_HANDLE_MSG);

        if (result == null) {
            HMSAgentLog.e("result is null");
            onConnectEnd(HMSAgent.AgentResultCode.RESULT_IS_NULL);
            return;
        }

        int errCode = result.getErrorCode();
        HMSAgentLog.d("errCode=" + errCode + " allowResolve=" + allowResolveConnectError);

        if(HuaweiApiAvailability.getInstance().isUserResolvableError(errCode) && allowResolveConnectError) {
            Activity activity = ActivityMgr.INST.getLastActivity();
            if (activity != null) {
                try {
                    timeoutHandler.sendEmptyMessageDelayed(APICLIENT_STARTACTIVITY_TIMEOUT_HANDLE_MSG, APICLIENT_STARTACTIVITY_TIMEOUT);
                    Intent intent = new Intent(activity, HMSAgentActivity.class);
                    intent.putExtra(HMSAgentActivity.CONN_ERR_CODE_TAG, errCode);
                    intent.putExtra(BaseAgentActivity.EXTRA_IS_FULLSCREEN, UIUtils.isActivityFullscreen(activity));
                    activity.startActivity(intent);
                    return;
                } catch (Exception e) {
                    HMSAgentLog.e("start HMSAgentActivity exception:" + e.getMessage());
                    timeoutHandler.removeMessages(APICLIENT_STARTACTIVITY_TIMEOUT_HANDLE_MSG);
                    onConnectEnd(HMSAgent.AgentResultCode.START_ACTIVITY_ERROR);
                    return;
                }
            } else {
                // 当前没有界面处理不了错误
                HMSAgentLog.d("no activity");
                onConnectEnd(HMSAgent.AgentResultCode.NO_ACTIVITY_FOR_USE);
                return;
            }
        } else {
            //其他错误码直接透传
        }

        onConnectEnd(errCode);
    }
1008932
@Override
	public void write(Iterable<QueryResult> results) {
		logger.debug("Export to '{}', proxy {} metrics {}", url, proxy, results);

		HttpURLConnection urlConnection = null;

		try {
			if (proxy == null) {
				urlConnection = (HttpURLConnection) url.openConnection();
			} else {
				urlConnection = (HttpURLConnection) url.openConnection(proxy);
			}
			urlConnection.setRequestMethod("POST");
			urlConnection.setDoInput(true);
			urlConnection.setDoOutput(true);
			urlConnection.setReadTimeout(stackdriverApiTimeoutInMillis);
			urlConnection.setRequestProperty("content-type", "application/json; charset=utf-8");
			urlConnection.setRequestProperty("x-stackdriver-apikey", apiKey);

			serialize(results, urlConnection.getOutputStream());
			int responseCode = urlConnection.getResponseCode();
			if (responseCode != 200 && responseCode != 201) {
				exceptionCounter.incrementAndGet();
				logger.warn("Failure {}:'{}' to send result to Stackdriver server '{}' with proxy {}", responseCode,
						urlConnection.getResponseMessage(), url, proxy);
			}
			if (logger.isTraceEnabled()) {
				IoUtils2.copy(urlConnection.getInputStream(), System.out);
			}
		} catch (Exception e) {
			exceptionCounter.incrementAndGet();
			logger.warn("Failure to send result to Stackdriver server '{}' with proxy {}", url, proxy, e);
		} finally {
			if (urlConnection != null) {
				try {
					InputStream in = urlConnection.getInputStream();
					IoUtils2.copy(in, IoUtils2.nullOutputStream());
					IoUtils2.closeQuietly(in);
					InputStream err = urlConnection.getErrorStream();
					if (err != null) {
						IoUtils2.copy(err, IoUtils2.nullOutputStream());
						IoUtils2.closeQuietly(err);
					}
					urlConnection.disconnect();
				} catch (IOException e) {
					logger.warn("Error flushing http connection for one result, continuing");
					logger.debug("Stack trace for the http connection, usually a network timeout", e);
				}
			}

		}
	}
824294
function processResult(result) {
    return {
        whenErrorIs: (errorCode) => {
            if (
                errorCode === EAUDITNOLOCK &&
                packageLockHasNotBeenFound(result)
            ) {
                const summary = result.error.summary || '';
                result.error.summary = `package.json file is missing or is badly formatted. ${summary}`;
                return result;
            }
            return result;
        },
    };
}
356795
function validateBody(err, body) {
      body = tryParse(body);

      if (err || !body) {
        return next(err || new Error('Unparsable response with statusCode ' + statusCode));
      }

      if (statusCode !== 200) {
        return next(new Error(body.message || 'Invalid status code ' + statusCode));
      }

      next(null, body);
    }