An email arrives on the mail server with a foto attached (a motion warning from a security camera, for example) and I would like to forward that foto to a twitter account via a DM. I think I have all the tools necessary to do this, but I haven't gotten them all together.
postfix
oysttyer
procmail
ImageMagick
dovecot (can add sieve/pigeonhole)
root access to install anything else
Currently I am able to send a text message saying "there was a motion warning with a photo, please check email" but that is suboptimal.
The solution I am thinking is best (though I am open o anything) is to figure out how to extract the image from the email and save it to a http accessible location on the server, then link to that location in the DM. However, I am open to any other ideas.
OK, I have a working (if terrible) solution.
First, using ripmime I pipe the message to ripmime from within procmail. This produces a bunch of garbage files, along with an image file that I want. I proud these files in a web folder, and then I run a cron task to test the URL to the image and delete the garbage files.
#!/bin/bash
BASE="/usr/local/www/photodrop/"
PHOTO=`find $BASE -cmin -2 -type f -name="*.jpg" -exec basename {} \;`
URL="http://www.example.com/photodrop/$PHOTO"
echo $URL
oysttyer -runcommand="/dm #[user] $URL"
In procmail, I simply pipe the message to ripmime
:0
| ripmime -i - -v -d /usr/local/www/photodrop/
I looked at several other mime packages (munpack for one) but they didn't like accepting piped messages and munpack specifically required a path to a file, so that was no good. So, this works. Barely.
For security, I remove the images (actually, I move them) after 5 minutes.
Related
I need to download an archived google group.
Following link is one of the messages of that group for example.
https://groups.google.com/forum/#!topic/sci.aeronautics/ViFtpXfVm7M
The problem is, what i see in the browser does not appear in the downloaded webpage.
With my very limited knowledge, It seems to me like the reason behind it is this content is dynamically created by java-script. Or else, these downloaded files are with so called 'mbox' extension which is encrypted ?
What I've tried so far
First trys
Simple download
wget https://groups.google.com/d/topic/sci.aeronautics/ViFtpXfVm7M
With mirror
wget --mirror https://groups.google.com/d/topic/sci.aeronautics/ViFtpXfVm7M
Assuming its encrypted
With cookies.
wget --load-cookies=cookies.txt https://groups.google.com/d/topic/sci.aeronautics/ViFtpXfVm7M
Got thunderbird to setup my gmail and opening. did not open correctly
Assuming the content was javascript generated
Downloaded using phantomJS
https://askubuntu.com/questions/411540/how-to-get-wget-to-download-exact-same-web-page-html-as-browser
Downloaded using phantomJS with a different script
https://gist.github.com/giocomai/247d54e097b5083e2451
Used scripts available from Github
https://github.com/henryk/gggd
https://github.com/icy/google-group-crawler
But none did not work so far.
Can anyone please shed some light on how to download this page with its message as a readable html or txt file ?
Cheers
AyyoSalli
You could use https://groups.google.com/forum/feed/sci.aeronautics/msgs/atom.xml?num=100 to get some of the posts - but it only gets roughly half the posts in this case.
And it has all the messages from all topics together.
View it in Firefox or Classic Opera to see directly in a more human-readable form.
But since you say you already got a file in standard mbox format, what exactly is wrong with it - did you attempt to import it into a locally installed email or newsclient ? (like Thunderbird)
I have been given a task that involves downloading a single file every day from a website. Let's call it "https://test.example.com". I have credentials that allow me to login to the site, where a Flash interface then presents the files that are available for download. After the file is downloaded, it is then processed in a variety of ways. I have already put together the Powershell that handles all that, I am just having a hard time with automating the actual download of the file.
I used the Flash interface to download a few files while watching the network activity, and found that it is actually pulling the file from this URL:
https://test.example.com/link/EBDB7F67EF3B28XX99NCAD9920160423/file.zip
Therefore, I was able to put this together in order to automatically get the file via my PS script:
$url = 'https://test.example.com/link/EBDB7F67EF3B28XX99NCAD9920160423/file.zip'
$output = "C:\Downloads\file.zip"
Invoke-WebRequest -Uri $url -OutFile $output
However, the long string of numbers in the URL changes every day. The only discernible pattern I can find is that the last eight digits are always the date on which that particular file is posted.
Is there a good way to approach this? I've been experimenting with wildcards and patterns, as well as checking the HTML for elements that I can filter, but I am having a hard time finding the correct solution.
This is very hard to automate. You can't drive Flash from the script unless it is specifically designed for that. As I see it now your only options are:
Contact site devs if possible, maybe they can give you a details on function that generates link. This gives me an idea - perhaps you can reverse engineer Flash code to find that function details yourself. Use flash decompiler for this.
Simulate the user browsing the flash site. This can be done in one of the following ways:
Autohotkey - you can record mouse clicking relative to the browser window and execute the script again. Unless flash interface is too dynamic and unpredictive it will work.
Sikuli - another automation language which relies on picture segment recognition.
All above 2.* methods produce fragile automation code as they depend on browser settings (zoom, theme) and even OS settings. For this reason you need to dedicate one machine for that in all probability (virtual machine ofc). Decompiling flash code and re-implementing the url generting code in powershell will make it a reliable 100%.
As somebody said in comments this is not a powershell queestion but browser automation question.
I can't find the solution for my problem. So, in my send-mailmessage html body is field that should be redirected to file which is included as attachment in message. How can I create hyperlink to that file in mail, when client opens it?
I don't know if you get my idea. In other words, in message I have attached file, and then there is field which should be a hyperlink to attached file. When client receives message he/she should press the link and then attached file opens.
I searched almost everything in everwhere but can't find a appropriate solution how to solve this.
This isn't really a PowerShell question, since this issue has nothing to do with the functionality of the Send-MailMessage cmdlet.
In any case, the reason you can't find a solution anywhere is that what you're trying to do is impossible. There is no way that a hyperlink in an e-mail message can point to a file attached to that message. Different mail clients on different operating systems store attachments in different locations. Even if you want to assume that all your recipients are running Outlook on Windows, there are different versions of both. Even if you know for a fact that all recipients are running a specific version of Outlook on a specific version of Windows, you're still out of luck. Outlook stores attachments in a subfolder in the Temporary Internet Files in the user's profile that has a randomly generated name. There's no way to inject code into a hyperlink in an email message, so without knowing the exact local file location, you can't link to it.
I suppose if you're really determined you could have the hyperlink point to a web page that runs some complex javascript code that tries to figure out where the attachment is stored, but that's a major undertaking, and would break if the recipient's default browser has javascript disabled.
Which begs the question, why exactly are you trying to do this? So that recipients can click once instead of having to double-click to open the attachment?
I have found that you can make a hyperlink point to a file share that you know the recipients have access to.
To do so:
Simply make each hyperlink point to the specific file and there you have it.
They have to have permissions to access that file share, or there is a much better way now that I haven't thought of.
Oh well, this works for me, for now.
I need to be able to download just the data from the page into a text file to parse later with a different program. I've used this syntax with other sites and works perfect, but I've run into a program with one web site.
Here's the site and the syntax I'm using:
WGET.EXE http://quotes.morningstar.com/fund/AAAAX/f?t=AAAAX -O AAAAX.TXT --no-check-certificate -owebdata/logfile.txt
This downloads the page but key data I need to see is not there. For example:
Expenses Turnover and status data is not there
I know the script is using a sub-program to produce the data but I know WGET is capable of just downloading the output to a file, I'm just unclear what flag or option to set to make it do it
The expenses and turnover and other status data are set using javascript on the page. As far as i know, you cannot wget that as it is generated on the client side when javascript runs on the browser.
I'm trying to use nmh's "draftfolder" feature to queue outgoing mail for later delivery.
The key step I don't know how to implement is how to write a program that will send a message from a draft folder.
Here's the workflow I'm trying to achieve:
I compose a message using the comp or repl programs, and I quit with the message unsent, leaving it in the "draft folder" +delay4.
Sometime after four hours have elapsed, a cron job comes along and sends the message, removing it from the draft folder.
Here are the difficulties I'm having with existing MH commands
The comp -use command can send an existing message from a draft folder, but it requires interaction. I want to do this noninteractively from a cron job, and I'd prefer not to try to write an expect script. I tried
comp -use -noedit -nowhatnowproc
but that did not send the message. I don't know if some kind of alternate whatnow program would do the trick.
The send and post commands look promising, but both expect to operate on files, not messages in folders. Maybe send followed by rmm works, maybe it doesn't.
I could go direct to sendmail, but then I would have to figure out whether to run mhbuild or not. And I would seem to have the same issue of needing to remove the message from the folder.
My question is how can I use the MH API in a script to send a message that is sitting in a draft folder?
RTFM.
The send command's -draftfolder option makes it work on messages, not files.
Perfect for what I want. If you want to be extra explicit, use the -draftmessage option as well.