-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
95 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import java.net.*; | ||
import java.io.*; | ||
public class EmailReportSender implements ScoreReportSender{ | ||
@Override | ||
public void send(String recipient, String content) { | ||
try { | ||
Socket s = new Socket("osfmail.rit.edu", 25); | ||
BufferedReader in = | ||
new BufferedReader( | ||
new InputStreamReader(s.getInputStream(), "8859_1")); | ||
BufferedWriter out = | ||
new BufferedWriter( | ||
new OutputStreamWriter(s.getOutputStream(), "8859_1")); | ||
|
||
String boundary = "DataSeparatorString"; | ||
|
||
// here you are supposed to send your username | ||
sendln(in, out, "HELO world"); | ||
sendln(in, out, "MAIL FROM: <[email protected]>"); | ||
sendln(in, out, "RCPT TO: <" + recipient + ">"); | ||
sendln(in, out, "DATA"); | ||
sendln(out, "Subject: Bowling Score Report "); | ||
sendln(out, "From: <Lucky Strikes Bowling Club>"); | ||
|
||
sendln(out, "Content-Type: text/plain; charset=\"us-ascii\"\r\n"); | ||
sendln(out, content + "\n\n"); | ||
sendln(out, "\r\n"); | ||
|
||
sendln(in, out, "."); | ||
sendln(in, out, "QUIT"); | ||
s.close(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
public void sendln(BufferedReader in, BufferedWriter out, String s) { | ||
try { | ||
out.write(s + "\r\n"); | ||
out.flush(); | ||
// System.out.println(s); | ||
s = in.readLine(); | ||
// System.out.println(s); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public void sendln(BufferedWriter out, String s) { | ||
try { | ||
out.write(s + "\r\n"); | ||
out.flush(); | ||
System.out.println(s); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import java.awt.print.*; | ||
public class PrintReportSender implements ScoreReportSender { | ||
@Override | ||
public void send(String recipient, String content) { | ||
PrinterJob job = PrinterJob.getPrinterJob(); | ||
|
||
PrintableText printobj = new PrintableText(content); | ||
|
||
job.setPrintable(printobj); | ||
|
||
if (job.printDialog()) { | ||
try { | ||
job.print(); | ||
} catch (PrinterException e) { | ||
System.out.println(e); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,15 @@ | ||
/** | ||
* | ||
* SMTP implementation based on code by Réal Gagnon mailto:[email protected] | ||
* SMTP implementation based on code by R�al Gagnon mailto:[email protected] | ||
* | ||
*/ | ||
|
||
|
||
import java.io.*; | ||
import java.util.Vector; | ||
import java.util.Iterator; | ||
import java.net.*; | ||
import java.awt.*; | ||
import java.awt.print.*; | ||
|
||
public class ScoreReport { | ||
|
||
private ScoreReportSender sender; | ||
private String content; | ||
|
||
public ScoreReport( Bowler bowler, int[] scores, int games ) { | ||
public ScoreReport( Bowler bowler, int[] scores, int games) { | ||
String nick = bowler.getNick(); | ||
String full = bowler.getFullName(); | ||
Vector v = null; | ||
|
@@ -49,77 +42,11 @@ public ScoreReport( Bowler bowler, int[] scores, int games ) { | |
content += "Thank you for your continuing patronage."; | ||
|
||
} | ||
|
||
public void sendEmail(String recipient) { | ||
try { | ||
Socket s = new Socket("osfmail.rit.edu", 25); | ||
BufferedReader in = | ||
new BufferedReader( | ||
new InputStreamReader(s.getInputStream(), "8859_1")); | ||
BufferedWriter out = | ||
new BufferedWriter( | ||
new OutputStreamWriter(s.getOutputStream(), "8859_1")); | ||
|
||
String boundary = "DataSeparatorString"; | ||
|
||
// here you are supposed to send your username | ||
sendln(in, out, "HELO world"); | ||
sendln(in, out, "MAIL FROM: <[email protected]>"); | ||
sendln(in, out, "RCPT TO: <" + recipient + ">"); | ||
sendln(in, out, "DATA"); | ||
sendln(out, "Subject: Bowling Score Report "); | ||
sendln(out, "From: <Lucky Strikes Bowling Club>"); | ||
|
||
sendln(out, "Content-Type: text/plain; charset=\"us-ascii\"\r\n"); | ||
sendln(out, content + "\n\n"); | ||
sendln(out, "\r\n"); | ||
|
||
sendln(in, out, "."); | ||
sendln(in, out, "QUIT"); | ||
s.close(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public void sendPrintout() { | ||
PrinterJob job = PrinterJob.getPrinterJob(); | ||
|
||
PrintableText printobj = new PrintableText(content); | ||
|
||
job.setPrintable(printobj); | ||
|
||
if (job.printDialog()) { | ||
try { | ||
job.print(); | ||
} catch (PrinterException e) { | ||
System.out.println(e); | ||
} | ||
} | ||
|
||
} | ||
|
||
public void sendln(BufferedReader in, BufferedWriter out, String s) { | ||
try { | ||
out.write(s + "\r\n"); | ||
out.flush(); | ||
// System.out.println(s); | ||
s = in.readLine(); | ||
// System.out.println(s); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
public void setSender(ScoreReportSender sender) { | ||
this.sender = sender; | ||
} | ||
|
||
public void sendln(BufferedWriter out, String s) { | ||
try { | ||
out.write(s + "\r\n"); | ||
out.flush(); | ||
System.out.println(s); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
public void sendTo(String recipient) { | ||
sender.send(recipient, this.content); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
public interface ScoreReportSender { | ||
void send(String recipient, String content); | ||
} |