Search

Clear filter
Article
José Pereira · Sep 1, 2021

Implementing an IMAP Client in InterSystems IRIS - part I

This article explains how to use the InterSystems IRIS platform to write a basic IMAP client. First, we present an overview of IMAP, then we discuss the main IMAP commands and client implementation. Finally, we offer a simple use of this IMAP client on the IRIS interoperability application. Note that this article isn’t a detailed IMAP explanation. For more detailed information, please check the references of this article. IMAP Overview The Internet Message Access Protocol (IMAP) lets users retrieve emails. Mark Crispin proposed IMAP in the 1980s, and since then, the protocol has been published and revised in RFC 3501. At the time of writing this article, its current version is IMAP4rev1. It’s important to note that this protocol is designed for retrieving only. You must use another protocol, the Simple Mail Transfer Protocol (SMTP), if you need to send emails. There’s also an older protocol for email retrieval that’s as popular as IMAP, called Post Office Protocol version 3 (POP3). Trying Basic IMAP Commands Like POP3, IMAP is a plaintext protocol. You can easily try some of its commands by yourself, using a TCP client like Telnet or OpenSSL. First, you need your IMAP host and email server port. For instance, at the time of writing this article, this is the host and port to connect to the Microsoft Outlook service: outlook.office365.com:993 Let’s connect to this server using our TCP client. Enter the command below and hit ENTER. Note the use of the -crlf flag. This flag is mandatory for IMAP as carriage return and line feed (CRLF) is its line terminator. $ openssl s_client -connect outlook.office365.com:993 -crlf -quiet After you hit enter, the IMAP server shows you some information and stays waiting for input. depth=2 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert ... * OK The Microsoft Exchange IMAP4 service is ready. [...] Now we can perform our first IMAP command: CAPACITY. As its name suggests, this command presents features that the server can provide. Note that the first line is the IMAP command itself, and the others lines are its output - this is the same for all other IMAP commands presented here. TAG1 CAPABILITY * CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS ID UNSELECT CHILDREN IDLE NAMESPACE LITERAL+ TAG1 OK CAPABILITY completed. Note the token before the CAPABILITY command: TAG1. A tag must precede every IMAP command and is any string you want. They identify what command instance the server is responding to. Generally, a simple counter with a prefix fits all your needs. The IMAP server finishes the response with the tag you used to issue the command and a flag indicating the command’s status, followed by miscellaneous information related to the command and status. The statuses allowed are: OK (success), NO (failure), and BAD (wrong command). The command LOGIN expects user and password as arguments. First, let’s check how the server responds if someone gives an invalid username and password: TAG2 LOGIN user@outlook.com wrong-password TAG2 NO LOGIN failed. Note the NO status after the command tag. Now, let’s proceed to a valid login: TAG3 LOGIN user@outlook.com password TAG3 OK LOGIN completed. Now we’re logged in. To finish our session, we use the LOGOUT command: TAG4 LOGOUT * BYE Microsoft Exchange Server IMAP4 server signing off. TAG4 OK LOGOUT completed. We need other commands to implement our IMAP client, so we need to reconnect and log into our IMAP server again. Let’s get some information about the inbox next. First, we must tell the server which mailbox we want to access, INBOX in this case. TAG5 SELECT "INBOX" * 14 EXISTS * 0 RECENT ... TAG5 OK [READ-WRITE] SELECT completed. Now we are ready to access messages in our inbox, but we need a way to refer to them first. There are two ways to do that: by message number or by a unique identifier (UID). Message numbers are just counters, starting from 1 and going up to the number of messages within the inbox. When you delete a message, all following messages have their numbers decremented by 1. You can think of this as an array that has one of its elements removed. UIDs, on the other hand, keep their value whatever happens to the other messages. You can get UIDs using the UID SEARCH command. This command accepts a message number if you'd like to get a specific UID or the ALL parameter to get all UIDs in the directory. In the example below, we search for UID for message number 1, which is 483. TAG6 UID SEARCH 1 * SEARCH 483 TAG6 OK SEARCH completed. Now let’s retrieve message information, like headers, body, and attachments. We use the FETCH command for this. This command has plenty of parameters, which you can explore in detail on RFC 3501. In this article, we only address parameters related to the needs of the IMAP client implementation. The first information we need for this demonstration is the message size. We can get this information using the RFC822.SIZE parameter: TAG7 FETCH 1 RFC822.SIZE * 1 FETCH (RFC822.SIZE 70988) TAG7 OK FETCH completed. This indicates that the size of message number 1 is 70,988 bytes. Note that it’s also possible to use UIDs rather than message numbers to fetch message information: TAG8 UID FETCH 483 RFC822.SIZE * 1 FETCH (RFC822.SIZE 70988 UID 483) TAG8 OK FETCH completed. You can also get the basic From, To, Date, and Subject message headers: TAG9 FETCH 1 (FLAGS BODY[HEADER.FIELDS (FROM TO DATE SUBJECT)]) * 1 FETCH (FLAGS (\Seen) BODY[HEADER.FIELDS (FROM TO DATE SUBJECT)] {157} Date: Thu, 22 Apr 2021 15:49:05 +0000 From: Another User <anotheruser@outlook.com> To: user@outlook.com Subject: Greetings from Another User! FLAGS (\Seen)) TAG9 OK FETCH completed. Now let’s retrieve the message body. We can retrieve all the body content using this command: TAG10 FETCH 1 BODY[] * 1 FETCH (BODY[] {9599} ... MIME-Version: 1.0 --00000000000041bd3405c3403048 Content-Type: multipart/alternative; boundary="00000000000041bd3205c3403046" --00000000000041bd3205c3403046 Content-Type: text/plain; charset="UTF-8" ... --00000000000041bd3405c3403048 Content-Type: image/png; name="download.png" Content-Disposition: attachment; filename="download.png" ... TAG10 OK FETCH completed. We can see in this code that some blocks are delimited by hex numbers between -- --, called parts. A message with parts is called a multipart message. It’s possible to get such parts directly by passing the part index to the command. In order to delete messages, the protocol has the commands STORE and EXPUNGE, which mark a message as deleted and commit such an operation. TAG11 STORE 1 +FLAGS (\Deleted) * 0 EXISTS * 0 RECENT TAG11 OK [READ-WRITE] SELECT completed; now in selected state TAG12 EXPUNGE EXPUNGE: TAG12 OK EXPUNGE completed The last command is simple: NOOP. This command does nothing but is used to implement a keep-alive strategy. By default, the IMAP session closes after 30 minutes without commands. So, issuing the NOOP command keeps the connection active. TAG17 NOOP TAG17 OK NOOP completed. And this finishes our IMAP overview. If you’d like more information, there are a lot of good articles on the Web (I've selected some in resources section), and of course always remember the RFC 3501. Resources Atmail’s IMAP 101: Manual IMAP Sessions Fastmail’s Why is IMAP better than POP? IETF’s Internet Message Access Protocol IETF’s Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies Nylas’ Everything you need to know about IMAP Next part, you'll use those commands within IRIS and see them in action! See you!
Announcement
Anastasia Dyubaylo · Sep 17, 2021

