I am accessing Lotus Notes via OLE, and this is how I retrieve the selected mail:
try
UIView := FLNotes.CURRENTVIEW; // am I in a view or in an opened document ?
if VarIsClear(UIView) then begin
try
aDocument := FLNotes.CURRENTDOCUMENT.Document;
except
raise;
end;
end else begin // any selected mails in view ?
UIDocuments := UIView.DOCUMENTS;
for counter := 1 to UIDocuments.Count do begin
if counter = 1 Then
aDocument := UIDocuments.GETFIRSTDOCUMENT
else
aDocument := UIDocuments.GETNEXTDOCUMENT(aDocument);
end;
end;
finally
UIView := Unassigned;
UIDocuments := Unassigned;
aDocument := Unassigned;
end;
I have the reference to the particular mail in aDocument. Now I would like to save every each mail (on the disk as a file, not inside Lotus Notes), but I didnt find the right method to use with OLE.
I have found this Notes Commands, but I didnt figure out whats the syntax for OLE access. I tried it like this: aDocument.Command("FileSave", "Test.eml"), and I tried also lot of other combinations with Save but none of them worked. So maybe somebody did this already or has a tip where I could look for a solution
Thanks
Regards
Save operations in Notes will save a document in an NSF file, not the filesystem. It's an Export operation you would be looking for.
The FileSave command saves a currently open-for-edit document in the
Notes UI and saves it to the NSF file that it was opened from.
The Save method similarly does a back-end save - i.e., it bypasses the UI operations, takes the in-memmory representation of an existing Notes document (not necessarily the one that is current in the Notes client), and saves it to the NSF file that it was opened from.
Back to the subject of Export operations, as far as I know, there is no supported Export method for .eml files. Although the Notes client can save a .eml file if you drag a message from a view and drop it on your desktop, I don't believe there is any supported method in any of the supported Notes APIs for automating this process. (In theory, I imagine that one might be able to use the Windows API to send the appropriate event messages to the Notes client in order to make it think the user is doing a drag-and-drop operation, but that's way beyond the scope of what could possibly be addressed here on StackOverflow.)
It seems that there is a way to save the mail as an eml file (actually any file that you want, but since .eml is what I need I will use that). So for any case somebody may need it here the code :
try
oleSession := GetActiveOleObject('Notes.NotesSession');
except
oleSession := CreateOleObject('Notes.NotesSession');
end;
path := '...Somepath.../Mail.eml';
oleDB := oleSession.CurrentDatabase;
oleSession.ConvertMIME := false;
oleView := GetSelectedMail; //the code for this is in the first post
oleDoc := oleView.GetFirstDocument;
oleDoc.converttomime(1);
mime := oleDoc.getmimeentity;
oleEmailText := oleSession.CreateStream; // create a stream to fill it with the data
oleEmailText.open(path, 'us-ascii');
mime.GetEntityAsText(oleEmailText); // write inside stream
oleSession.ConvertMIME := true; // put this flag back to its original state - per default its true -
Just as a side note, with this method attachments are missing from the saved mail. But since I separate them and save inside another folder, its not a big issue for my case
Regards
Related
I'm currently implementing onReferences on the server side of a language server. When a user right clicks on some custom syntax in a markdown file, I want to be able to use that syntax to search for other occurances of strings elsewhere in the workspace.
connection.onReferences((params) => {
// I can get the syntax here from the client through params and the document manager
// but I only have access to the document manager and the open documents.
// I want to be able to return a location from a possibly unopened file elsewhere
return null;
});
Since I know this happens all the time with the ts-server (click on an interface name and find all occurances) I know this is surely possible. What general strategy am I missing that I can obtain locations of strings elsewhere?
I am trying to create a program to automatically download the attached files that are sent to us from a certain email and then transform the delimiter with SAS, of those csv that are attached to us and pass those csv through a flow that I have already created.
I have managed to create a program that treats the csv as I want and the delimiter that I want, the problem is that when it comes to automating the download of files from Outlook it does not work.
What I have done is create a rule with the following VB code that I found on the internet:
Public Sub SaveAttachmentsToDisk(MItem As Outlook.MailItem)
Dim oAttachment As Outlook.Attachment
Dim sSaveFolder As String
sSaveFolder = "C:\Users\ES010246\Desktop"
For Each oAttachment In MItem.Attachments
oAttachment.SaveAsFile sSaveFolder & oAttachment.DisplayName
Next
End Sub
I have changed the path to my personal path where i want the files are downloaded.
website: https://es.extendoffice.com/documents/outlook/3747-outlook
The problem is that this code does not work for me, it does absolutely nothing for me and no matter how much I search the internet, only this code appears.
Is there any other way to do with SAS what I want? What is it to automatically download 8 csv files sent to me by Outlook, or has someone experienced the same thing as me with VBA?
I have followed all the steps about 7 times so I think the error is not in copying the code or selecting certain options wrong, in fact I had copied and pasted the code and later I modified the path where I wanted those to be saved. files but it doesn't work, does anyone know why?
I will be tremendously grateful, thank you very much for everything!
First of all, you need to make sure the file name and path doesn't include forbidden symbols.
The VBA macro used for a rule in Outlook is absolutely valid except that a mail item may contain the attached files with the same name, so a file saved to the disk may be overwritten (saved with the same name). That's why I'd suggest generating a file name with your own unique IDs making sure that DisplayName property is not empty and has a valid name what can be used for file names (exclude forbidden symbols).
Also you may consider handling the NewMailEx event of the Application class which is fired when a new message arrives in the Inbox and before client rule processing occurs. Use the Entry ID returned in the EntryIDCollection string to call the NameSpace.GetItemFromID method and process the item. This event fires once for every received item that is processed by Microsoft Outlook. The item can be one of several different item types, for example, MailItem, MeetingItem, or SharingItem.
The Items.ItemAdd event can be helpful when items are moved to a folder (from Inbox). This event does not run when a large number of items are added to the folder at once.
In Dec. 2012, Mark Hunte of this stackoverflow site helped another user by providing the following AppleScript. The script creates a new email msg. and attaches a file to the end.
Could anyone here please help me? I need to have a shortened version of this script that only does one thing: attach a file named "selectedPhoto.jpg" to the end of an already open email.
That is, if I am creating a new email or replying to an email and already have the window open, I would like to run a script that simply attaches a photo to the end of that email.
I have tried taking out lines of the following script, but I can't get it to work.
I am running OS X 10.8
Can someone help?
set theAttachment1 to POSIX file "/Users/USERNAME/Desktop/Desktop--IMAGE/scooter-6.jpg"
tell application "Mail"
set newMessage to make new outgoing message with properties {subject:"subject", content:"the_content" & return & return}
tell newMessage
set visible to false
set sender to "myaddress#btinternet.com"
make new to recipient at end of to recipients with properties {address:"someAddress#btinternet.com"}
make new attachment with properties {file name:theAttachment1} at after the last paragraph
(* change save to send to send*)
save --<<<<---------------- change save to send to send
(* change save to send to send*)
end tell
end tell
I couldn't get tell outgoing message 1 to make new attachment to work, but you could use UI scripting:
set old to the clipboard as record
set f to "/Library/Desktop Pictures/Antelope Canyon.jpg"
set the clipboard to (read (POSIX file f as alias) as JPEG picture)
activate application "Mail"
tell application "System Events" to keystroke "v" using command down
set the clipboard to old
This is only part of a larger project. I have a text box on a form and when the command button next to it is clicked, I want to bring up a form that looks aligned to the text box. The idea is to make it look like a drop-down box. But the only thing is that this 'drop-down' is another form and a modal one.
This is what I've done so far and the form shows fine.
procedure TfrmSetupTaxes.cmdChangeParentClick(Sender: TObject);
var
Res : Integer;
frmPopUp : TForm;
begin
frmPopUp := TfrmTreePopUp.Create(nil);
frmPopUp.Parent := Self;
frmPopUp.Top:= self.rp.Top + self.EditItemCat.Top +
self.txtSelParentName.Top + self.txtSelParentName.Height + 3;
frmPopUp.Left:= self.rp.Left + self.EditItemCat.left + self.txtSelParentName.Left;
Res := frmPopUp.ShowModal;
end;
Note: 'rp' is a panel and 'EditITemCat' is a tabsheet. These are merely used for positioning.
Now, here's my problem...
Although the form shows up, it seems frozen. It does not respond, neither does the parent form. Since I'm on the IDE, I just close it.
Can someone please show me what I'm missing here?
Thanks!
What you're missing is how modality works. When there's a modal window in an application, you cannot interact with other windows because these other windows are disabled.
When you call ShowModal on frmPopup, the TfrmSetupTaxes form is disabled for the above reason. Since you've made frmPopup a child of frmSetupTaxes, it also gets disabled.
You cannot workout this design by using modality, you have to devise another mechanism.
This is one of the best findings, at least to me ;)
After a lot of digging and direction, I realised that it was beyond me. I could not figure out the 'right' way that would work for the various OSs (at least Windows and Ubuntu).
Finally I hired an expert (no, not from any forum site) and paid him to show me this. And with the hope that it may help other developers, I thought it would be best to post it here.
Before the answer, I need to give a big thank you to Sertac-Akyuz who showed me that certain things were impossible. I also found through their links that there were some solutions but they did not fit my needs.
Now, before the answer, here are my rules I had to stick to.
I should not use Any Windows-specific functions or APIs because I want to be able to port my work between Windows and Ubuntu (at least for now).
There no MDI forms in use. Again for cross-platform reasons.
There are no 3rd party plugins or products in use.
Now the answer...
procedure TfrmSetupTaxes.cmdChangeParentClick(Sender: TObject);
var
Res : Integer;
frmPopUp : TForm;
pt: TPoint;
begin
frmPopUp := TfrmTreePopUp.Create(self);
pt := txtSelParentName.ClientToScreen(Point(0, 0));
frmPopUp.Top := pt.y + txtSelParentName.Height;
frmPopUp.Left := pt.x;
Res := frmPopUp.ShowModal;
end;
And that's it!
The key was in NOT setting the parent property of the popup. Then using ClientToScreen (a function I didn't even dream of using). It does the job beautifully.
I have asked here a question on how setting the filename of a Word document via automation without saving it. Thanks to Remou, I have received a nice way doing this via calling the FileSummaryInfo-Dialog and setting the Title-property.
However now I have the problem that the client wants to have document names with special chars in (point and underscore) and it seems to be a bug (or a feature) of word, that it cuts the title and only takes the chars before the first special char for building the file name! I have already googled a lot, however was not able to find a resolution for this problem.
The problem is also noticed here (see under gotcha), however without a solution.
Has anybody another solution for setting the filename without saving, or a workaround/bugfix for the mentioned odd behavior?
Try easyhook, since do not have Windows machine besides my hand these days.
following is just the call flow (something like what i did years ago, changed a software's socket bind port to different one by Detours)
About Hook the CreateFileW:
The example in the easyhook's wiki is just what we want here.
CreateFileHook = LocalHook.Create(
LocalHook.GetProcAddress("kernel32.dll", "CreateFileW"),
new DCreateFile(CreateFile_Hooked),
this);
In the CreateFile_Hooked you can change the parameter InFileName, then call real CreateFileW
static IntPtr CreateFile_Hooked(
String InFileName,
UInt32 InDesiredAccess,
UInt32 InShareMode,
IntPtr InSecurityAttributes,
UInt32 InCreationDisposition,
UInt32 InFlagsAndAttributes,
IntPtr InTemplateFile)
{
// FIGURE OUT THE FILE NAME THAT YOU WANT HERE
// IF the InFileName is not your Document name "My.doc", then call orignal CreateFile
// with all the parameter unchanged.
// call original API...
return CreateFile(
YOUR_CHANGED_FILE_NAME_HERE,
InDesiredAccess,
InShareMode,
InSecurityAttributes,
InCreationDisposition,
InFlagsAndAttributes,
InTemplateFile);
}
Call flow:
After you changed the title to "My_Document_2012_11_29",
then hook the CreateFileW of Word process.
For example when the InFileName is "My.doc",
then you should change it to "My_Document_2012_11_29".
Because this is done in the Word process, so the Detoured function do not know
"My.doc" is mapping to "My_Document_2012_11_29".
There is lot ways to get this mapping info, one is save this mapping info to
a known file in your app, and read the file in the Detoured function.