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

Conversation

derbronko
Copy link

No description provided.

Copy link
Owner

@dschmidt dschmidt left a comment

Choose a reason for hiding this comment

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

Please make it work :-P

src/billo.php Outdated
@@ -95,8 +95,11 @@ function main() {
if ($message->hasFlag(Storage::FLAG_SEEN)) {
// continue;
} else {
messageAddFlag($GLOBALS['mailStorage'], $id, $message, Storage::FLAG_SEEN);
if ($listsConfig->isMember($list, $message->getHeader('from'))) {
Copy link
Owner

@dschmidt dschmidt Jun 2, 2020

Choose a reason for hiding this comment

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

Look closer at the link I sent you https://github.com/dschmidt/billo/blob/master/src/billo.php#L43

You need to handle an addressList here, as there could be multiple from values.

Apart from that: there is no $list in this scope.
You could probably handle this better here:

with code similar to this:

     $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 (in_array($from->getEmail(), array_keys($members))) {                                                                                              
         $subscribed = true;                                                                                                                     
       }                                                                                                                                         
     }                                                                                                                                           
     if(!$subscribed) {                                                                                                                          
       continue;                                                                                                                                 
     } 

Please test, I haven't :)

Copy link
Owner

@dschmidt dschmidt left a comment

Choose a reason for hiding this comment

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

There's one bug, so this won't work and I'd like the logic to be moved out of billo.php but apart from that this looks really good now

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...

// 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())) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants