How can I get the latest emails from all folders with exchangelib? - exchangelib

Currently, I use
latest_mails = account.inbox.filter(datetime_received__gt=emails_since)
But it seems to miss received emails which are in subfolders.
Printing all folders with
for f in account.root.get_folders():
print(f)
gives something like
Calendar (Kalender)
Contacts (Kontakte)
Contacts (Vorgeschlagene Kontakte)
Folder (AllItems)
Folder (Calendar Logging)
Folder (Common Views)
Folder (Conversation Action Settings)
Folder (Deferred Action)
Folder (Deletions)
Folder (Erinnerungen)
Folder (ExchangeSyncData)
Folder (Finder)
Folder (Infected Items)
Folder (Journal)
Folder (Location)
Folder (MailboxAssociations)
Folder (Notizen)
Folder (Recipient Cache)
Folder (Recoverable Items)
Folder (Schedule)
Folder (Shortcuts)
Folder (Spooler Queue)
Folder (System)
Folder (Versions)
Folder (Views)
Folder (WorkingSet)
Messages (Postausgang)
Messages (Posteingang)
Messages (foo)
Messages (bar)
Messages (something is)
Messages (here)
Messages (Gelöschte Elemente)
Messages (Gesendete Elemente)
Messages (Junk-E-Mail)
Messages (Meine Kontakte)
Messages (MyContactsExtended)
Messages (Nachverfolgte E-Mail-Verarbeitung)
Messages (Zugang)
Tasks (Aufgaben)
Tasks (Aufgabensuche)
So I only want to look at the "Messages" folders, but at all of them. Is that possible (without using account.root.get_folders()) and looping over the results (which took about 5 minutes)

You're correct that .filter() only works on the folder you call it on, not subfolders. I'm pretty sure EWS only supports searching one folder at a time.
You should be able to do something like this to speed things up a little bit:
from exchangelib.folders import Messages
for f in account.folders[Message]:
for i in f.filter(datetime_received__gt=emails_since):
print(i)
But Folder type folders can also contain Message items, so depending on your needs you may also have to visit those.
f.supported_item_models will tell you which item types a given folder can contain.

Related

WSO2 APIM custom error messages removed after restart

I added some custom error messages to the APIM according to documentation https://apim.docs.wso2.com/en/4.0.0/troubleshooting/error-handling/ - I created custom file in
<API-M_HOME>/repository/deployment/server/synapse-configs/default/sequences and added references to that file in some of the default files in that directory (so that it is called to transform error message).
Everything seemed to be working just fine until the restart of WSO2 - after that, changes made to default files were present, but the custom file was removed, so that custom error message handling didn't work.
I resolved this by adding non-removable attribute (chattr +i) to the file, but I wonder is there other, more elegant way to prevent the file from being deleted every time restart is being made?
There are 'template' files placed in: <API-M_HOME>/repository/resources/apim-synapse-config. Maybe, those files are overriding files in the ../synapse-configs/default/ location.
Second thing, which came on my mind, is using specific High Avability scenario. Where artifacts are shared files in system as the content synchronization mechanism, it can override local changes.
At the startup gateway removes these files. You can add the following configuration to the deployment.toml and place the file in the sequence directory.
Sample Config:
[apim.sync_runtime_artifacts.gateway.skip_list]
apis = ["api1.xml","api2.xml"]
endpoints = ["endpoint1.xml"]
sequences = ["post_with_nobody.xml"]
local-entries = ["file.xml"]
For your case:
[apim.sync_runtime_artifacts.gateway.skip_list]
sequences = ["name_of_the_file.xml"]
Refer - https://apim.docs.wso2.com/en/latest/install-and-setup/setup/distributed-deployment/deploying-wso2-api-m-in-a-distributed-setup/#configure-the-gateway-nodes

sg-cookie-optin extension throws No class named SGalinski\SgCookieOptin\Hook\LicenceCheckHook

