Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sender must be a part of mail list #2

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/ListsConfigParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public function getListName($list) {
public function getLists() {
return array_keys($this->_config);
}

public function isMember($senderAddress, $listAddress)
{
return array_key_exists($senderAddress, $this->getMembers($listAddress));
}

public function getMembers($listAddress)
{
Expand Down
15 changes: 13 additions & 2 deletions src/billo.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ function distributeMessage($listsConfig, $mailSender, $id, $message) {
$mailSender->Subject =
'['.$listsConfig->getListName($list->getEmail()).'] '.$message->subject;

$members = $listsConfig->getMembers($list->getEmail());
// Check at least one of the senders ("from") is subscribed to the list
$subscribed = false;
foreach($message->getHeader('from')->getAddressList() as $from) {
if ($listsConfig->isMember($from->getEmail(), $members)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to pass the list name to isMember not the members themselves.

Suggested change
if ($listsConfig->isMember($from->getEmail(), $members)) {
if ($listsConfig->isMember($from->getEmail(), $list->getEmail())) {

$subscribed = true;
}
}
if(!$subscribed) {
echo "Not distributed message from unknown sender" . PHP_EOL;
continue;
}
Copy link
Owner

@dschmidt dschmidt Jun 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could move this logic to the ListsConfigParser. Naming the function is probably the hardest part :-D
... and then:

Suggested change
}
if(!$listsConfig->isAnyAddressMemberOfList($message->getHeader('from')->getAddressList(), $list->getEmail())) {
continue;
}

Keeps the complexity of this function lower and gives us a chance to unit test it...


// Copy over content
$content = $GLOBALS['mailStorage']->getRawContent($id);
Expand Down Expand Up @@ -93,10 +105,9 @@ function main() {
foreach ($GLOBALS['mailStorage'] as $id => $message) {
if ($message->hasFlag(Storage::FLAG_SEEN)) {
continue;
} else {
messageAddFlag($GLOBALS['mailStorage'], $id, $message, Storage::FLAG_SEEN);
}

messageAddFlag($GLOBALS['mailStorage'], $id, $message, Storage::FLAG_SEEN);
distributeMessage($listsConfig, $GLOBALS['mailSender'], $id, $message);
}
}
Expand Down
13 changes: 13 additions & 0 deletions tests/ListsConfigParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,18 @@ public function testListsAndMembersAreParsed(): void
'[email protected]' => 'Bar',
]
);

$this->assertTrue(
$parser->isMember('[email protected]', '[email protected]')
);

$this->assertFalse(
$parser->isMember('[email protected]', '[email protected]')
);

// TODO: implement case insensitive matching
// $this->assertTrue(
// $parser->isMember('[email protected]', '[email protected]')
// );
}
}