Video: Getting Up to Speed on InterSystems API Manager

Hi Community, Enjoy watching the new video on InterSystems Developers YouTube: ⏯ Getting Up to Speed on InterSystems API Manager Get a walkthrough of the newest features of InterSystems API Manager (IAM), which offers full API management capabilities for InterSystems IRIS data platform; and get a brief introduction to the basic concepts of API management. 🗣 Presenter: @Stefan.Wittmann, Product Manager, InterSystems Enjoy and stay tuned!
Announcement
Evgeny Shvarov · Oct 4, 2021

Technology Bonuses for InterSystems InterOperability Contest 2021

Hi Developers! Here're the technology bonuses for the InterSystems Interoperability Contest 2021 that will give you extra points in the voting: Business Process BPL or Business Rule DTL Usage Custom Interoperability Adapter Usage Production EXtension(PEX) Java or .NET usage Workflow Engine usage Docker container usage ZPM Package deployment Online Demo Code Quality pass Article on Developer Community Video on YouTube See the details below. Business Process BPL or Business Rules Usage - 3 point One of the key features of IRIS Interoperability Productions are business processes, which could be described by BPL (Business Process Language). Learn more on Business Processes in documentation. Business Rules it's a no-code/low-code approach to manage the processing logic of the interoperability production. In InterSystems IRIS you can create a business rule which you can create visually or via the ObjectScript representation. You can collect the Business Process/Business Rule bonus if you create and use the business process or business rule in your interoperability production. Business Rule Example Learn more on Business Rules in documentation. Custom Interoperability Adapter Usage - 2 point InterSystems Interoperability production can contain inbound or Outbound adapters which are being used to communicate with external systems by business services and operations of the production. You can use out-of-the-box adapters (like File, or Email) or develop your own. You get the bonus if you develop your own custom inbound or outbound adapter and use it in your production. Example of an adapter. Learn more on adapters. Production EXtension (PEX) Usage - 4 points PEX is a Java or .NET extension of Interoperability productions. You get this bonus if you use PEX with JAVA or .NET in your interoperability production. PEX Demo. Learn more on PEX in Documentation. Workflow Engine Usage - 2 point Workflow Engine is a part of IRIS Interoperability which could be used to automate the distribution of tasks among users. You get this bonus if you use include the usage of Workflow Engine in your interoperability production. Learn more on Workflow in Documentation. There are Community modules WorkflowAPI and WorkflowUI-ngx which provide a nice UI layer on Angular for the Workflow engine. Docker container usage - 2 points The application gets a 'Docker container' bonus if it uses InterSystems IRIS running in a docker container. Here is the simplest template to start from. ZPM Package deployment - 2 points You can collect the bonus if you build and publish the ZPM(ObjectScript Package Manager) package for your Full-Stack application so it could be deployed with: zpm "install your-multi-model-solution" command on IRIS with ZPM client installed. ZPM client. Documentation. Online Demo of your project - 3 pointsCollect 3 more bonus points if you provision your project to the cloud as an online demo. You can do it on your own or you can use this template - here is an Example. Here is the video on how to use it. Code quality pass with zero bugs - 1 point Include the code quality Github action for code static control and make it show 0 bugs for ObjectScript. Article on Developer Community - 2 points Post an article on Developer Community that describes the features of your project. Collect 2 points for each article. Translations to different languages work too. Video on YouTube - 3 points Make the Youtube video that demonstrates your product in action and collect 3 bonus points per each. Example. The list of bonuses is subject to change. Stay tuned! Good luck in the competition! can we add a China video website to add since China developers since we cannot access Youtube? If I translate my own article count as 2 articles!? Just kidding
Announcement
Anastasia Dyubaylo · Dec 21, 2021

