Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
marigostra committed Nov 23, 2022
1 parent ef0e67e commit a6f5615
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 47 deletions.
4 changes: 1 addition & 3 deletions src/main/java/org/luwrain/app/mail/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
public final class App extends AppBase<Strings> implements MonoApp
{
static final String
LOG_COMPONENT = "mail",
HOOK_ORGANIZE_SUMMARY = "mail.summary.organize",
HOOK_REPLY = "mail.reply";
LOG_COMPONENT = "mail";

private Hooks hooks = null;
private MailStoring storing = null;
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/org/luwrain/app/mail/FoldersModel.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
Copyright 2012-2022 Michael Pozhidaev <[email protected]>
This file is part of LUWRAIN.
LUWRAIN is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
LUWRAIN is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
*/

package org.luwrain.app.mail;

Expand Down
77 changes: 65 additions & 12 deletions src/main/java/org/luwrain/app/mail/Hooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,66 @@
package org.luwrain.app.mail;

import java.util.*;
import java.util.concurrent.atomic.*;

import org.luwrain.core.*;
import org.luwrain.script.*;
import org.luwrain.script.hooks.*;
import org.luwrain.pim.*;
import org.luwrain.pim.mail.*;
import org.luwrain.pim.mail.script.*;

import static org.luwrain.script.ScriptUtils.*;
import static org.luwrain.script.Hooks.*;

import static org.luwrain.app.mail.App.*;

final class Hooks
{
static private final String LOG_COMPONENT = App.LOG_COMPONENT;

static private final String ORGANIZE_SUMMARY_HOOK_NAME = "luwrain.mail.summary.organize";
static private final String REPLY_HOOK_NAME = "luwrain.mail.reply";
static private final String
SERVERS = "luwrain.mail.servers",
REPLY = "luwrain.mail.reply",
ORGANIZE_SUMMARY = "luwrain.mail.summary.organize";

private final Luwrain luwrain;
Hooks(Luwrain luwrain) { this.luwrain = luwrain; }

Hooks(Luwrain luwrain)
Map<String, MailAccount> server(String mailAddr)
{
NullCheck.notNull(luwrain, "luwrain");
this.luwrain = luwrain;
final Object res = provider(luwrain, SERVERS, new Object[]{mailAddr});
if (isNull(res))
return null;
final Map<String, MailAccount> accounts = new HashMap<>();
final Object
smtp = getMember(res, "smtp");
if (!isNull(smtp))
accounts.put("smtp", getAccount(smtp));
return accounts;
}

void organizeSummary()
{
/*
final MessageObj [] hookObjs = new MessageObj[messages.length];
for(int i = 0;i < messages.length;i++)
hookObjs[i] = new MessageObj(messages[i]);
final Object[] args = new Object[]{getArray(hookObjs)};
final Object res;
final List<SummaryItem> items = new ArrayList<>();
try {
res = getHooks().provider(getLuwrain(), App.HOOK_ORGANIZE_SUMMARY, args);
}
catch(RuntimeException e)
{
Log.error(LOG_COMPONENT, "unable to run the " + App.HOOK_ORGANIZE_SUMMARY + ": " + e.getClass().getName() + ": " + e.getMessage());
app.crash(e);
return items;
}
if (res == null)
return items;
final Object[] array = asArray(res);
if (array == null)
return items;
for(Object o: array)
items.add(new SummaryItem(o));
return items;
*/
}

boolean makeReply(MailMessage message)
{
Expand All @@ -58,4 +94,21 @@ boolean makeReply(MailMessage message)
*/
return false;
}

static MailAccount getAccount(Object obj)
{
final MailAccount account = new MailAccount();
account.setHost(asString(getMember(obj, "host")));
account.setPort(asInt(getMember(obj, "port")));
final EnumSet<MailAccount.Flags> flags = EnumSet.noneOf(MailAccount.Flags.class);
final boolean
ssl = asBoolean(getMember(obj, "ssl")),
tls = asBoolean(getMember(obj, "tls"));
if (ssl)
flags.add(MailAccount.Flags.SSL);
if (tls)
flags.add(MailAccount.Flags.TLS);
account.setFlags(flags);
return account;
}
}
24 changes: 1 addition & 23 deletions src/main/java/org/luwrain/app/mail/MainLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,28 +262,6 @@ private String[] getCcExcludeAddrs()

private List<SummaryItem> organizeSummary(MailMessage[] messages)
{
final MessageObj [] hookObjs = new MessageObj[messages.length];
for(int i = 0;i < messages.length;i++)
hookObjs[i] = new MessageObj(messages[i]);
final Object[] args = new Object[]{getArray(hookObjs)};
final Object res;
final List<SummaryItem> items = new ArrayList<>();
try {
res = getHooks().provider(getLuwrain(), App.HOOK_ORGANIZE_SUMMARY, args);
}
catch(RuntimeException e)
{
Log.error(LOG_COMPONENT, "unable to run the " + App.HOOK_ORGANIZE_SUMMARY + ": " + e.getClass().getName() + ": " + e.getMessage());
app.crash(e);
return items;
}
if (res == null)
return items;
final Object[] array = asArray(res);
if (array == null)
return items;
for(Object o: array)
items.add(new SummaryItem(o));
return items;
return null;
}
}
34 changes: 27 additions & 7 deletions src/main/java/org/luwrain/app/mail/StartingLayout.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2012-2021 Michael Pozhidaev <[email protected]>
Copyright 2012-2022 Michael Pozhidaev <[email protected]>
Copyright 2015-2016 Roman Volovodov <[email protected]>
This file is part of LUWRAIN.
Expand All @@ -18,23 +18,25 @@
package org.luwrain.app.mail;

