package com.celements.mailsender;

import java.util.List;
import java.util.Map;

import org.xwiki.component.annotation.Component;
import org.xwiki.component.annotation.Requirement;
import org.xwiki.context.Execution;
import org.xwiki.script.service.ScriptService;

import com.celements.web.plugin.cmd.CelSendMail;
import com.xpn.xwiki.api.Attachment;

@Component("celmail")
public class CelMailScriptService implements ScriptService{
  
  private CelSendMail celSendMail;
  
  @Requirement
  private Execution execution;

  public int sendMail(
      String from, String replyTo,
      String to, String cc, String bcc,
      String subject, String htmlContent, String textContent,
      List<Attachment> attachments, Map<String, String> others) {
    CelSendMail sender = getCelSendMail();
    sender.setFrom(from);
    sender.setReplyTo(replyTo);
    sender.setTo(to);
    sender.setCc(cc);
    sender.setBcc(bcc);
    sender.setSubject(subject);
    sender.setHtmlContent(htmlContent, false);
    sender.setTextContent(textContent);
    sender.setAttachments(attachments);
    sender.setOthers(others);
    return sender.sendMail();
  }
  
  public boolean isValidEmail(String email) {
    //chars - a-z A-Z 0-9 œ à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ø ù ú û ü ý þ ÿ
    String wordChars = "\\w\\-\\u0153\\u00E0-\\u00F6\\u00F8-\\u00FF";
    String regex = "^[" + wordChars + "\\.\\+]+[@][" + wordChars + "]+([.]([" + wordChars 
        + "]+))+$";
    return email.matches(regex);
  }
  
  private CelSendMail getCelSendMail() {
    if(celSendMail != null) {
      return celSendMail;
    }
    return new CelSendMail();
  }
}

@@ -127,95 +127,8 @@
 nt;%0A
-import org.xwiki.component.annotation.Requirement;%0Aimport org.xwiki.context.Execution;%0A
 impo
@@ -338,16 +338,17 @@
 tService
+ 
 %7B%0A  %0A  p
@@ -386,55 +386,8 @@
 %0A  %0A
-  @Requirement%0A  private Execution execution;%0A%0A
   pu

remove unused requirement in CelMailScriptService