InterSystems DataSets Contest Kick-off Webinar

Hi Community, We are pleased to invite all the developers to the upcoming InterSystems Datasets Contest Kick-off Webinar! The topic of this webinar is dedicated to the Datasets contest. In this webinar, we’ll do a quick tour of the new LOAD DATA feature, also chime in on packaging global data or file data with ZPM, and run a data-generation script as part of a method in the zpm install. As always, our experts will answer the questions on how to develop, build, and deploy datasets using InterSystems IRIS. Date & Time: Tuesday, December 28 – 10:00 AM EDT Speakers: 🗣 @Benjamin.DeBoe, Product Manager, InterSystems 🗣 @Evgeny.Shvarov, InterSystems Developer Ecosystem Manager So! We will be happy to talk to you at our webinar in Zoom! ✅ JOIN THE KICK-OFF WEBINAR! Hey everyone, The kick-off will start in 10 minutes! Please join us here: https://us02web.zoom.us/j/9822194974?pwd=bnZBdFhCckZ6c0xOcW5GT1lLdnAvUT09 Or enjoy watching the stream on YouTube: https://youtu.be/IEIGHit-9O8 Hi @Anastasia.Dyubaylo Is Kick-off webinar recoding available ?Thanks Hey Developers, The recording of this webinar is available on InterSystems Developers YouTube! Please welcome: ⏯ InterSystems DataSets Contest Kick-off Webinar Big applause to our speakers! 👏🏼
Announcement
Anastasia Dyubaylo · Nov 11, 2021

