3 import java.io.BufferedReader;
\r
5 import java.io.FileNotFoundException;
\r
6 import java.io.FileReader;
\r
7 import java.io.IOException;
\r
8 import java.io.UnsupportedEncodingException;
\r
9 import java.util.Calendar;
\r
10 import java.util.Date;
\r
11 import java.util.GregorianCalendar;
\r
12 import java.util.Properties;
\r
14 import javax.mail.AuthenticationFailedException;
\r
15 import javax.mail.Authenticator;
\r
16 import javax.mail.Message;
\r
17 import javax.mail.MessagingException;
\r
18 import javax.mail.PasswordAuthentication;
\r
19 import javax.mail.Session;
\r
20 import javax.mail.Transport;
\r
21 import javax.mail.internet.InternetAddress;
\r
22 import javax.mail.internet.MimeMessage;
\r
25 public class PlugIn_RecRD_MAIL extends HDDRecorderUtils implements HDDRecorder,Cloneable {
\r
27 public PlugIn_RecRD_MAIL clone() {
\r
28 return (PlugIn_RecRD_MAIL) super.clone();
\r
34 public String getRecorderId() { return "RD(Mail)"; }
\r
35 public RecType getType() { return RecType.MAIL; }
\r
38 private ChannelCode cc = new ChannelCode(getRecorderId());
\r
39 private String rsvedFile = "";
\r
41 private String errmsg = "";
\r
43 protected String getDefFile() { return "env/mail.def"; }
\r
50 public String Myself() {
\r
51 return("MAIL"+":"+getMacAddr()+":"+getRecorderId());
\r
53 public ChannelCode getChCode() {
\r
59 public boolean isRepeatReserveSupported() { return false; }
\r
64 public boolean ChangeChannel(String Channel) {
\r
71 public boolean GetRdReserve(boolean force)
\r
75 System.out.println("Through: GetRdReserve("+force+")");
\r
77 String defFile = getDefFile();
\r
79 FileReader fr = null;
\r
80 BufferedReader r = null;
\r
92 fr = new FileReader(defFile);
\r
93 r = new BufferedReader(fr);
\r
95 while ( (s = r.readLine()) != null ) {
\r
96 String[] b = s.split(",");
\r
97 if ( b.length >= 3 ) {
\r
98 TextValueSet t = new TextValueSet() ;
\r
102 if ( b[0].equals("7") ) {
\r
105 else if ( b[0].equals("10") ) {
\r
108 else if ( b[0].equals("11") ) {
\r
111 else if ( b[0].equals("12") ) {
\r
114 else if ( b[0].equals("14") ) {
\r
117 else if ( b[0].equals("16") ) {
\r
120 else if ( b[0].equals("17") ) {
\r
123 else if ( b[0].equals("18") ) {
\r
126 else if ( b[0].equals("19") ) {
\r
131 } catch (FileNotFoundException e) {
\r
132 // TODO Auto-generated catch block
\r
133 e.printStackTrace();
\r
134 } catch (IOException e) {
\r
135 // TODO Auto-generated catch block
\r
136 e.printStackTrace();
\r
139 if (r != null) try { r.close(); } catch (Exception e) {};
\r
140 if (fr != null) try { fr.close(); } catch (Exception e) {};
\r
144 rsvedFile = "env/reserved."+getIPAddr()+"_"+getPortNo()+"_"+getRecorderId()+".xml";
\r
146 File f = new File(rsvedFile);
\r
147 if ( force == false && f.exists()) {
\r
148 // キャッシュから読み出し(予約一覧)
\r
149 setReserves(ReservesFromFile(rsvedFile));
\r
150 if (getReserves().size() > 0) {
\r
151 System.out.println("+read from="+rsvedFile);
\r
162 public boolean PostRdEntry(ReserveList r)
\r
167 if (cc.getCH_WEB2CODE(r.getCh_name()) == null) {
\r
168 errmsg = "【警告】Web番組表の放送局名「"+r.getCh_name()+"」をCHコードに変換できません。CHコード設定を修正してください。" ;
\r
169 System.out.println(errmsg);
\r
173 System.out.println("Run: PostRdEntry("+r.getTitle()+")");
\r
177 String message = "";
\r
179 GregorianCalendar c = CommonUtils.getCalendar(r.getRec_pattern());
\r
181 errmsg = "日付指定しか利用出来ません。" ;
\r
184 msg = getMailBody(r, this.getBroadcast());
\r
187 message = new String(msg.getBytes("MS932"),"Shift_JIS");
\r
188 } catch (UnsupportedEncodingException e1) {
\r
189 // TODO Auto-generated catch block
\r
190 e1.printStackTrace();
\r
195 Properties props = new Properties() ;
\r
196 props.put("mail.smtp.host", this.getIPAddr()) ;
\r
197 props.put("mail.host", this.getIPAddr()) ;
\r
198 props.put("mail.smtp.port", this.getPortNo()) ;
\r
199 props.put("mail.smtp.auth", "true") ;
\r
200 props.put("mail.smtp.starttls.enable","true");
\r
202 Session session = Session.getInstance( props, new Authenticator() {
\r
203 protected PasswordAuthentication getPasswordAuthentication() {
\r
204 return new PasswordAuthentication(getUser(), getPasswd()) ;
\r
207 //session.setDebug(true);
\r
208 MimeMessage mimeMessage = new MimeMessage(session);
\r
209 mimeMessage.setRecipients(Message.RecipientType.TO, this.getMacAddr());
\r
210 mimeMessage.setFrom(new InternetAddress(this.getUser()));
\r
211 mimeMessage.setSubject(new Date().toString());
\r
212 mimeMessage.setSentDate(new Date());
\r
213 //mimeMessage.setText(message, "ISO-2022-JP");
\r
214 mimeMessage.setContent(message, "text/html;charset=iso-2022-jp");
\r
215 mimeMessage.setHeader("Content-Transfer-Encoding", "7bit");
\r
216 Transport.send(mimeMessage);
\r
217 } catch (AuthenticationFailedException e) {
\r
218 errmsg = "SMTP認証に失敗しました:"+e.toString() ;
\r
220 } catch (MessagingException e) {
\r
221 errmsg = "メール送信に失敗しました:"+e.toString() ;
\r
227 for (ReserveList x : getReserves()) {
\r
228 if (Long.valueOf(x.getId()) > no) {
\r
229 no = Long.valueOf(x.getId());
\r
233 r.setId(String.valueOf(++no));
\r
235 r.setRec_pattern_id(getRec_pattern_Id(r.getRec_pattern()));
\r
238 r.setRec_nextdate(CommonUtils.getNextDate(r));
\r
241 r.setRec_min(CommonUtils.getRecMin(r.getAhh(),r.getAmm(),r.getZhh(),r.getZmm()));
\r
244 getStartEndDateTime(r);
\r
247 getReserves().add(r);
\r
250 ReservesToFile(getReserves(), rsvedFile);
\r
254 protected String getMailBody(ReserveList r, String passwd) {
\r
255 GregorianCalendar c = CommonUtils.getCalendar(r.getRec_pattern());
\r
257 StringBuilder sb = new StringBuilder();
\r
261 sb.append(this.getBroadcast());
\r
263 sb.append("prog ");
\r
265 sb.append(String.format("%04d%02d%02d ",c.get(Calendar.YEAR),c.get(Calendar.MONTH)+1,c.get(Calendar.DATE))+" ");
\r
267 sb.append(r.getAhh()+r.getAmm());
\r
269 sb.append(r.getZhh()+r.getZmm());
\r
271 sb.append(cc.getCH_WEB2CODE(r.getCh_name()));
\r
273 sb.append(text2value(encoder,r.getTuner()));
\r
275 sb.append(text2value(vrate,r.getRec_mode()));
\r
277 if (r.getRec_mode().indexOf("[TS") != 0) {
\r
278 sb.append(text2value(arate,r.getRec_audio()));
\r
281 sb.append(text2value(device,r.getRec_device()));
\r
283 sb.append(text2value(dvdcompat,r.getRec_dvdcompat()));
\r
284 String chapter_mode = text2value(xchapter,r.getRec_xchapter());
\r
285 if (chapter_mode != null) {
\r
287 sb.append(chapter_mode);
\r
289 chapter_mode = text2value(mvchapter,r.getRec_mvchapter());
\r
290 if (chapter_mode != null) {
\r
292 sb.append(chapter_mode);
\r
296 sb.append("CPN"); // マジックチャプターOFFをつけないとエラー発生
\r
298 chapter_mode = text2value(mschapter,r.getRec_mschapter());
\r
299 if (chapter_mode != null) {
\r
301 sb.append(chapter_mode);
\r
304 sb.append((r.getExec())?("RY"):("RN"));
\r
306 sb.append(r.getTitle());
\r
309 return sb.toString();
\r
315 public boolean UpdateRdEntry(ReserveList o, ReserveList r) {
\r
316 System.out.println("Through: UpdateRdEntry()");
\r
318 errmsg = "更新処理は無効です。";
\r
326 public ReserveList RemoveRdEntry(String delid) {
\r
329 System.out.println("Through: RemoveRdEntry()");
\r
332 ReserveList rx = null;
\r
333 for ( ReserveList reserve : getReserves() ) {
\r
334 if (reserve.getId().equals(delid)) {
\r
344 getReserves().remove(rx);
\r
347 ReservesToFile(getReserves(), rsvedFile);
\r
349 errmsg = "鯛ナビのエントリは削除しました。REGZA上で実際のエントリを削除して下さい。";
\r
357 public String getErrmsg() {
\r
358 return(errmsg.replaceAll("\\\\r\\\\n", ""));
\r