Downloaded this https://packagist.org/packages/sgalinski/sg-cookie-optin
Copied the file to the server, activated the extension in ext manager.
Suddenly front & backend not working anymore.
Deleted the extension manually from PackageStates.php according to
https://docs.typo3.org/m/typo3/guide-installation/master/en-us/ExtensionInstallation/Index.html
Frontend now working, backend still throws the error
No class named SGalinski\SgCookieOptin\Hook\LicenceCheckHook
in /home/sc/wwn/typo3_src-10.4.10/typo3/sysext/core/Classes/Utility/GeneralUtility.php line 3340
throw new \InvalidArgumentException($errorMsg, 1294585865);
}
} else {
$errorMsg = 'No class named ' . $parts[0];
throw new \InvalidArgumentException($errorMsg, 1294585866);
}
} elseif (function_exists($funcName) && is_callable($funcName)) {
// It's a function
$content = call_user_func_array($funcName, [&$params, &$ref]);
I did set up the key and the output folder in the config file
what I didn't do since backend not working anymore :
3. Add the static TypoScript named "Cookie Optin" to your instance with the "Template" backend module.
Open up the "Template" module in the backend of TYPO3.
Go to your root site page within the page tree.
Choose "Info/Modify" at the select on the top.
Click on the button "Edit the whole template record".
Select the tab "Includes".
Choose the template "Cookie Optin (sg_cookie_optin)" on the multi select box with the name "Include static (from extensions)"
Save
4. Go into the "Cookie Opt In" backend module, configure it and save it once.
Any idea how i can fix that? Pretty stuck atm.
The install tool of your installation should still work. Try to open yourdomain.tld/typo3/install.php.
To enable the Install Tool, the file ENABLE_INSTALL_TOOL must be created in the directory typo3conf/. Make sure that the file has no file extension like .txt.
Then log in to the install tool and go to Maintenance => Flush TYPO3 and PHP Cache and flush all caches.
Then the backend should work.
If the install tool is not accessible, try to find a folder var/Cache. Most probably it will be located in typo3temp. Delete all files and subfolders from the Cache folder.

DropNet returning metadata for root folder not folder requested

Problem: GetMetaData for the folder that I need returns the root folder metadata.
Background:
I'm trying to write a small app to download a folder that is too large (many thousand files and multiple GB) to download from the Dropbox web interface. It tries to recurse through the subdirectories of the directory given, downloading all the files.
What actually happens is an endless loop. The app (incorrectly) gets the root folder metadata, iterates through the directories until it hits the directory I need and then starts working through the root directory as that is the metadata set that it receives.
The directory name "/Apps" works fine but the one I need doesn't. The folder name has an underscore and a mix of upper and lower case letters (no other characters) similar to "/XYX_DataFolder".
My app has "Full Dropbox" permission and I authorized with the account that the api key was acquired under.
Changing the directory name is not an option for me.
I'm using VS2012 and the DropNet was added through NuGet.
Any input on this issue would be welcome. Thanks!
Edit:
Runtime Version v4.0.30319
Version 1.10.23.0
As reported in the Visual Studio properties page for the reference.
I authorize which works fine and then use the code below. Some directories work fine but when I try to GetMetaData on the folder mentioned above, I get the metadata from the root folder.
private void DownloadDirectory( string serverDirectory, string clientDirectory ) {
var meta = m_client.GetMetaData( serverDirectory, false, false );
foreach ( var item in meta.Contents ) {
var destinationPath = Path.Combine( clientDirectory, item.Name );
if ( item.Is_Dir && item.Path == m_serverRootDirectory ) {
DownloadDirectory( item.Path, destinationPath );
}
else {
//var fileBytes = m_client.GetFile( item.Path );
//File.WriteAllBytes( destinationPath, fileBytes );
//textBox1.Text += Environment.NewLine + destinationPath;
}
}
}
Ok, so I downloaded the source and found my problem right away. I was missing a null for the hash in the GetMetaData call, so it was using the wrong overload. Sorry to waste your time... Thanks for the response!

Mailbox directory not changed after IMAP account switch

In my configuration I have two online IMAP accounts, say A and B.
My simplified configuration file looks like that:
## Account A settings
source ~/.mutt/a/config
folder-hook 'a.com' 'source ~/.mutt/a/config'
## Account B settings
folder-hook 'b.com' 'source ~/.mutt/b/config'
macro index <f2> '<sync-mailbox><enter-command>source ~/.mutt/a/config<enter><change-folder>!<enter>'
macro index <f3> '<sync-mailbox><enter-command>source ~/.mutt/b/config<enter><change-folder>!<enter>'
Configuration files of both accounts are similar and looks like this:
set imap_user = usera
set imap_pass = userasecret
unset folder
set folder = "imaps://mail.a.com/"
set spoolfile = "+INBOX"
mailboxes "+INBOX"
and
set imap_user = userb
set imap_pass = userbsecret
unset folder
set folder = "imaps://mail.b.com/"
set spoolfile = "+INBOX"
mailboxes "+INBOX"
I can switch between accounts using F2 nad F3 keys, but the problem is when I try to change the mailbox. At the beginning (i.e., before using F-key) pressing c? gives me the list of available IMAP folders. However, when I switch to the second account - by pressing F3 - and then try to list IMAP folders there is an error. Mutt try to fetch folders from the first server: imaps://mail.a.com and fails because of the wrong credentials (as imap_user is already set to userb). I have to wait a while, then press c again and change the directory name to the current folder variable value. After this operation I can list the folders again. Until the next switch...
Why is mutt sticking with the old directory path after changing the folder and how can I change this behaviour?
I don't know if you still care, but I found this solution:
With the above shortcuts (or with the sidebar) you will find that changing folders (with c by default) is not contextual, i.e. it will not list the folders of the current mailbox, but of the one used the last time you changed folders. To make the behaviour more contextual, the trick is to press = or + for current mailbox. You can automate this with the following macro:
macro index 'c' '<change-folder>?<change-dir><home>^K=<enter>'
See the website: https://wiki.archlinux.org/index.php/Mutt

Adding a File object programatically in Plone using PloneFormGen

I'm writing a PloneFormGen custom action adapter in order to add a File object to a folder from the File Field in the form. Here is the script:
target = context.filefolder
form = request.form
uid = str(DateTime().millis())
target.invokeFactory("File", id=uid, file=form['arquivo-do-cv_file'])
obj = target[uid]
"filefolder" is the name of a folder inside the parent folder for the PFG FormFolder. This script is configured to run with a Manager proxy role.
Problem is that the File objects created this way won't show the "Click here to download the file" link when I view them. The files can be downloaded though, if I suppress the "/view" part from the end of the URL. What am I missing when calling invokeFactory to create the File object?
UPDATE: What I meant is that I don't get the "filename - filetype, size in KBs (size in bytes)" link for the document, below the byline. When I create a File object using the normal Plone UI, it does show up.
I suspect nothing; I think that is the default behavior in Plone 4.
I just added a File and I don't see any "Click here to download the file".
And a quick search does not reveal the string "click here to download":
aclark#Alex-Clarks-MacBook-Pro:~/Developer/test-4.1/ > grep -ir "Click here to download" parts/omelette
parts/omelette/plone/app/jquerytools/browser/jquery.tools.plugins.js: (root.tagName == 'A' ? "<p>Click here to download latest version</p>" :
parts/omelette/plone/app/jquerytools/browser/jquery.tools.plugins.min.js:" or greater is required</h2><h3>"+(g[0]>0?"Your version is "+g:"You have no flash plugin installed")+"</h3>"+(a.tagName=="A"?"<p>Click here to download latest version</p>":"<p>Download latest version from <a href='"+k+"'>here</a></p>");if(a.tagName=="A")a.onclick=function(){location.href=k}}if(b.onFail){var d=b.onFail.call(this);if(typeof d=="string")a.innerHTML=d}}if(i)window[b.id]=document.getElementById(b.id);f(this,{getRoot:function(){return a},getOptions:function(){return b},getConf:function(){return c},
I don't have a Plone instance to test it, but try to call processForm() after invokeFactory. It will:
unmark creation flag;
rename object according to title;
reindex the object;
invoke the after_creation script and fire the ObjectInitialized event.
These actions are detailed on Object Construction Lifecycle. Maybe some of these actions are needed to create the KB information you're after (I'm hoping it's the index).