Video: Working with FHIR Profiles in InterSystems IRIS for Health

Hey Developers, Don't miss our new video on InterSystems Developers YouTube: ⏯ Working with FHIR Profiles in IRIS for Health Learn how a FHIR server built with InterSystems IRIS for Health can support multiple FHIR profiles, including those available in the US Core Implementation Guide and other published FHIR packages. FHIR profiles and other conformance resources allow you to adapt FHIR for a specific purpose or environment. 🗣Presenter: @Kurt.Dawn , Technical Writer, InterSystems FHIR team Subscribe and enjoy watching!
Article
Yuri Marx · Nov 12, 2021

InterSystems IRIS Building Blocks to TOGAF Architecture Domains

The TOGAF is the The Open Group Architecture Framework. It provides an approach for planning, design, implement, deploy and govern your EA (Enterprise Architecture) projects. The TOGAF has a concept called Building Block. It is any element that can be used, reused a executed to deliver value and new functions to the business. In the picture above, I present to you the main IRIS building blocks to create fantastic apps. To learn more about TOGAF and building blocks, see https://www.opengroup.org/togaf. Hi Yuri and DC members As you know I have challenged the DC members to come up with cheat sheets for IRIS and this is a perfect example of what I was hoping to see from DC members. With your permission, I would like to include it in my collection of IRIS Cheat/Information sheets. For other DC members reading this post and there is an aspect of IRIS that you are particularly familiar with or passionate about then have a go and see if you can come up with a similar informative diagram. Typically the cheat/information sheets are one-two page long. When it comes to a language explanation then you would typically create a page on commands, another on operators and so on. Let your inner artist guide your layout and colour scheme. Once I have built up a substantial collection of IRIS topics I'll see if Olga, Evgeny and Anastasia and the ISC Experts will vote on the best layout and all cheat/information sheets will be modified to conform to that look. Who knows, they may even reward the winner. Bear in mind that ISC have a certain style, colour scheme and logo's and this should be taken into consideration/ Nigel P.S. Sorry Yuri for high jacking your Article ro further my personal mission. Thanks Nigel. If you want, send me an email - yurimarx@gmail.com, to get the editable diagram file.
Announcement
Evgeny Shvarov · Jun 22, 2022

InterSystems "Climate Change" Fullstack Contest 2022 Bonuses

Hi developers! Here are the bonus points for the experts voting for your applications in the Fullstack contest 2022: Here we go! Climate Change - 5 isc.rest package - 2 isc.ipm.js package - 2 Embedded Python - 3 Adaptive Analytics (AtScale) Cubes usage - 3 Docker container usage - 2 ZPM Package deployment - 2 Online Demo - 2 Unit Testing - 2 First Article on Developer Community - 2 Second Article On DC - 1 Code Quality pass - 1 Video on YouTube - 3 Climate Change - 5 points Collect the bonus if your solution will help to fight the global warming and climate change problems. Join the Climate Change Full Stack contest kick-off on Monday 27th for more information. isc.rest package - 2 points Use isc-rest package in your full-stack application to collect the bonus. Check the isc-perf-ui application to see how it works. isc.ipm.js package - 2 points Use isc-ipm-js package in your full-stack application to collect the bonus. Check the isc-perf-ui application to see how it works. Embedded Python - 3 points Use Embedded Python in your application and collect 4 extra points. You'll need at least InterSystems IRIS 2021.2 for it. Adaptive Analytics (AtScale) Cubes usage - 3 pointsInterSystems Adaptive Analytics provides the option to create and use AtScale cubes for analytics solutions. You can use the AtScale server we set up for the contest (URL and credentials can be collected in the Discord Channel) to use cubes or create a new one and connect to your IRIS server via JDBC. The visualization layer for your Analytics solution with AtScale can be crafted with Tableau, PowerBI, Excel, or Logi. Documentation, AtScale documentation Training Docker container usage - 2 points The application gets a 'Docker container' bonus if it uses InterSystems IRIS running in a docker container. Here is the simplest template to start from. ZPM Package deployment - 2 points You can collect the bonus if you build and publish the ZPM(InterSystems Package Manager) package for your Full-Stack application so it could be deployed with: zpm "install your-multi-model-solution" command on IRIS with ZPM client installed. ZPM client. Documentation. Online Demo of your project - 2 pointsCollect 2 more bonus points if you provision your project to the cloud as an online demo. You can do it on your own or you can use this template - here is an Example. Here is the video on how to use it. Unit Testing - 2 points Applications that have Unit Testing for the InterSystems IRIS code will collect the bonus. Learn more about ObjectScript Unit Testing in Documentation and on Developer Community. Article on Developer Community - 2 points Post an article on Developer Community that describes the features of your project and collect 2 points for the article. The Second article on Developer Community - 1 point You can collect one more bonus point for the second article or the translation regarding the application. The 3rd and more will not bring more points but the attention will all be yours. Code quality pass with zero bugs - 1 point Include the code quality Github action for code static control and make it show 0 bugs for ObjectScript. Video on YouTube - 3 points Make the Youtube video that demonstrates your product in action and collect 3 bonus points per each. The list of bonuses is subject to change. Stay tuned!
Announcement
Anastasia Dyubaylo · Sep 19, 2022

