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

Refactored Office 365 Plugin #1225

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

caronc
Copy link
Owner

@caronc caronc commented Oct 11, 2024

Description:

Related issue (if applicable): #1217, #836, and #858

Refactoring Office 365 Plugin and updating wiki page

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • No lint errors (use flake8)
  • 100% test coverage

Testing

Anyone can help test this source code as follows:

# Create a virtual environment to work in as follows:
python3 -m venv apprise

# Change into our new directory
cd apprise

# Activate our virtual environment
source bin/activate

# Install the branch
pip install git+https://github.com/caronc/apprise.git@1217-office365-azure-refactor

# Test out the changes with the following command:
apprise -t "Test Title" -b "Test Message" \
  "o365://tenant_id/client_id/client_secret/[email protected]"

@caronc caronc force-pushed the 1217-office365-azure-refactor branch from 3137829 to f6c7dde Compare October 11, 2024 03:35
@Austenite2
Copy link

Thank you! I tried on my Raspberry pi running klipper and got:

2024-10-13 10:59:13,257 - ERROR - Could not load Office 365 URL: o365://2...7:[email protected]/0...0/H...e
You must specify at least one server URL or populated configuration file.
Try 'apprise --help' for more information.
(apprise) pi@mainsailos:~/apprise $

User error on my end?

@Austenite2
Copy link

Austenite2 commented Oct 13, 2024

Indeed there was a user error on my end, I copied and pasted the o365:// link in the old format. Once corrected, still get same error, unfortunately.

2024-10-13 11:34:15,312 - ERROR - Could not load Office 365 URL: o365://2...7/0...0/H...e/j...m
You must specify at least one server URL or populated configuration file.
Try 'apprise --help' for more information.
(apprise) pi@mainsailos:~/apprise $

Edit - same error if secret is url-encoded or not

Edit2: Adding --debug gives:

2024-10-13 12:03:08,203 - DEBUG - Could not load translation path: /home/pi/apprise/lib/python3.9/site-packages/apprise/i18n/en
2024-10-13 12:03:08,647 - DEBUG - Notification Plugin 110(s) and 156 Schema(s) loaded in 0.4312s
2024-10-13 12:03:08,650 - WARNING - An invalid Office 365 Email Account ID(None) was specified.
2024-10-13 12:03:08,651 - ERROR - Could not load Office 365 URL: o365://2...7/0...0/H...e/j...m
You must specify at least one server URL or populated configuration file.
Try 'apprise --help' for more information.
(apprise) pi@mainsailos:~/apprise $

On checking, I see all lib/python/ directories are there except the final /en

@caronc
Copy link
Owner Author

caronc commented Oct 13, 2024

Unfortunately this PR is still in development. It may not work because i don't have an Azure connection to test with anymore. Would you actually be able to assist and create an email for me to develop with? You can delete it right after? If this is not something you can help with, I understand.

@Austenite2
Copy link

Would you actually be able to assist and create an email for me to develop with?
Yes, will email details

Copy link

codecov bot commented Oct 27, 2024

Codecov Report

Attention: Patch coverage is 85.05747% with 13 lines in your changes missing coverage. Please review.

Project coverage is 99.30%. Comparing base (19c0d8a) to head (e2897fe).
Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
apprise/attachment/base.py 38.46% 8 Missing ⚠️
apprise/plugins/office365.py 93.24% 2 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1225      +/-   ##
==========================================
- Coverage   99.37%   99.30%   -0.07%     
==========================================
  Files         148      147       -1     
  Lines       20675    20608      -67     
  Branches     3679     3678       -1     
==========================================
- Hits        20545    20465      -80     
- Misses        121      131      +10     
- Partials        9       12       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Austenite2
Copy link

I just tested and get different errors now:

(apprise) pi@mainsailos:~/apprise $ apprise -t "Test Title" -b "Test Message" --debug o365://8cb3feab-8888-416c-b03a-920ca0df26b0/730930cf-1943-4237-9a44-092796683b06/.hG8Q~q3_restofsecret_/[email protected]

2024-10-27 22:36:35,550 - DEBUG - Could not load translation path: /home/pi/apprise/lib/python3.9/site-packages/apprise/i18n/en
2024-10-27 22:36:35,988 - DEBUG - Notification Plugin 110(s) and 157 Schema(s) loaded in 0.4252s
2024-10-27 22:36:35,991 - DEBUG - Loaded Office 365 URL: azure://8...0/7...6/****/[email protected]/?mode=self&format=html&overflow=upstream
2024-10-27 22:36:35,991 - DEBUG - Office 365 POST URL: https://login.microsoftonline.com/8cb3feab-8888-416c-b03a-920ca0df26b0/oauth2/v2.0/token (cert_verify=True)
2024-10-27 22:36:35,991 - DEBUG - Office 365 Payload: {'client_id': '730930cf-1943-4237-9a44-092796683b06', 'client_secret': '.hG8Q~q3_restofsecret_', 'scope': 'https://graph.microsoft.com/.default', 'grant_type': 'client_credentials'}
2024-10-27 22:36:51,373 - DEBUG - Email To: [email protected]
2024-10-27 22:36:51,374 - DEBUG - Office 365 POST URL: https://graph.microsoft.com/v1.0/me/sendMail (cert_verify=True)
2024-10-27 22:36:51,374 - DEBUG - Office 365 Payload: {"message": {"subject": "Test Title", "body": {"contentType": "HTML", "content": "Test Message"}, "toRecipients": [{"emailAddress": {"Address": "[email protected]"}}]}, "saveToSentItems": "true"}
2024-10-27 22:36:56,507 - WARNING - Failed to send Office 365 POST to https://graph.microsoft.com/v1.0/me/sendMail: , error=400.
2024-10-27 22:36:56,507 - DEBUG - Response Details:
b'{"error":{"code":"BadRequest","message":"/me request is only valid with delegated authentication flow.","innerError":{"date":"2024-10-27T22:36:56","request-id":"f991871c-ddcd-45b4-b728-9286cb185117","client-request-id":"f991871c-ddcd-45b4-b728-9286cb185117"}}}'

@caronc
Copy link
Owner Author

caronc commented Oct 27, 2024

I still have a ways to go on my end. I just wanted to push up the code that i had on my local PC. This is a bit of a learning curve for me.

Sorry for the wait; please be patient

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