Skip to content

Commit

Permalink
Fix WC24 mail receiving
Browse files Browse the repository at this point in the history
  • Loading branch information
Difegue committed Sep 14, 2024
1 parent f3c161f commit d30fdae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
2 changes: 0 additions & 2 deletions src/com/difegue/doujinsoft/wc24/WC24Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ public WC24Base(ServletContext application) throws Exception {
"WiiConnect24 account password not specified. Please set the WC24_PASSWORD environment variable.");

if (!System.getenv().containsKey("WC24_DEBUG")) {
System.out.println("WC24_DEBUG not set, defaulting to false.");
debugLogging = false;
} else {
debugLogging = Boolean.parseBoolean(System.getenv("WC24_DEBUG"));
System.out.println("WC24_DEBUG set to " + debugLogging);
}

sender = System.getenv("WII_NUMBER");
Expand Down
24 changes: 14 additions & 10 deletions src/com/difegue/doujinsoft/wc24/WiiConnect24Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private String sendMailsInternal(List<MailItem> mails) throws IOException {
Logger log = Logger.getLogger("WC24");

HttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost("http://mtw." + wc24Server + "/cgi-bin/send.cgi");
HttpPost request = new HttpPost("http://mtw." + wc24Server + "/cgi-bin/send.cgi");

// Request parameters and other properties.
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
Expand All @@ -87,7 +87,7 @@ private String sendMailsInternal(List<MailItem> mails) throws IOException {
}

HttpEntity formDataEntity = builder.build();
httppost.setEntity(formDataEntity);
request.setEntity(formDataEntity);

// Log full multipart request, if thou must
// It makes the logs gigantic
Expand All @@ -98,15 +98,15 @@ private String sendMailsInternal(List<MailItem> mails) throws IOException {
builder.build().writeTo(baos);

log.log(Level.INFO, "Executing request:" + System.lineSeparator()
+ httppost.getRequestLine() + System.lineSeparator()
+ request.getRequestLine() + System.lineSeparator()
+ baos.toString());
} catch (Exception e) {
log.log(Level.INFO, e.getMessage());
}
}

// Execute and get the response.
HttpResponse response = httpclient.execute(httppost);
HttpResponse response = httpclient.execute(request);
HttpEntity entity = response.getEntity();

if (entity != null) {
Expand All @@ -130,12 +130,16 @@ private String sendMailsInternal(List<MailItem> mails) throws IOException {
public void receiveMails() throws Exception {

HttpClient httpclient = HttpClients.createDefault();
HttpPost request = new HttpPost("http://mtw." + wc24Server + "/cgi-bin/receive.cgi");

// For receiving, the syntax is different and the creds are form parameters.
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addTextBody("mlid", "w" + sender);
builder.addTextBody("passwd", wc24Pass);
builder.addTextBody("maxsize", "2000000");

// For receiving, the syntax is different and the mail/password are query
// parameters.
String authString = "mlid=w" + sender + "&passwd=" + wc24Pass;
HttpPost request = new HttpPost(
"http://mtw." + wc24Server + "/cgi-bin/receive.cgi?" + authString + "&maxsize=2000000");
HttpEntity formDataEntity = builder.build();
request.setEntity(formDataEntity);

// Execute and get the response.
HttpResponse response = httpclient.execute(request);
Expand All @@ -149,7 +153,7 @@ public void receiveMails() throws Exception {

if (debugLogging) {
Logger log = Logger.getLogger("WC24 Debug");
log.log(Level.INFO, responseText);
log.log(Level.INFO, "Reponse from WC24: \n" + responseText);
}

new MailItemParser(application).consumeEmails(responseText);
Expand Down

0 comments on commit d30fdae

Please sign in to comment.