Winners of the InterSystems Interoperability Contest: Building Sustainable Solutions

Hi Community, We are super excited to announce the winners of the InterSystems Interoperability Contest: Building Sustainable Solutions! Thank you all for participating in our coding competition! Without further ado, the winners are... Experts Nomination 🥇 1st place and $5,000 go to the Sustainable Machine Learning app by @Lucas.Enard2487 🥈 2nd place and $3,000 go to the iris-energy-isodata app by @Muhammad.Waseem 🥉 3rd place and $1,500 go to the iris-megazord app by @José.Pereira 🏅 4th place and $750 go to the n8n-nodes-iris app by @Dmitry.Maslennikov 🏅 5th place and $500 go to the samba-iris-adapter app by @Yuri.Gomes More winners: 🏅 $100 go to the Recycler app by @Oleh.Dontsov 🏅 $100 go to the interoperability-test app by @Oliver.Wilms 🏅 $100 go to the interoperability-soap app by @Oliver.Wilms 🏅 $100 go to the production-monitor app by @Oliver.Wilms 🏅 $100 go to the appmsw-banks-ru app by @MikhailenkoSergey Community Nomination 🥇 1st place and $1,000 go to the iris-megazord app by @José.Pereira 🥈 2nd place and $750 go to the Sustainable Machine Learning app by @Lucas.Enard2487 🥉 3rd place and $500 go to the iris-energy-isodata app by @Muhammad.Waseem Our sincerest congratulations to all the participants and winners! Join the fun next time 😎 Thank you so much everyone for the feedback on my work and the kind comments. Thank you for choosing my application as the winner and for the second place in the community vote !! Congrats @Lucas.Enard2487, it's honestly deserved !! You are proof that all it takes is an internship of a few months to become a real expert.Well done. Congratulation @Lucas.Enard2487 and all the winners Thank you so much Sylvain ! Thank you Muhammad, it was a pleasure to participate! Congratulations to all winners! Congratulations to all the winners!! The InterSystems Interoperability Contest Winners video is available on InterSystems Developer's YouTube! ⏯ Winners of InterSystems Interoperability Programming Contest Check it out!
Announcement
Anastasia Dyubaylo · Aug 1, 2022

Winners of InterSystems Tech Article Contest: Python Edition