import java.util.*;
import java.io.*;

import org.luwrain.core.*;
import org.luwrain.core.events.*;
import org.luwrain.controls.*;
import org.luwrain.pim.mail.*;
import org.luwrain.app.base.*;

import org.luwrain.controls.WizardArea.Frame;
import org.luwrain.controls.WizardArea.WizardValues;

import static org.luwrain.core.DefaultEventResponse.*;

final class StartingLayout extends LayoutBase
{
final App app;
final WizardArea wizardArea;
final Frame introFrame;
final Frame introFrame, passwordFrame;

private String mail = "", passwd = "";
private MailAccount smtp = null, pop3 = null;

StartingLayout(App app)
{
Expand All @@ -44,12 +46,16 @@ final class StartingLayout extends LayoutBase
this.introFrame = wizardArea.newFrame()
.addText(app.getStrings().wizardIntro())
.addInput(app.getStrings().wizardMailAddr(), "")
.addClickable(app.getStrings().wizardContinue(), this::onContinue);
.addClickable(app.getStrings().wizardContinue(), this::onMailAddress);
this.passwordFrame = wizardArea.newFrame()
.addText(app.getStrings().wizardPasswordIntro())
.addInput(app.getStrings().wizardPassword(), "")
.addClickable(app.getStrings().wizardContinue(), this::onPassword);
wizardArea.show(introFrame);
setAreaLayout(wizardArea, null);
setAreaLayout(wizardArea, null);
}

private boolean onContinue(WizardValues values)
private boolean onMailAddress(WizardValues values)
{
final String mail = values.getText(0).trim();
if (mail.isEmpty())
Expand All @@ -62,6 +68,20 @@ private boolean onContinue(WizardValues values)
app.message(app.getStrings().wizardMailAddrIsInvalid(), Luwrain.MessageType.ERROR);
return true;
}
final Map<String, MailAccount> accounts = app.getHooks().server(mail);
if (accounts == null)
return false;
this.smtp = accounts.get("smtp");
this.pop3 = accounts.get("pop3");
if (smtp == null/* || pop3 == null*/)
return false;
wizardArea.show(passwordFrame);
app.setEventResponse(text(Sounds.OK, app.getStrings().wizardPasswordAnnouncement()));
return true;
}

private boolean onPassword(WizardValues values)
{
return false;
}
}
5 changes: 4 additions & 1 deletion src/main/java/org/luwrain/app/mail/Strings.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ public interface Strings
String actionFetchIncomingBkg();

String wizardIntro();
String wizardContinue();
String wizardMailAddr();
String wizardMailAddrIsEmpty();
String wizardMailAddrIsInvalid();
String wizardContinue();
String wizardPasswordAnnouncement();
String wizardPasswordIntro();
String wizardPassword();
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ MessageAreaTo = Кому:
SummaryAreaName = Сообщения

WizardIntro = Необходимо произвести подключение к учётной записи вашей электронной почты. Укажите ваш адрес электронной почты в поле ниже и нажмите кнопку "Продолжить".
WizardContinue = Продолжить
WizardMailAddr = Адрес электронной почты:
WizardMailAddrIsEmpty = Адрес электронной почты не может быть пустым
WizardMailAddrIsInvalid = Указанное значение не является допустимым адресом электронной почты
WizardContinue = Продолжить
WizardPasswordAnnouncement = Необходимо указать пароль
WizardPasswordIntro = Адрес электронной почты распознан, мы готовы настроить подключение к серверу. Для этого необходимо указать пароль для доступа к учётной записи:
WizardPassword = Пароль:


0 comments on commit a6f5615

Please sign in to comment.