Hi Developers! We have great new articles for your to read and enjoy, thanks to our wonderful participants of the 3rd InterSystems Tech Article Contest: Python Edition! 🌟 12 AMAZING ARTICLES 🌟 And now it's time to announce the winners! Let's meet the winners and their articles: ⭐️ Expert Awards – winners selected by InterSystems experts: 🥇 1st place: IRIS Embedded Python with Azure Service Bus (ASB) use case by @Yaron.Munz8173 🥈 2nd place: Getting known with Django part 1 by @Dmitry.Maslennikov 🥉 3rd place: Introduction to Web Scraping with Embedded Python - Let’s Extract python job’s by @Rizmaan.Marikar2583 ⭐️ Community Award – winner selected by Community members, article with the most likes: 🏆 IRIS Embedded Python with Azure Service Bus (ASB) use case by @Yaron.Munz8173 And... ⭐️ We'd like to reward @Dmitry.Maslennikov for a series of 3 articles! He will get Apple HomePod mini or Apple Pencil. Let's congratulate all our heroes, who took part in the Tech Article contest #3: @Yuri.Gomes @Robert.Cemper1003 @Muhammad.Waseem @Veerarajan.Karunanithi9493 @Renato.Banzai @Ramil.TK THANK YOU ALL! You have made an incredible contribution to our Dev Community! The prizes are in production now. We will contact all the participants when they are ready to ship. Congratulations to the winners and the participants! Great job! 👏👏 Congratulations to all the winners
Announcement
Janine Perkins · Feb 16, 2016

Featured InterSystems Online Course - Caché Objects Introduction

Do you need to build an object-oriented application using Caché? Take this course to learn how to create, retrieve, update and delete objects in Caché.Caché Objects IntroductionLearn the basics of Caché objects. This course will provide an overview of Caché Classes, Methods, and interaction with the Caché database by creating, saving, loading and deleting objects. The lessons in this course assume that you have some previous object-oriented programming experience. Learn More.
Question
Tiago Ribeiro · Feb 25, 2016

Better Unit Testing Strategies for InterSystems Caché Development

Good morning people.The use of TDD is currently being reference for software delivery more confiabilitade and quality.At the company I work developing web applications , we create tests for method class in a deteminado package and running the steps that the documentation recommends:1 export the tests classes to a predefined folder.2- And running the test ( D ## class (% UnitTest.Manager ) .RunTest (,"/nodelete" )It is a lot of work to do the export and run these tests would have a resource that we could only run the tests without the need for export ? You may call RunTest with /noload parameter, but you still have to set a valid directory as a value in ^UnitTestRoot Set ^UnitTestRoot = "C:\UnitTests" Do ##class(%UnitTest.Manager).RunTest("mytests:MyPackage.Tests", "/noload/nodelete") Or so, here you can specify: suit, class and method if you want Do ##class(%UnitTest.Manager).DebugRunTestCase("mytests","MyPackage.Tests","","") This call does not load any classes from any directories nor does it delete any classes from Caché. And executes the tests contained in MyPackage.Tests. The optional third argument is for specifying an individual test method within the test class to execute. Dmitry, Thanks. Different people are going to have different workflows for unit testing, but I would encourage you to settle on a way to get those tests out of the database. I'd be nervous about running tests in a namespace that contains my only copy, since %UnitTest is designed to load and delete by default. If you're using Studio with the source control hooks, it works pretty well to write the tests in a development namespace, then run them in a test namespace. Hi, Jon.Yes, I here use different developer namespace, one for testings.I will go about hooks of control sources, Thanks. Indeed. Presumably the "load and delete" defaults were a design decision based on the model of running unit tests elsewhere. That seems relevant for a build server, but not so friendly for the developer who you're trying to persuade to code the tests in the first place. Yes, Studio the source control hook facility can be your friend here provided you're prepared to spend enough time getting intimate with it.
Announcement
Evgeny Shvarov · Feb 23, 2016

InterSystems Global Summit 2016 MVP Contest Update!

Hi, Community! There are only six days left to win InterSystems Developer Community MVP prize. As it was announced in addition to Free Registration on InterSystems Global Summit winner gets 4 nights stay in the Arizona Baltimore, Waldorf Astoria Resort. We measure contribution to Developer Community on valuable posts and comments and prepared special leaderboard built on InterSystems DeepSee. By default, it shows all the members. We added the filter to the dashboard to show leaderboard without members who are InterSystems employees. So here is current leaderboard without InterSystems members: Win MVP and come to InterSystems Global Summit 2016! Go Dmitry! I would add "Go Scott!" If you change filters to February scope there is following picture for top 20:Where are your new cruel questions? ) I've been very sick the last week :( The original post talked about accounting for "number of votes a post received". How is this reflected in these numbers? We have a formula which summarize votes for posts, votes for comments.It also gives some score for comments in your post.It counts points also for your comments in other posts - e.g. for your answer on the question. Oh. Hope you are doing well now.
Announcement
Janine Perkins · Mar 22, 2016

Featured InterSystems Online Course: Caché Objects Introduction

Learn the basics about Caché objects.Caché Objects IntroductionThis course provides an overview of Caché classes, methods, and interaction with the Caché database by creating, saving, loading and deleting objects. Learn More.
Announcement
Janine Perkins · May 10, 2016

Featured InterSystems Online Course: Navigating the Management Portal

Learn the different ways to navigate the management portal.Navigating the Management PortalThis course describes how to start the Management Portal, explains the different sections of the home page and shows several ways to navigate to other pages. Learn how to start the Management Portal on your client system, identify the sections of the Management Portal home page, recall how to add a page to the Favorites and navigate the Management Portal using links and keywords.Learn More.
Article
Evgeny Shvarov · May 11, 2016

The simplest snippet to read from file in InterSystems IRIS

Hi! I believe the simplest is (to work with csv delimited by ";"): set file = ##class(%File).%New( "data.csv" ) set sc = file.Open( "R" ) if $$$ISERR(sc) quit ; or do smth while 'file.AtEnd { set str=file.ReadLine() for i=1:1:$length( str, ";" ) { set id=$piece( str, ";" ,i ) write !, id // or do smth } } do file.Close() Possible options: different variants of error handling with sc code. Embrace while loop into try/catch block. And what's yours? Ok, here is the "simplest"N IO,D,P,I,A,X,L S IO=$I R D U 0 W !,D,! S P="^" F U IO R A Q:A="" I $P(A,P,3) S L=$P(A,P,5) S:L X=$ZU(55,L) ZL ZS @$P(A,P) S:L X=$ZU(55,0) U 0 W !,$P(A,P,1,2),?20," loaded" ;(Self-loading) (Well, I'm joking - this is the standard preamble for self-loading INT file) This is MUMPS-Enigma code) I would generally advise against using %File class for reading files as this is a very low level wrapper around the COS file commands. For example if you want to apply a translate table you need to know about the 'K' flag on the open command. I much prefer using the %Stream.FileBinary or %Stream.FileCharacter classes as these provide a much more consistent interface to the file. Evgeny,Thank you for sharing this snippet.However, I don't understand why you de-piece a line with a delimiter of ";"?I would just like to see the line like it is.What am I missing here? You have missed the extension of file "data.csv" used in the example. CSV stands for "Comma Separated Values", which is simplest way to exportt Excel like data to the textual file. And in this case it was apparently exported in the Russian-loale where "comma" is ";" actually. Yes) Timur already answered. This snippet is not very general "read from file" snippet - but snippet to parse "russian-like" csvs) But every time when I work with text files line by line I use it. Thank you for that clarification, but, should that be part of the opening documentation? Didn't get it. You mean I should change the description for the snippet?Or to change the snippet to make it less "csv" specific? Just get rid of your inner for loop and you have a generic snippet that is helpful for everybody. The description doesn't speak of CSV files at all, though that may be an interesting use case as well. For CSV files, you can use the Record Mapper by the way:http://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=EGDV_recmap Sorry, I am not criticizing what you have done.I had to ask why you de-pieced the line based on ";"and I was given an answer.Suppose I did not ask, took your snippet and assumed to worked for all files?All I am saying is the assumption you used (Russian style files) should be part of your documentation so someone not familiar with these style of files would know. Any (unfamiliar) assumptions should be documented. Agreed. Will fix it. Anyway, you are very welcome to add your version of the simplest ever file management snippet ;) Stefan,Thanks for the tip on the Record Mapper, great stuff! Oh, thanks for this! I think it worth to make a separate snippet posting how to use the record mapper. Haven't found it in the documentation. And since Yesterday here is new fashion way to make links to documentation ;) maybe enigmic,but i think it's very convient and good-short! it's like my native tatarian tongue))))))